]>
Commit | Line | Data |
---|---|---|
92a42be0 | 1 | // RUN: %clangxx_msan -O0 %s -o %t && %run %t |
1a4d82fc JJ |
2 | |
3 | // Check that strlen() and similar intercepted functions can be called on shadow | |
4 | // memory. | |
5 | ||
6 | #include <assert.h> | |
7 | #include <stdint.h> | |
8 | #include <stdio.h> | |
9 | #include <string.h> | |
92a42be0 SL |
10 | #include <stdlib.h> |
11 | #include "test.h" | |
1a4d82fc JJ |
12 | |
13 | const char *mem_to_shadow(const char *p) { | |
92a42be0 SL |
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); | |
24 | #endif | |
1a4d82fc JJ |
25 | } |
26 | ||
27 | int main(void) { | |
28 | const char *s = "abcdef"; | |
29 | assert(strlen(s) == 6); | |
30 | assert(strlen(mem_to_shadow(s)) == 0); | |
31 | ||
32 | char *t = new char[42]; | |
33 | t[41] = 0; | |
34 | assert(strlen(mem_to_shadow(t)) == 41); | |
35 | return 0; | |
36 | } |