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>
|
|
|
|
|
|
|
|
const char *mem_to_shadow(const char *p) {
|
2015-02-18 17:24:19 +08:00
|
|
|
#if defined(__x86_64__)
|
2013-12-06 17:19:07 +08:00
|
|
|
return (char *)((uintptr_t)p & ~0x400000000000ULL);
|
2015-02-18 17:24:19 +08:00
|
|
|
#elif defined (__mips64)
|
|
|
|
return (char *)((uintptr_t)p & ~0x4000000000ULL);
|
|
|
|
#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;
|
|
|
|
}
|