diff options
| author | Christopher Ferris <cferris@google.com> | 2014-07-09 17:16:07 -0700 |
|---|---|---|
| committer | Christopher Ferris <cferris@google.com> | 2014-07-09 21:27:15 -0700 |
| commit | dda1c6c466c4f31de31d76c8be7e46c16b4b4209 (patch) | |
| tree | 33df23032fdd6451750acc4f87ea0e298d2cee5b /libc/bionic/malloc_debug_qemu.cpp | |
| parent | 4c199170a84e725a56b7d40c113c9d76a75d89ab (diff) | |
| download | bionic-dda1c6c466c4f31de31d76c8be7e46c16b4b4209.zip bionic-dda1c6c466c4f31de31d76c8be7e46c16b4b4209.tar.gz bionic-dda1c6c466c4f31de31d76c8be7e46c16b4b4209.tar.bz2 | |
Do not include libc_common in malloc debug code.
The inclusion of the static libc_common library in the malloc_debug_XXX.so
shared libraries causes constructors to be called twice. This doesn't seem
to have caused any issues when setting the libc.debug.malloc property.
However, jemalloc crashes because there are two jemalloc implementations,
one in the static libc_common library and one in the shared library. Each
implementation has created overlapping thread keys that are not the same.
The crash comes because one of the jemalloc keys is actually used by the
locale setting code. Thus if someone sets the locale, the jemalloc code
crashes trying to access the same key.
Change-Id: Iaac650a82d69064db148a6333e9403744f68b4a4
Diffstat (limited to 'libc/bionic/malloc_debug_qemu.cpp')
| -rw-r--r-- | libc/bionic/malloc_debug_qemu.cpp | 33 |
1 files changed, 19 insertions, 14 deletions
diff --git a/libc/bionic/malloc_debug_qemu.cpp b/libc/bionic/malloc_debug_qemu.cpp index fd5161a..d0069e1 100644 --- a/libc/bionic/malloc_debug_qemu.cpp +++ b/libc/bionic/malloc_debug_qemu.cpp @@ -336,6 +336,9 @@ static void dump_malloc_descriptor(char* str, // Static data // ============================================================================= +// The underlying malloc implementation to use to get memory. +static const MallocDebug* g_malloc_dispatch = NULL; + /* Emulator's magic page address. * This page (mapped on /dev/qemu_trace device) is used to fire up events * in the emulator. */ @@ -595,7 +598,9 @@ extern "C" void* qemu_instrumented_valloc(size_t); * Return: * 0 on success, or -1 on failure. */ -extern "C" bool malloc_debug_initialize(HashTable*) { +extern "C" bool malloc_debug_initialize(HashTable*, const MallocDebug* malloc_dispatch) { + g_malloc_dispatch = malloc_dispatch; + /* We will be using emulator's magic page to report memory allocation * activities. In essence, what magic page does, it translates writes to * the memory mapped spaces into writes to an I/O port that emulator @@ -693,7 +698,7 @@ extern "C" void* qemu_instrumented_malloc(size_t bytes) { errno = ENOMEM; return NULL; } - desc.ptr = Malloc(malloc)(size); + desc.ptr = g_malloc_dispatch->malloc(size); if (desc.ptr == NULL) { qemu_error_log("<libc_pid=%03u, pid=%03u> malloc(%zu): malloc(%zu) failed.", malloc_pid, getpid(), bytes, size); @@ -704,7 +709,7 @@ extern "C" void* qemu_instrumented_malloc(size_t bytes) { if (notify_qemu_malloc(&desc)) { log_mdesc(error, &desc, "<libc_pid=%03u, pid=%03u>: malloc: notify_malloc failed for ", malloc_pid, getpid()); - Malloc(free)(desc.ptr); + g_malloc_dispatch->free(desc.ptr); errno = ENOMEM; return NULL; } else { @@ -726,7 +731,7 @@ extern "C" void qemu_instrumented_free(void* mem) { if (mem == NULL) { // Just let go NULL free - Malloc(free)(mem); + g_malloc_dispatch->free(mem); return; } @@ -757,7 +762,7 @@ extern "C" void qemu_instrumented_free(void* mem) { } else { log_mdesc(info, &desc, "--- <libc_pid=%03u, pid=%03u> free(%p) -> ", malloc_pid, getpid(), mem); - Malloc(free)(desc.ptr); + g_malloc_dispatch->free(desc.ptr); } } @@ -816,7 +821,7 @@ extern "C" void* qemu_instrumented_calloc(size_t n_elements, size_t elem_size) { total_elements++; desc.suffix_size += (elem_size - total_size); } - desc.ptr = Malloc(calloc)(total_elements, elem_size); + desc.ptr = g_malloc_dispatch->calloc(total_elements, elem_size); if (desc.ptr == NULL) { error_log("<libc_pid=%03u, pid=%03u> calloc: calloc(%zu(%zu), %zu) (prx=%u, sfx=%u) failed.", malloc_pid, getpid(), n_elements, total_elements, elem_size, @@ -827,7 +832,7 @@ extern "C" void* qemu_instrumented_calloc(size_t n_elements, size_t elem_size) { if (notify_qemu_malloc(&desc)) { log_mdesc(error, &desc, "<libc_pid=%03u, pid=%03u>: calloc(%zu(%zu), %zu): notify_malloc failed for ", malloc_pid, getpid(), n_elements, total_elements, elem_size); - Malloc(free)(desc.ptr); + g_malloc_dispatch->free(desc.ptr); errno = ENOMEM; return NULL; } else { @@ -905,7 +910,7 @@ extern "C" void* qemu_instrumented_realloc(void* mem, size_t bytes) { errno = ENOMEM; return NULL; } - new_desc.ptr = Malloc(malloc)(new_size); + new_desc.ptr = g_malloc_dispatch->malloc(new_size); if (new_desc.ptr == NULL) { log_mdesc(error, &cur_desc, "<libc_pid=%03u, pid=%03u>: realloc(%p, %zu): malloc(%zu) failed on ", malloc_pid, getpid(), mem, bytes, new_size); @@ -924,7 +929,7 @@ extern "C" void* qemu_instrumented_realloc(void* mem, size_t bytes) { log_mdesc(error, &new_desc, "<libc_pid=%03u, pid=%03u>: realloc(%p, %zu) notify_malloc failed -> ", malloc_pid, getpid(), mem, bytes); log_mdesc(error, &cur_desc, " <- "); - Malloc(free)(new_desc.ptr); + g_malloc_dispatch->free(new_desc.ptr); errno = ENOMEM; return NULL; } @@ -940,11 +945,11 @@ extern "C" void* qemu_instrumented_realloc(void* mem, size_t bytes) { /* Since we registered new decriptor with the emulator, we need * to unregister it before freeing newly allocated block. */ notify_qemu_free(mallocdesc_user_ptr(&new_desc)); - Malloc(free)(new_desc.ptr); + g_malloc_dispatch->free(new_desc.ptr); errno = ENOMEM; return NULL; } - Malloc(free)(cur_desc.ptr); + g_malloc_dispatch->free(cur_desc.ptr); log_mdesc(info, &new_desc, "=== <libc_pid=%03u, pid=%03u>: realloc(%p, %zu) -> ", malloc_pid, getpid(), mem, bytes); @@ -985,7 +990,7 @@ extern "C" void* qemu_instrumented_memalign(size_t alignment, size_t bytes) { return NULL; } - desc.ptr = Malloc(memalign)(desc.prefix_size, size); + desc.ptr = g_malloc_dispatch->memalign(desc.prefix_size, size); if (desc.ptr == NULL) { error_log("<libc_pid=%03u, pid=%03u> memalign(%zx, %zu): malloc(%zu) failed.", malloc_pid, getpid(), alignment, bytes, size); @@ -994,7 +999,7 @@ extern "C" void* qemu_instrumented_memalign(size_t alignment, size_t bytes) { if (notify_qemu_malloc(&desc)) { log_mdesc(error, &desc, "<libc_pid=%03u, pid=%03u>: memalign(%zx, %zu): notify_malloc failed for ", malloc_pid, getpid(), alignment, bytes); - Malloc(free)(desc.ptr); + g_malloc_dispatch->free(desc.ptr); return NULL; } @@ -1032,7 +1037,7 @@ extern "C" size_t qemu_instrumented_malloc_usable_size(const void* mem) { } extern "C" struct mallinfo qemu_instrumented_mallinfo() { - return Malloc(mallinfo)(); + return g_malloc_dispatch->mallinfo(); } extern "C" int qemu_instrumented_posix_memalign(void** memptr, size_t alignment, size_t size) { |
