]>
git.proxmox.com Git - rustc.git/blob - src/compiler-rt/test/msan/strlen_of_shadow.cc
1 // RUN: %clangxx_msan -O0 %s -o %t && %run %t
3 // Check that strlen() and similar intercepted functions can be called on shadow
13 const char *mem_to_shadow(const char *p
) {
14 #if defined(__x86_64__)
15 return (char *)((uintptr_t)p
^ 0x500000000000ULL
);
16 #elif defined (__mips64)
17 return (char *)((uintptr_t)p
& ~0x4000000000ULL
);
18 #elif defined(__powerpc64__)
19 #define LINEARIZE_MEM(mem) \
20 (((uintptr_t)(mem) & ~0x200000000000ULL) ^ 0x100000000000ULL)
21 return (char *)(LINEARIZE_MEM(p
) + 0x080000000000ULL
);
22 #elif defined(__aarch64__)
23 return (char *)((uintptr_t)p
^ 0x6000000000ULL
);
28 const char *s
= "abcdef";
29 assert(strlen(s
) == 6);
30 assert(strlen(mem_to_shadow(s
)) == 0);
32 char *t
= new char[42];
34 assert(strlen(mem_to_shadow(t
)) == 41);