2015-03-03 03:34:27 +08:00
|
|
|
// RUN: %clangxx_msan -O0 %s -o %t && %run %t
|
2013-12-06 17:19:07 +08:00
|
|
|
|
|
|
|
// Check that strlen() and similar intercepted functions can be called on shadow
|
|
|
|
// memory.
|
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
2015-09-16 23:12:25 +08:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include "test.h"
|
2013-12-06 17:19:07 +08:00
|
|
|
|
|
|
|
const char *mem_to_shadow(const char *p) {
|
2015-02-18 17:24:19 +08:00
|
|
|
#if defined(__x86_64__)
|
2015-10-09 05:35:34 +08:00
|
|
|
return (char *)((uintptr_t)p ^ 0x500000000000ULL);
|
2015-02-18 17:24:19 +08:00
|
|
|
#elif defined (__mips64)
|
|
|
|
return (char *)((uintptr_t)p & ~0x4000000000ULL);
|
2015-06-25 14:22:31 +08:00
|
|
|
#elif defined(__powerpc64__)
|
|
|
|
#define LINEARIZE_MEM(mem) \
|
|
|
|
(((uintptr_t)(mem) & ~0x200000000000ULL) ^ 0x100000000000ULL)
|
|
|
|
return (char *)(LINEARIZE_MEM(p) + 0x080000000000ULL);
|
2015-09-16 23:12:25 +08:00
|
|
|
#elif defined(__aarch64__)
|
2015-10-29 21:04:19 +08:00
|
|
|
return (char *)((uintptr_t)p ^ 0x6000000000ULL);
|
2015-02-18 17:24:19 +08:00
|
|
|
#endif
|
2013-12-06 17:19:07 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int main(void) {
|
|
|
|
const char *s = "abcdef";
|
|
|
|
assert(strlen(s) == 6);
|
|
|
|
assert(strlen(mem_to_shadow(s)) == 0);
|
|
|
|
|
|
|
|
char *t = new char[42];
|
|
|
|
t[41] = 0;
|
|
|
|
assert(strlen(mem_to_shadow(t)) == 41);
|
|
|
|
return 0;
|
|
|
|
}
|