Use libunwindbacktrace for debug malloc code.
Create a method of disabling the debug allocation code paths so that
it's possible to use the libunwindbacktrace library without any
modifications.
Use this path to create and destroy the maps for the process. It's not
stricly necessary in the init code since the symbols are not modified
until after the initialize calls.
Also, remove the debug_XXX source files that doesn't need to be in libc.so.
Fix the maps reading code since it was completely broken for 64 bit.
Bug: 16408686
Change-Id: I6b02ef6ce26fdb7a59ad1029e7cbba9accceb704
diff --git a/libc/bionic/malloc_debug_leak.cpp b/libc/bionic/malloc_debug_leak.cpp
index d9824f0..7926a1f 100644
--- a/libc/bionic/malloc_debug_leak.cpp
+++ b/libc/bionic/malloc_debug_leak.cpp
@@ -48,6 +48,7 @@
#include "debug_stacktrace.h"
#include "malloc_debug_common.h"
+#include "malloc_debug_disable.h"
#include "private/bionic_macros.h"
#include "private/libc_logging.h"
@@ -267,6 +268,7 @@
return (*memptr != NULL) ? 0 : ENOMEM;
}
+#if defined(HAVE_DEPRECATED_MALLOC_FUNCS)
extern "C" void* fill_pvalloc(size_t bytes) {
size_t pagesize = getpagesize();
size_t size = BIONIC_ALIGN(bytes, pagesize);
@@ -279,6 +281,7 @@
extern "C" void* fill_valloc(size_t size) {
return fill_memalign(getpagesize(), size);
}
+#endif
// =============================================================================
// malloc leak functions
@@ -287,6 +290,10 @@
static uint32_t MEMALIGN_GUARD = 0xA1A41520;
extern "C" void* leak_malloc(size_t bytes) {
+ if (DebugCallsDisabled()) {
+ return g_malloc_dispatch->malloc(bytes);
+ }
+
// allocate enough space infront of the allocation to store the pointer for
// the alloc structure. This will making free'ing the structer really fast!
@@ -319,6 +326,10 @@
}
extern "C" void leak_free(void* mem) {
+ if (DebugCallsDisabled()) {
+ return g_malloc_dispatch->free(mem);
+ }
+
if (mem == NULL) {
return;
}
@@ -355,6 +366,10 @@
}
extern "C" void* leak_calloc(size_t n_elements, size_t elem_size) {
+ if (DebugCallsDisabled()) {
+ return g_malloc_dispatch->calloc(n_elements, elem_size);
+ }
+
// Fail on overflow - just to be safe even though this code runs only
// within the debugging C library, not the production one.
if (n_elements && SIZE_MAX / n_elements < elem_size) {
@@ -370,6 +385,10 @@
}
extern "C" void* leak_realloc(void* oldMem, size_t bytes) {
+ if (DebugCallsDisabled()) {
+ return g_malloc_dispatch->realloc(oldMem, bytes);
+ }
+
if (oldMem == NULL) {
return leak_malloc(bytes);
}
@@ -398,6 +417,10 @@
}
extern "C" void* leak_memalign(size_t alignment, size_t bytes) {
+ if (DebugCallsDisabled()) {
+ return g_malloc_dispatch->memalign(alignment, bytes);
+ }
+
// we can just use malloc
if (alignment <= MALLOC_ALIGNMENT) {
return leak_malloc(bytes);
@@ -439,6 +462,10 @@
}
extern "C" size_t leak_malloc_usable_size(const void* mem) {
+ if (DebugCallsDisabled()) {
+ return g_malloc_dispatch->malloc_usable_size(mem);
+ }
+
if (mem != NULL) {
// Check the guard to make sure it is valid.
const AllocationEntry* header = const_to_header((void*)mem);
@@ -467,6 +494,10 @@
}
extern "C" int leak_posix_memalign(void** memptr, size_t alignment, size_t size) {
+ if (DebugCallsDisabled()) {
+ return g_malloc_dispatch->posix_memalign(memptr, alignment, size);
+ }
+
if (!powerof2(alignment)) {
return EINVAL;
}
@@ -476,7 +507,12 @@
return (*memptr != NULL) ? 0 : ENOMEM;
}
+#if defined(HAVE_DEPRECATED_MALLOC_FUNCS)
extern "C" void* leak_pvalloc(size_t bytes) {
+ if (DebugCallsDisabled()) {
+ return g_malloc_dispatch->pvalloc(bytes);
+ }
+
size_t pagesize = getpagesize();
size_t size = BIONIC_ALIGN(bytes, pagesize);
if (size < bytes) { // Overflow
@@ -486,5 +522,10 @@
}
extern "C" void* leak_valloc(size_t size) {
+ if (DebugCallsDisabled()) {
+ return g_malloc_dispatch->valloc(size);
+ }
+
return leak_memalign(getpagesize(), size);
}
+#endif