llvm-capstone/compiler-rt/test/msan/mmap_below_shadow.cc
Adhemerval Zanella 19074450ee [MSan] Enable MSAN for aarch64
This patch enabled msan for aarch64 with 39-bit VMA and 42-bit VMA.
As defined by lib/msan/msan.h the memory layout used is for 39-bit is:

   00 0000 0000 - 40 0000 0000:  invalid
   40 0000 0000 - 43 0000 0000:  shadow
   43 0000 0000 - 46 0000 0000:  origin
   46 0000 0000 - 55 0000 0000:  invalid
   55 0000 0000 - 56 0000 0000:  app (low)
   56 0000 0000 - 70 0000 0000:  invalid
   70 0000 0000 - 80 0000 0000:  app (high)

And for 42-bit VMA:

   000 0000 0000 - 100 0000 0000:  invalid
   100 0000 0000 - 11b 0000 0000:  shadow
   11b 0000 0000 - 120 0000 0000:  invalid
   120 0000 0000 - 13b 0000 0000:  origin
   13b 0000 0000 - 2aa 0000 0000:  invalid
   2aa 0000 0000 - 2ab 0000 0000:  app (low)
   2ab 0000 0000 - 3f0 0000 0000:  invalid
   3f0 0000 0000 - 400 0000 0000:  app (high)

Most of tests are passing with exception of:

   * Linux/mallinfo.cc
   * chained_origin_limits.cc
   * dlerror.cc
   * param_tls_limit.cc
   * signal_stress_test.cc
   * nonnull-arg.cpp

The 'Linux/mallinfo.cc' is due the fact AArch64 returns the sret in 'x8'
instead of default first argument 'x1'.  So a function prototype that
aims  to mimic (by using first argument as the return of function) won't
work. For GCC one can make a register alias (register var asm ("r8")), but
for clang it detects is an unused variable and generate wrong code.

The 'chained_origin_limits' is probably due a wrong code generation,
since it fails only when origin memory is used
(-fsanitize-memory-track-origins=2) and only in the returned code
(return buf[50]).

The 'signal_streess_test' and 'nonnull-arg' are due currently missing variadic
argument handling in memory sanitizer code instrumentation on LLVM side.

Both 'dlerror' and 'param_tls_test' are unknown failures that require
further investigation.

All the failures are XFAIL for aarch64 for now.

llvm-svn: 247809
2015-09-16 15:12:25 +00:00

43 lines
1.4 KiB
C++

// Test mmap behavior when map address is below shadow range.
// With MAP_FIXED, we return EINVAL.
// Without MAP_FIXED, we ignore the address hint and map somewhere in
// application range.
// 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
#include <assert.h>
#include <errno.h>
#include <stdint.h>
#include <sys/mman.h>
int main(void) {
// Hint address just below shadow.
#if defined(__FreeBSD__) && defined(__x86_64__)
uintptr_t hint = 0x0f0000000000ULL;
const uintptr_t app_start = 0x000000000000ULL;
#elif defined(__x86_64__)
uintptr_t hint = 0x4f0000000000ULL;
const uintptr_t app_start = 0x600000000000ULL;
#elif defined (__mips64)
uintptr_t hint = 0x4f00000000ULL;
const uintptr_t app_start = 0x6000000000ULL;
#elif defined (__powerpc64__)
uintptr_t hint = 0x2f0000000000ULL;
const uintptr_t app_start = 0x300000000000ULL;
#elif defined (__aarch64__)
uintptr_t hint = 0x4f0000000ULL;
const uintptr_t app_start = 0x7000000000ULL;
#endif
uintptr_t p = (uintptr_t)mmap(
(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);
return 0;
}