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 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 10 11 #include <assert.h> 12 #include <errno.h> 13 #include <stdint.h> 14 #include <sys/mman.h> 15 main(void)16int main(void) { 17 // Hint address just below shadow. 18 #if defined(__FreeBSD__) && defined(__x86_64__) 19 uintptr_t hint = 0x0f0000000000ULL; 20 const uintptr_t app_start = 0x000000000000ULL; 21 #elif defined(__x86_64__) 22 uintptr_t hint = 0x4f0000000000ULL; 23 const uintptr_t app_start = 0x600000000000ULL; 24 #elif defined (__mips64) 25 uintptr_t hint = 0x4f00000000ULL; 26 const uintptr_t app_start = 0x6000000000ULL; 27 #elif defined (__powerpc64__) 28 uintptr_t hint = 0x2f0000000000ULL; 29 const uintptr_t app_start = 0x300000000000ULL; 30 #elif defined (__aarch64__) 31 uintptr_t hint = 0x4f0000000ULL; 32 const uintptr_t app_start = 0x7000000000ULL; 33 #endif 34 uintptr_t p = (uintptr_t)mmap( 35 (void *)hint, 4096, PROT_WRITE, 36 MAP_PRIVATE | MAP_ANONYMOUS | (FIXED ? MAP_FIXED : 0), -1, 0); 37 if (FIXED) 38 assert(p == (uintptr_t)-1 && errno == EINVAL); 39 else 40 assert(p >= app_start); 41 return 0; 42 } 43