Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 1 | // Test mmap behavior when map address is below shadow range. |
| 2 | // With MAP_FIXED, we return EINVAL. |
| 3 | // Without MAP_FIXED, we ignore the address hint and map somewhere in |
| 4 | // application range. |
| 5 | |
Pirama Arumuga Nainar | 7c91505 | 2015-04-08 08:58:29 -0700 | [diff] [blame] | 6 | // RUN: %clangxx_msan -O0 -DFIXED=0 %s -o %t && %run %t |
| 7 | // RUN: %clangxx_msan -O0 -DFIXED=1 %s -o %t && %run %t |
| 8 | // RUN: %clangxx_msan -O0 -DFIXED=0 -D_FILE_OFFSET_BITS=64 %s -o %t && %run %t |
| 9 | // RUN: %clangxx_msan -O0 -DFIXED=1 -D_FILE_OFFSET_BITS=64 %s -o %t && %run %t |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 10 | |
| 11 | #include <assert.h> |
| 12 | #include <errno.h> |
| 13 | #include <stdint.h> |
| 14 | #include <sys/mman.h> |
| 15 | |
| 16 | int main(void) { |
| 17 | // Hint address just below shadow. |
Pirama Arumuga Nainar | cdce50b | 2015-07-01 12:26:56 -0700 | [diff] [blame] | 18 | #if defined(__FreeBSD__) && defined(__x86_64__) |
| 19 | uintptr_t hint = 0x0f0000000000ULL; |
| 20 | const uintptr_t app_start = 0x000000000000ULL; |
| 21 | #elif defined(__x86_64__) |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 22 | uintptr_t hint = 0x4f0000000000ULL; |
| 23 | const uintptr_t app_start = 0x600000000000ULL; |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 24 | #elif defined (__mips64) |
| 25 | uintptr_t hint = 0x4f00000000ULL; |
| 26 | const uintptr_t app_start = 0x6000000000ULL; |
| 27 | #endif |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 28 | uintptr_t p = (uintptr_t)mmap( |
| 29 | (void *)hint, 4096, PROT_WRITE, |
| 30 | MAP_PRIVATE | MAP_ANONYMOUS | (FIXED ? MAP_FIXED : 0), -1, 0); |
| 31 | if (FIXED) |
| 32 | assert(p == (uintptr_t)-1 && errno == EINVAL); |
| 33 | else |
| 34 | assert(p >= app_start); |
| 35 | return 0; |
| 36 | } |