diff options
| -rw-r--r-- | compiler-rt/test/sanitizer_common/TestCases/malloc_hook.cc | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/compiler-rt/test/sanitizer_common/TestCases/malloc_hook.cc b/compiler-rt/test/sanitizer_common/TestCases/malloc_hook.cc index 9702249c57e..7a45f8dfb23 100644 --- a/compiler-rt/test/sanitizer_common/TestCases/malloc_hook.cc +++ b/compiler-rt/test/sanitizer_common/TestCases/malloc_hook.cc @@ -13,7 +13,7 @@ const volatile void *global_ptr; // Note: avoid calling functions that allocate memory in malloc/free // to avoid infinite recursion. void __sanitizer_malloc_hook(const volatile void *ptr, size_t sz) { - if (__sanitizer_get_ownership(ptr)) { + if (__sanitizer_get_ownership(ptr) && sz == 4) { write(1, "MallocHook\n", sizeof("MallocHook\n")); global_ptr = ptr; } @@ -24,8 +24,18 @@ void __sanitizer_free_hook(const volatile void *ptr) { } } // extern "C" +volatile int *x; + +// Call this function with uninitialized arguments to poison +// TLS shadow for function parameters before calling operator +// new and, eventually, user-provided hook. +__attribute__((noinline)) void allocate(int *unused1, int *unused2) { + x = new int; +} + int main() { - volatile int *x = new int; + int *undef1, *undef2; + allocate(undef1, undef2); // CHECK: MallocHook // Check that malloc hook was called with correct argument. if (global_ptr != (void*)x) { |

