diff options
author | Alexey Samsonov <samsonov@google.com> | 2014-02-14 13:02:58 +0000 |
---|---|---|
committer | Alexey Samsonov <samsonov@google.com> | 2014-02-14 13:02:58 +0000 |
commit | 8434e60f7e2d8e5da48d94f612cf980a5d63bcec (patch) | |
tree | 50cad838f4fa63729797db962033eb72ddcb0fe1 /compiler-rt/test/msan/malloc_hook.cc | |
parent | 0de2b9b1e2d7a24a54b64e7302536b59c3010c38 (diff) | |
download | bcm5719-llvm-8434e60f7e2d8e5da48d94f612cf980a5d63bcec.tar.gz bcm5719-llvm-8434e60f7e2d8e5da48d94f612cf980a5d63bcec.zip |
Move MSan lit-tests under test/msan
llvm-svn: 201412
Diffstat (limited to 'compiler-rt/test/msan/malloc_hook.cc')
-rw-r--r-- | compiler-rt/test/msan/malloc_hook.cc | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/compiler-rt/test/msan/malloc_hook.cc b/compiler-rt/test/msan/malloc_hook.cc new file mode 100644 index 00000000000..fc68fbc35fb --- /dev/null +++ b/compiler-rt/test/msan/malloc_hook.cc @@ -0,0 +1,36 @@ +// RUN: %clangxx_msan -O2 %s -o %t +// RUN: %t 2>&1 | FileCheck %s +#include <stdlib.h> +#include <unistd.h> + +extern "C" { +int __msan_get_ownership(const void *p); + +void *global_ptr; + +// Note: avoid calling functions that allocate memory in malloc/free +// to avoid infinite recursion. +void __msan_malloc_hook(void *ptr, size_t sz) { + if (__msan_get_ownership(ptr)) { + write(1, "MallocHook\n", sizeof("MallocHook\n")); + global_ptr = ptr; + } +} +void __msan_free_hook(void *ptr) { + if (__msan_get_ownership(ptr) && ptr == global_ptr) + write(1, "FreeHook\n", sizeof("FreeHook\n")); +} +} // extern "C" + +int main() { + volatile int *x = new int; + // CHECK: MallocHook + // Check that malloc hook was called with correct argument. + if (global_ptr != (void*)x) { + _exit(1); + } + *x = 0; + delete x; + // CHECK: FreeHook + return 0; +} |