Pirama Arumuga Nainar | 7c91505 | 2015-04-08 08:58:29 -0700 | [diff] [blame] | 1 | // RUN: %clangxx_msan -O0 %s -o %t && %run %t |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 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> |
| 10 | |
| 11 | const char *mem_to_shadow(const char *p) { |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 12 | #if defined(__x86_64__) |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 13 | return (char *)((uintptr_t)p & ~0x400000000000ULL); |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 14 | #elif defined (__mips64) |
| 15 | return (char *)((uintptr_t)p & ~0x4000000000ULL); |
| 16 | #endif |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 17 | } |
| 18 | |
| 19 | int main(void) { |
| 20 | const char *s = "abcdef"; |
| 21 | assert(strlen(s) == 6); |
| 22 | assert(strlen(mem_to_shadow(s)) == 0); |
| 23 | |
| 24 | char *t = new char[42]; |
| 25 | t[41] = 0; |
| 26 | assert(strlen(mem_to_shadow(t)) == 41); |
| 27 | return 0; |
| 28 | } |