summaryrefslogtreecommitdiffstats
path: root/compiler-rt/lib/msan/lit_tests
diff options
context:
space:
mode:
authorEvgeniy Stepanov <eugeni.stepanov@gmail.com>2013-08-02 14:26:58 +0000
committerEvgeniy Stepanov <eugeni.stepanov@gmail.com>2013-08-02 14:26:58 +0000
commit44b77c26e492fe50eafa399882b7eaa965b2fae0 (patch)
tree13416ee8b1865316bb389e8924025e6b7b171d32 /compiler-rt/lib/msan/lit_tests
parent0389d883fc3614a419db65577a751f471186aacf (diff)
downloadbcm5719-llvm-44b77c26e492fe50eafa399882b7eaa965b2fae0.tar.gz
bcm5719-llvm-44b77c26e492fe50eafa399882b7eaa965b2fae0.zip
[msan] Allocator statistics interface and malloc hooks.
llvm-svn: 187653
Diffstat (limited to 'compiler-rt/lib/msan/lit_tests')
-rw-r--r--compiler-rt/lib/msan/lit_tests/malloc_hook.cc36
1 files changed, 36 insertions, 0 deletions
diff --git a/compiler-rt/lib/msan/lit_tests/malloc_hook.cc b/compiler-rt/lib/msan/lit_tests/malloc_hook.cc
new file mode 100644
index 00000000000..5e7e7dc857e
--- /dev/null
+++ b/compiler-rt/lib/msan/lit_tests/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" {
+bool __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;
+}
OpenPOWER on IntegriCloud