2014-01-27 17:12:22 +08:00
|
|
|
// Test mmap behavior when map address is below shadow range.
|
2014-02-10 17:37:03 +08:00
|
|
|
// With MAP_FIXED, we return EINVAL.
|
2014-01-27 17:12:22 +08:00
|
|
|
// Without MAP_FIXED, we ignore the address hint and map somewhere in
|
|
|
|
// application range.
|
|
|
|
|
2015-03-03 03:34:27 +08:00
|
|
|
// RUN: %clangxx_msan -O0 -DFIXED=0 %s -o %t && %run %t
|
|
|
|
// RUN: %clangxx_msan -O0 -DFIXED=1 %s -o %t && %run %t
|
|
|
|
// RUN: %clangxx_msan -O0 -DFIXED=0 -D_FILE_OFFSET_BITS=64 %s -o %t && %run %t
|
|
|
|
// RUN: %clangxx_msan -O0 -DFIXED=1 -D_FILE_OFFSET_BITS=64 %s -o %t && %run %t
|
2014-01-27 17:12:22 +08:00
|
|
|
|
|
|
|
#include <assert.h>
|
2014-02-10 17:37:03 +08:00
|
|
|
#include <errno.h>
|
2014-01-27 17:12:22 +08:00
|
|
|
#include <stdint.h>
|
|
|
|
#include <sys/mman.h>
|
|
|
|
|
|
|
|
int main(void) {
|
|
|
|
// Hint address just below shadow.
|
2015-05-06 17:31:33 +08:00
|
|
|
#if defined(__FreeBSD__) && defined(__x86_64__)
|
|
|
|
uintptr_t hint = 0x0f0000000000ULL;
|
|
|
|
const uintptr_t app_start = 0x000000000000ULL;
|
|
|
|
#elif defined(__x86_64__)
|
2014-02-10 17:37:03 +08:00
|
|
|
uintptr_t hint = 0x4f0000000000ULL;
|
2014-01-27 17:12:22 +08:00
|
|
|
const uintptr_t app_start = 0x600000000000ULL;
|
2015-02-18 17:24:19 +08:00
|
|
|
#elif defined (__mips64)
|
|
|
|
uintptr_t hint = 0x4f00000000ULL;
|
|
|
|
const uintptr_t app_start = 0x6000000000ULL;
|
2015-06-25 14:22:31 +08:00
|
|
|
#elif defined (__powerpc64__)
|
|
|
|
uintptr_t hint = 0x2f0000000000ULL;
|
|
|
|
const uintptr_t app_start = 0x300000000000ULL;
|
2015-09-16 23:12:25 +08:00
|
|
|
#elif defined (__aarch64__)
|
|
|
|
uintptr_t hint = 0x4f0000000ULL;
|
|
|
|
const uintptr_t app_start = 0x7000000000ULL;
|
2015-02-18 17:24:19 +08:00
|
|
|
#endif
|
2014-01-27 17:12:22 +08:00
|
|
|
uintptr_t p = (uintptr_t)mmap(
|
2014-02-10 17:37:03 +08:00
|
|
|
(void *)hint, 4096, PROT_WRITE,
|
|
|
|
MAP_PRIVATE | MAP_ANONYMOUS | (FIXED ? MAP_FIXED : 0), -1, 0);
|
|
|
|
if (FIXED)
|
|
|
|
assert(p == (uintptr_t)-1 && errno == EINVAL);
|
|
|
|
else
|
|
|
|
assert(p >= app_start);
|
2014-01-27 17:12:22 +08:00
|
|
|
return 0;
|
|
|
|
}
|