]>
git.proxmox.com Git - rustc.git/blob - src/compiler-rt/test/sanitizer_common/TestCases/malloc_hook.cc
1 // RUN: %clangxx -O2 %s -o %t && %run %t 2>&1 | FileCheck %s
3 // Malloc/free hooks are not supported on Windows.
8 #include <sanitizer/allocator_interface.h>
11 const volatile void *global_ptr
;
13 // Note: avoid calling functions that allocate memory in malloc/free
14 // to avoid infinite recursion.
15 void __sanitizer_malloc_hook(const volatile void *ptr
, size_t sz
) {
16 if (__sanitizer_get_ownership(ptr
)) {
17 write(1, "MallocHook\n", sizeof("MallocHook\n"));
21 void __sanitizer_free_hook(const volatile void *ptr
) {
22 if (__sanitizer_get_ownership(ptr
) && ptr
== global_ptr
)
23 write(1, "FreeHook\n", sizeof("FreeHook\n"));
28 volatile int *x
= new int;
30 // Check that malloc hook was called with correct argument.
31 if (global_ptr
!= (void*)x
) {