1 // RUN: %clangxx_msan -O0 %s -o %t && %run %t 2 3 // Check that strlen() and similar intercepted functions can be called on shadow 4 // memory. 5 // The mem_to_shadow's part might need rework 6 // XFAIL: freebsd 7 8 #include <assert.h> 9 #include <stdint.h> 10 #include <stdio.h> 11 #include <string.h> 12 #include <stdlib.h> 13 #include "test.h" 14 15 const char *mem_to_shadow(const char *p) { 16 #if defined(__x86_64__) 17 return (char *)((uintptr_t)p ^ 0x500000000000ULL); 18 #elif defined (__mips64) 19 return (char *)((uintptr_t)p ^ 0x8000000000ULL); 20 #elif defined(__powerpc64__) 21 #define LINEARIZE_MEM(mem) \ 22 (((uintptr_t)(mem) & ~0x200000000000ULL) ^ 0x100000000000ULL) 23 return (char *)(LINEARIZE_MEM(p) + 0x080000000000ULL); 24 #elif defined(__aarch64__) 25 return (char *)((uintptr_t)p ^ 0x6000000000ULL); 26 #endif 27 } 28 29 int main(void) { 30 const char *s = "abcdef"; 31 assert(strlen(s) == 6); 32 assert(strlen(mem_to_shadow(s)) == 0); 33 34 char *t = new char[42]; 35 t[41] = 0; 36 assert(strlen(mem_to_shadow(t)) == 41); 37 return 0; 38 } 39