From 6c619a0da3f96a26d91c1db48fd3e3be156aabe5 Mon Sep 17 00:00:00 2001 From: Christopher Ferris Date: Fri, 1 Mar 2019 17:59:51 -0800 Subject: Refactor the malloc_info code. malloc_info needs to be per native allocator, but the code treated it like a global function that doesn't depend on the native memory allocator. Update malloc debug to dump the actual pointers that it has been tracking. Test: bionic-unit-tests pass. Test: malloc debug tests pass. Test: malloc hook tests pass. Change-Id: I3b0d4d748489dd84c16d16933479dc8b8d79013e Merged-In: I3b0d4d748489dd84c16d16933479dc8b8d79013e (cherry picked from commit a3656a98b10d2a4a6194a5d9705ad9c2cc5877b0) --- libc/malloc_hooks/malloc_hooks.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'libc/malloc_hooks/malloc_hooks.cpp') diff --git a/libc/malloc_hooks/malloc_hooks.cpp b/libc/malloc_hooks/malloc_hooks.cpp index 715a6295b..07b668f08 100644 --- a/libc/malloc_hooks/malloc_hooks.cpp +++ b/libc/malloc_hooks/malloc_hooks.cpp @@ -29,6 +29,7 @@ #include #include #include +#include #include #include #include @@ -57,6 +58,7 @@ ssize_t hooks_malloc_backtrace(void* pointer, uintptr_t* frames, size_t frame_co void hooks_free_malloc_leak_info(uint8_t* info); size_t hooks_malloc_usable_size(void* pointer); void* hooks_malloc(size_t size); +int hooks_malloc_info(int options, FILE* fp); void hooks_free(void* pointer); void* hooks_memalign(size_t alignment, size_t bytes); void* hooks_aligned_alloc(size_t alignment, size_t bytes); @@ -174,6 +176,10 @@ int hooks_mallopt(int param, int value) { return g_dispatch->mallopt(param, value); } +int hooks_malloc_info(int options, FILE* fp) { + return g_dispatch->malloc_info(options, fp); +} + void* hooks_aligned_alloc(size_t alignment, size_t size) { if (__memalign_hook != nullptr && __memalign_hook != default_memalign_hook) { if (!powerof2(alignment) || (size % alignment) != 0) { @@ -191,7 +197,7 @@ void* hooks_aligned_alloc(size_t alignment, size_t size) { int hooks_posix_memalign(void** memptr, size_t alignment, size_t size) { if (__memalign_hook != nullptr && __memalign_hook != default_memalign_hook) { - if (!powerof2(alignment)) { + if (alignment < sizeof(void*) || !powerof2(alignment)) { return EINVAL; } *memptr = __memalign_hook(alignment, size, __builtin_return_address(0)); -- cgit v1.2.3