| Vladimir Chtchetkine | b74ceb2 | 2009-11-17 14:13:38 -0800 | [diff] [blame] | 1 | /* | 
|  | 2 | * Copyright (C) 2009 The Android Open Source Project | 
|  | 3 | * All rights reserved. | 
|  | 4 | * | 
|  | 5 | * Redistribution and use in source and binary forms, with or without | 
|  | 6 | * modification, are permitted provided that the following conditions | 
|  | 7 | * are met: | 
|  | 8 | *  * Redistributions of source code must retain the above copyright | 
|  | 9 | *    notice, this list of conditions and the following disclaimer. | 
|  | 10 | *  * Redistributions in binary form must reproduce the above copyright | 
|  | 11 | *    notice, this list of conditions and the following disclaimer in | 
|  | 12 | *    the documentation and/or other materials provided with the | 
|  | 13 | *    distribution. | 
|  | 14 | * | 
|  | 15 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 
|  | 16 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 
|  | 17 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS | 
|  | 18 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE | 
|  | 19 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, | 
|  | 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | 
|  | 21 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS | 
|  | 22 | * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED | 
|  | 23 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | 
|  | 24 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT | 
|  | 25 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 
|  | 26 | * SUCH DAMAGE. | 
|  | 27 | */ | 
|  | 28 |  | 
| Christopher Ferris | a403780 | 2014-06-09 19:14:11 -0700 | [diff] [blame] | 29 | // Contains definition of structures, global variables, and implementation of | 
|  | 30 | // routines that are used by malloc leak detection code and other components in | 
|  | 31 | // the system. The trick is that some components expect these data and | 
| Christopher Ferris | 6fe376d | 2014-09-19 12:26:09 -0700 | [diff] [blame] | 32 | // routines to be defined / implemented in libc.so, regardless whether or not | 
|  | 33 | // malloc leak detection code is going to run. To make things even more tricky, | 
|  | 34 | // malloc leak detection code, implemented in libc_malloc_debug.so also | 
|  | 35 | // requires access to these variables and routines (to fill allocation entry | 
|  | 36 | // hash table, for example). So, all relevant variables and routines are | 
|  | 37 | // defined / implemented here and exported to all, leak detection code and | 
|  | 38 | // other components via dynamic (libc.so), or static (libc.a) linking. | 
| Vladimir Chtchetkine | b74ceb2 | 2009-11-17 14:13:38 -0800 | [diff] [blame] | 39 |  | 
| Vladimir Chtchetkine | b74ceb2 | 2009-11-17 14:13:38 -0800 | [diff] [blame] | 40 | #include "malloc_debug_common.h" | 
|  | 41 |  | 
| Elliott Hughes | 3b297c4 | 2012-10-11 16:08:51 -0700 | [diff] [blame] | 42 | #include <pthread.h> | 
|  | 43 | #include <stdlib.h> | 
| Elliott Hughes | 05fc1d7 | 2015-01-28 18:02:33 -0800 | [diff] [blame] | 44 | #include <string.h> | 
| Elliott Hughes | 3b297c4 | 2012-10-11 16:08:51 -0700 | [diff] [blame] | 45 | #include <unistd.h> | 
|  | 46 |  | 
| Josh Gao | 3c8fc2f | 2015-10-08 14:49:26 -0700 | [diff] [blame] | 47 | #include "private/bionic_globals.h" | 
| Elliott Hughes | eb847bc | 2013-10-09 15:50:50 -0700 | [diff] [blame] | 48 | #include "private/ScopedPthreadMutexLocker.h" | 
| Elliott Hughes | 3b297c4 | 2012-10-11 16:08:51 -0700 | [diff] [blame] | 49 |  | 
| Christopher Ferris | dda1c6c | 2014-07-09 17:16:07 -0700 | [diff] [blame] | 50 | #if defined(USE_JEMALLOC) | 
|  | 51 | #include "jemalloc.h" | 
|  | 52 | #define Malloc(function)  je_ ## function | 
|  | 53 | #elif defined(USE_DLMALLOC) | 
|  | 54 | #include "dlmalloc.h" | 
|  | 55 | #define Malloc(function)  dl ## function | 
|  | 56 | #else | 
|  | 57 | #error "Either one of USE_DLMALLOC or USE_JEMALLOC must be defined." | 
|  | 58 | #endif | 
|  | 59 |  | 
| Josh Gao | 3c8fc2f | 2015-10-08 14:49:26 -0700 | [diff] [blame] | 60 | static constexpr MallocDebug __libc_malloc_default_dispatch | 
|  | 61 | __attribute__((unused)) = { | 
|  | 62 | Malloc(calloc), | 
|  | 63 | Malloc(free), | 
|  | 64 | Malloc(mallinfo), | 
|  | 65 | Malloc(malloc), | 
|  | 66 | Malloc(malloc_usable_size), | 
|  | 67 | Malloc(memalign), | 
|  | 68 | Malloc(posix_memalign), | 
|  | 69 | #if defined(HAVE_DEPRECATED_MALLOC_FUNCS) | 
|  | 70 | Malloc(pvalloc), | 
|  | 71 | #endif | 
|  | 72 | Malloc(realloc), | 
|  | 73 | #if defined(HAVE_DEPRECATED_MALLOC_FUNCS) | 
|  | 74 | Malloc(valloc), | 
|  | 75 | #endif | 
|  | 76 | }; | 
|  | 77 |  | 
| Elliott Hughes | 8e52e8f | 2014-06-04 12:07:11 -0700 | [diff] [blame] | 78 | // In a VM process, this is set to 1 after fork()ing out of zygote. | 
| Vladimir Chtchetkine | b74ceb2 | 2009-11-17 14:13:38 -0800 | [diff] [blame] | 79 | int gMallocLeakZygoteChild = 0; | 
|  | 80 |  | 
| Elliott Hughes | 8e52e8f | 2014-06-04 12:07:11 -0700 | [diff] [blame] | 81 | static HashTable g_hash_table; | 
|  | 82 |  | 
| Elliott Hughes | 8e52e8f | 2014-06-04 12:07:11 -0700 | [diff] [blame] | 83 | // Handle to shared library where actual memory allocation is implemented. | 
|  | 84 | // This library is loaded and memory allocation calls are redirected there | 
|  | 85 | // when libc.debug.malloc environment variable contains value other than | 
|  | 86 | // zero: | 
|  | 87 | // 1  - For memory leak detections. | 
|  | 88 | // 5  - For filling allocated / freed memory with patterns defined by | 
|  | 89 | //      CHK_SENTINEL_VALUE, and CHK_FILL_FREE macros. | 
|  | 90 | // 10 - For adding pre-, and post- allocation stubs in order to detect | 
|  | 91 | //      buffer overruns. | 
|  | 92 | // Note that emulator's memory allocation instrumentation is not controlled by | 
|  | 93 | // libc.debug.malloc value, but rather by emulator, started with -memcheck | 
|  | 94 | // option. Note also, that if emulator has started with -memcheck option, | 
|  | 95 | // emulator's instrumented memory allocation will take over value saved in | 
|  | 96 | // libc.debug.malloc. In other words, if emulator has started with -memcheck | 
|  | 97 | // option, libc.debug.malloc value is ignored. | 
|  | 98 | // Actual functionality for debug levels 1-10 is implemented in | 
|  | 99 | // libc_malloc_debug_leak.so, while functionality for emulator's instrumented | 
|  | 100 | // allocations is implemented in libc_malloc_debug_qemu.so and can be run inside | 
|  | 101 | // the emulator only. | 
|  | 102 | #if !defined(LIBC_STATIC) | 
|  | 103 | static void* libc_malloc_impl_handle = NULL; | 
|  | 104 | #endif | 
|  | 105 |  | 
|  | 106 |  | 
|  | 107 | // The value of libc.debug.malloc. | 
|  | 108 | #if !defined(LIBC_STATIC) | 
|  | 109 | static int g_malloc_debug_level = 0; | 
|  | 110 | #endif | 
| Vladimir Chtchetkine | b74ceb2 | 2009-11-17 14:13:38 -0800 | [diff] [blame] | 111 |  | 
|  | 112 | // ============================================================================= | 
|  | 113 | // output functions | 
|  | 114 | // ============================================================================= | 
|  | 115 |  | 
| Elliott Hughes | c4d1fec | 2012-08-28 14:15:04 -0700 | [diff] [blame] | 116 | static int hash_entry_compare(const void* arg1, const void* arg2) { | 
| Christopher Ferris | a403780 | 2014-06-09 19:14:11 -0700 | [diff] [blame] | 117 | int result; | 
| Christopher Tate | 52e7d3d | 2010-08-09 13:43:46 -0700 | [diff] [blame] | 118 |  | 
| Christopher Ferris | a403780 | 2014-06-09 19:14:11 -0700 | [diff] [blame] | 119 | const HashEntry* e1 = *static_cast<HashEntry* const*>(arg1); | 
|  | 120 | const HashEntry* e2 = *static_cast<HashEntry* const*>(arg2); | 
| Vladimir Chtchetkine | b74ceb2 | 2009-11-17 14:13:38 -0800 | [diff] [blame] | 121 |  | 
| Christopher Ferris | a403780 | 2014-06-09 19:14:11 -0700 | [diff] [blame] | 122 | // if one or both arg pointers are null, deal gracefully | 
|  | 123 | if (e1 == NULL) { | 
|  | 124 | result = (e2 == NULL) ? 0 : 1; | 
|  | 125 | } else if (e2 == NULL) { | 
|  | 126 | result = -1; | 
|  | 127 | } else { | 
|  | 128 | size_t nbAlloc1 = e1->allocations; | 
|  | 129 | size_t nbAlloc2 = e2->allocations; | 
|  | 130 | size_t size1 = e1->size & ~SIZE_FLAG_MASK; | 
|  | 131 | size_t size2 = e2->size & ~SIZE_FLAG_MASK; | 
|  | 132 | size_t alloc1 = nbAlloc1 * size1; | 
|  | 133 | size_t alloc2 = nbAlloc2 * size2; | 
|  | 134 |  | 
|  | 135 | // sort in descending order by: | 
|  | 136 | // 1) total size | 
|  | 137 | // 2) number of allocations | 
|  | 138 | // | 
|  | 139 | // This is used for sorting, not determination of equality, so we don't | 
|  | 140 | // need to compare the bit flags. | 
|  | 141 | if (alloc1 > alloc2) { | 
|  | 142 | result = -1; | 
|  | 143 | } else if (alloc1 < alloc2) { | 
|  | 144 | result = 1; | 
| Vladimir Chtchetkine | b74ceb2 | 2009-11-17 14:13:38 -0800 | [diff] [blame] | 145 | } else { | 
| Christopher Ferris | a403780 | 2014-06-09 19:14:11 -0700 | [diff] [blame] | 146 | if (nbAlloc1 > nbAlloc2) { | 
|  | 147 | result = -1; | 
|  | 148 | } else if (nbAlloc1 < nbAlloc2) { | 
|  | 149 | result = 1; | 
|  | 150 | } else { | 
|  | 151 | result = 0; | 
|  | 152 | } | 
| Vladimir Chtchetkine | b74ceb2 | 2009-11-17 14:13:38 -0800 | [diff] [blame] | 153 | } | 
| Christopher Ferris | a403780 | 2014-06-09 19:14:11 -0700 | [diff] [blame] | 154 | } | 
|  | 155 | return result; | 
| Vladimir Chtchetkine | b74ceb2 | 2009-11-17 14:13:38 -0800 | [diff] [blame] | 156 | } | 
|  | 157 |  | 
| Christopher Ferris | a403780 | 2014-06-09 19:14:11 -0700 | [diff] [blame] | 158 | // Retrieve native heap information. | 
|  | 159 | // | 
|  | 160 | // "*info" is set to a buffer we allocate | 
|  | 161 | // "*overallSize" is set to the size of the "info" buffer | 
|  | 162 | // "*infoSize" is set to the size of a single entry | 
|  | 163 | // "*totalMemory" is set to the sum of all allocations we're tracking; does | 
|  | 164 | //   not include heap overhead | 
|  | 165 | // "*backtraceSize" is set to the maximum number of entries in the back trace | 
| Elliott Hughes | 7c9923d | 2014-05-16 16:29:55 -0700 | [diff] [blame] | 166 |  | 
| Christopher Ferris | a403780 | 2014-06-09 19:14:11 -0700 | [diff] [blame] | 167 | // ============================================================================= | 
| Elliott Hughes | 7c9923d | 2014-05-16 16:29:55 -0700 | [diff] [blame] | 168 | // Exported for use by ddms. | 
| Christopher Ferris | a403780 | 2014-06-09 19:14:11 -0700 | [diff] [blame] | 169 | // ============================================================================= | 
| Elliott Hughes | 7c9923d | 2014-05-16 16:29:55 -0700 | [diff] [blame] | 170 | extern "C" void get_malloc_leak_info(uint8_t** info, size_t* overallSize, | 
| Christopher Ferris | a403780 | 2014-06-09 19:14:11 -0700 | [diff] [blame] | 171 | size_t* infoSize, size_t* totalMemory, size_t* backtraceSize) { | 
|  | 172 | // Don't do anything if we have invalid arguments. | 
|  | 173 | if (info == NULL || overallSize == NULL || infoSize == NULL || | 
|  | 174 | totalMemory == NULL || backtraceSize == NULL) { | 
|  | 175 | return; | 
|  | 176 | } | 
|  | 177 | *totalMemory = 0; | 
|  | 178 |  | 
|  | 179 | ScopedPthreadMutexLocker locker(&g_hash_table.lock); | 
|  | 180 | if (g_hash_table.count == 0) { | 
|  | 181 | *info = NULL; | 
|  | 182 | *overallSize = 0; | 
|  | 183 | *infoSize = 0; | 
|  | 184 | *backtraceSize = 0; | 
|  | 185 | return; | 
|  | 186 | } | 
|  | 187 |  | 
|  | 188 | HashEntry** list = static_cast<HashEntry**>(Malloc(malloc)(sizeof(void*) * g_hash_table.count)); | 
|  | 189 |  | 
|  | 190 | // Get the entries into an array to be sorted. | 
|  | 191 | size_t index = 0; | 
|  | 192 | for (size_t i = 0 ; i < HASHTABLE_SIZE ; ++i) { | 
|  | 193 | HashEntry* entry = g_hash_table.slots[i]; | 
|  | 194 | while (entry != NULL) { | 
|  | 195 | list[index] = entry; | 
|  | 196 | *totalMemory = *totalMemory + ((entry->size & ~SIZE_FLAG_MASK) * entry->allocations); | 
|  | 197 | index++; | 
|  | 198 | entry = entry->next; | 
| Vladimir Chtchetkine | b74ceb2 | 2009-11-17 14:13:38 -0800 | [diff] [blame] | 199 | } | 
| Christopher Ferris | a403780 | 2014-06-09 19:14:11 -0700 | [diff] [blame] | 200 | } | 
| Vladimir Chtchetkine | b74ceb2 | 2009-11-17 14:13:38 -0800 | [diff] [blame] | 201 |  | 
| Christopher Ferris | a403780 | 2014-06-09 19:14:11 -0700 | [diff] [blame] | 202 | // XXX: the protocol doesn't allow variable size for the stack trace (yet) | 
|  | 203 | *infoSize = (sizeof(size_t) * 2) + (sizeof(uintptr_t) * BACKTRACE_SIZE); | 
|  | 204 | *overallSize = *infoSize * g_hash_table.count; | 
|  | 205 | *backtraceSize = BACKTRACE_SIZE; | 
| Vladimir Chtchetkine | b74ceb2 | 2009-11-17 14:13:38 -0800 | [diff] [blame] | 206 |  | 
| Christopher Ferris | a403780 | 2014-06-09 19:14:11 -0700 | [diff] [blame] | 207 | // now get a byte array big enough for this | 
|  | 208 | *info = static_cast<uint8_t*>(Malloc(malloc)(*overallSize)); | 
|  | 209 | if (*info == NULL) { | 
|  | 210 | *overallSize = 0; | 
| Christopher Ferris | 72bbd42 | 2014-05-08 11:14:03 -0700 | [diff] [blame] | 211 | Malloc(free)(list); | 
| Christopher Ferris | a403780 | 2014-06-09 19:14:11 -0700 | [diff] [blame] | 212 | return; | 
|  | 213 | } | 
|  | 214 |  | 
|  | 215 | qsort(list, g_hash_table.count, sizeof(void*), hash_entry_compare); | 
|  | 216 |  | 
|  | 217 | uint8_t* head = *info; | 
|  | 218 | const size_t count = g_hash_table.count; | 
|  | 219 | for (size_t i = 0 ; i < count ; ++i) { | 
|  | 220 | HashEntry* entry = list[i]; | 
|  | 221 | size_t entrySize = (sizeof(size_t) * 2) + (sizeof(uintptr_t) * entry->numEntries); | 
|  | 222 | if (entrySize < *infoSize) { | 
|  | 223 | // We're writing less than a full entry, clear out the rest. | 
|  | 224 | memset(head + entrySize, 0, *infoSize - entrySize); | 
|  | 225 | } else { | 
|  | 226 | // Make sure the amount we're copying doesn't exceed the limit. | 
|  | 227 | entrySize = *infoSize; | 
|  | 228 | } | 
|  | 229 | memcpy(head, &(entry->size), entrySize); | 
|  | 230 | head += *infoSize; | 
|  | 231 | } | 
|  | 232 |  | 
|  | 233 | Malloc(free)(list); | 
| Vladimir Chtchetkine | b74ceb2 | 2009-11-17 14:13:38 -0800 | [diff] [blame] | 234 | } | 
|  | 235 |  | 
| Elliott Hughes | 7c9923d | 2014-05-16 16:29:55 -0700 | [diff] [blame] | 236 | extern "C" void free_malloc_leak_info(uint8_t* info) { | 
| Christopher Ferris | a403780 | 2014-06-09 19:14:11 -0700 | [diff] [blame] | 237 | Malloc(free)(info); | 
| Vladimir Chtchetkine | b74ceb2 | 2009-11-17 14:13:38 -0800 | [diff] [blame] | 238 | } | 
|  | 239 |  | 
| Christopher Ferris | a403780 | 2014-06-09 19:14:11 -0700 | [diff] [blame] | 240 | // ============================================================================= | 
|  | 241 | // Allocation functions | 
|  | 242 | // ============================================================================= | 
|  | 243 | extern "C" void* calloc(size_t n_elements, size_t elem_size) { | 
| Josh Gao | 3c8fc2f | 2015-10-08 14:49:26 -0700 | [diff] [blame] | 244 | auto _calloc = __libc_globals->malloc_dispatch.calloc; | 
|  | 245 | if (__predict_false(_calloc != nullptr)) { | 
|  | 246 | return _calloc(n_elements, elem_size); | 
|  | 247 | } | 
|  | 248 | return Malloc(calloc)(n_elements, elem_size); | 
| Vladimir Chtchetkine | b74ceb2 | 2009-11-17 14:13:38 -0800 | [diff] [blame] | 249 | } | 
| Elliott Hughes | c4d1fec | 2012-08-28 14:15:04 -0700 | [diff] [blame] | 250 |  | 
|  | 251 | extern "C" void free(void* mem) { | 
| Josh Gao | 3c8fc2f | 2015-10-08 14:49:26 -0700 | [diff] [blame] | 252 | auto _free = __libc_globals->malloc_dispatch.free; | 
|  | 253 | if (__predict_false(_free != nullptr)) { | 
|  | 254 | _free(mem); | 
|  | 255 | } else { | 
|  | 256 | Malloc(free)(mem); | 
|  | 257 | } | 
| Vladimir Chtchetkine | b74ceb2 | 2009-11-17 14:13:38 -0800 | [diff] [blame] | 258 | } | 
| Elliott Hughes | c4d1fec | 2012-08-28 14:15:04 -0700 | [diff] [blame] | 259 |  | 
| Christopher Ferris | a403780 | 2014-06-09 19:14:11 -0700 | [diff] [blame] | 260 | extern "C" struct mallinfo mallinfo() { | 
| Josh Gao | 3c8fc2f | 2015-10-08 14:49:26 -0700 | [diff] [blame] | 261 | auto _mallinfo = __libc_globals->malloc_dispatch.mallinfo; | 
|  | 262 | if (__predict_false(_mallinfo != nullptr)) { | 
|  | 263 | return _mallinfo(); | 
|  | 264 | } | 
|  | 265 | return Malloc(mallinfo)(); | 
| Vladimir Chtchetkine | b74ceb2 | 2009-11-17 14:13:38 -0800 | [diff] [blame] | 266 | } | 
| Elliott Hughes | c4d1fec | 2012-08-28 14:15:04 -0700 | [diff] [blame] | 267 |  | 
| Christopher Ferris | a403780 | 2014-06-09 19:14:11 -0700 | [diff] [blame] | 268 | extern "C" void* malloc(size_t bytes) { | 
| Josh Gao | 3c8fc2f | 2015-10-08 14:49:26 -0700 | [diff] [blame] | 269 | auto _malloc = __libc_globals->malloc_dispatch.malloc; | 
|  | 270 | if (__predict_false(_malloc != nullptr)) { | 
|  | 271 | return _malloc(bytes); | 
|  | 272 | } | 
|  | 273 | return Malloc(malloc)(bytes); | 
| Vladimir Chtchetkine | b74ceb2 | 2009-11-17 14:13:38 -0800 | [diff] [blame] | 274 | } | 
|  | 275 |  | 
| Christopher Ferris | 885f3b9 | 2013-05-21 17:48:01 -0700 | [diff] [blame] | 276 | extern "C" size_t malloc_usable_size(const void* mem) { | 
| Josh Gao | 3c8fc2f | 2015-10-08 14:49:26 -0700 | [diff] [blame] | 277 | auto _malloc_usable_size = __libc_globals->malloc_dispatch.malloc_usable_size; | 
|  | 278 | if (__predict_false(_malloc_usable_size != nullptr)) { | 
|  | 279 | return _malloc_usable_size(mem); | 
|  | 280 | } | 
|  | 281 | return Malloc(malloc_usable_size)(mem); | 
| Christopher Ferris | 885f3b9 | 2013-05-21 17:48:01 -0700 | [diff] [blame] | 282 | } | 
|  | 283 |  | 
| Christopher Ferris | a403780 | 2014-06-09 19:14:11 -0700 | [diff] [blame] | 284 | extern "C" void* memalign(size_t alignment, size_t bytes) { | 
| Josh Gao | 3c8fc2f | 2015-10-08 14:49:26 -0700 | [diff] [blame] | 285 | auto _memalign = __libc_globals->malloc_dispatch.memalign; | 
|  | 286 | if (__predict_false(_memalign != nullptr)) { | 
|  | 287 | return _memalign(alignment, bytes); | 
|  | 288 | } | 
|  | 289 | return Malloc(memalign)(alignment, bytes); | 
| Christopher Ferris | a403780 | 2014-06-09 19:14:11 -0700 | [diff] [blame] | 290 | } | 
|  | 291 |  | 
|  | 292 | extern "C" int posix_memalign(void** memptr, size_t alignment, size_t size) { | 
| Josh Gao | 3c8fc2f | 2015-10-08 14:49:26 -0700 | [diff] [blame] | 293 | auto _posix_memalign = __libc_globals->malloc_dispatch.posix_memalign; | 
|  | 294 | if (__predict_false(_posix_memalign != nullptr)) { | 
|  | 295 | return _posix_memalign(memptr, alignment, size); | 
|  | 296 | } | 
|  | 297 | return Malloc(posix_memalign)(memptr, alignment, size); | 
| Christopher Ferris | a403780 | 2014-06-09 19:14:11 -0700 | [diff] [blame] | 298 | } | 
|  | 299 |  | 
| Dan Albert | e5fdaa4 | 2014-06-14 01:04:31 +0000 | [diff] [blame] | 300 | #if defined(HAVE_DEPRECATED_MALLOC_FUNCS) | 
| Christopher Ferris | a403780 | 2014-06-09 19:14:11 -0700 | [diff] [blame] | 301 | extern "C" void* pvalloc(size_t bytes) { | 
| Josh Gao | 3c8fc2f | 2015-10-08 14:49:26 -0700 | [diff] [blame] | 302 | auto _pvalloc = __libc_globals->malloc_dispatch.pvalloc; | 
|  | 303 | if (__predict_false(_pvalloc != nullptr)) { | 
|  | 304 | return _pvalloc(bytes); | 
|  | 305 | } | 
|  | 306 | return Malloc(pvalloc)(bytes); | 
| Christopher Ferris | a403780 | 2014-06-09 19:14:11 -0700 | [diff] [blame] | 307 | } | 
| Dan Albert | e5fdaa4 | 2014-06-14 01:04:31 +0000 | [diff] [blame] | 308 | #endif | 
| Christopher Ferris | a403780 | 2014-06-09 19:14:11 -0700 | [diff] [blame] | 309 |  | 
| Josh Gao | 3c8fc2f | 2015-10-08 14:49:26 -0700 | [diff] [blame] | 310 | extern "C" void* realloc(void* old_mem, size_t bytes) { | 
|  | 311 | auto _realloc = __libc_globals->malloc_dispatch.realloc; | 
|  | 312 | if (__predict_false(_realloc != nullptr)) { | 
|  | 313 | return _realloc(old_mem, bytes); | 
|  | 314 | } | 
|  | 315 | return Malloc(realloc)(old_mem, bytes); | 
| Christopher Ferris | a403780 | 2014-06-09 19:14:11 -0700 | [diff] [blame] | 316 | } | 
|  | 317 |  | 
| Dan Albert | e5fdaa4 | 2014-06-14 01:04:31 +0000 | [diff] [blame] | 318 | #if defined(HAVE_DEPRECATED_MALLOC_FUNCS) | 
| Christopher Ferris | a403780 | 2014-06-09 19:14:11 -0700 | [diff] [blame] | 319 | extern "C" void* valloc(size_t bytes) { | 
| Josh Gao | 3c8fc2f | 2015-10-08 14:49:26 -0700 | [diff] [blame] | 320 | auto _valloc = __libc_globals->malloc_dispatch.valloc; | 
|  | 321 | if (__predict_false(_valloc != nullptr)) { | 
|  | 322 | return _valloc(bytes); | 
|  | 323 | } | 
|  | 324 | return Malloc(valloc)(bytes); | 
| Christopher Ferris | a403780 | 2014-06-09 19:14:11 -0700 | [diff] [blame] | 325 | } | 
| Dan Albert | e5fdaa4 | 2014-06-14 01:04:31 +0000 | [diff] [blame] | 326 | #endif | 
| Christopher Ferris | a403780 | 2014-06-09 19:14:11 -0700 | [diff] [blame] | 327 |  | 
|  | 328 | // We implement malloc debugging only in libc.so, so the code below | 
|  | 329 | // must be excluded if we compile this file for static libc.a | 
| Vladimir Chtchetkine | b74ceb2 | 2009-11-17 14:13:38 -0800 | [diff] [blame] | 330 | #ifndef LIBC_STATIC | 
|  | 331 | #include <sys/system_properties.h> | 
|  | 332 | #include <dlfcn.h> | 
| Elliott Hughes | c4d1fec | 2012-08-28 14:15:04 -0700 | [diff] [blame] | 333 | #include <stdio.h> | 
| Elliott Hughes | eb847bc | 2013-10-09 15:50:50 -0700 | [diff] [blame] | 334 | #include "private/libc_logging.h" | 
| Vladimir Chtchetkine | b74ceb2 | 2009-11-17 14:13:38 -0800 | [diff] [blame] | 335 |  | 
| Christopher Ferris | 885f3b9 | 2013-05-21 17:48:01 -0700 | [diff] [blame] | 336 | template<typename FunctionType> | 
| Nick Kralevich | 35c1862 | 2013-10-03 14:59:05 -0700 | [diff] [blame] | 337 | static void InitMallocFunction(void* malloc_impl_handler, FunctionType* func, const char* prefix, const char* suffix) { | 
| Christopher Ferris | a403780 | 2014-06-09 19:14:11 -0700 | [diff] [blame] | 338 | char symbol[128]; | 
|  | 339 | snprintf(symbol, sizeof(symbol), "%s_%s", prefix, suffix); | 
|  | 340 | *func = reinterpret_cast<FunctionType>(dlsym(malloc_impl_handler, symbol)); | 
|  | 341 | if (*func == NULL) { | 
|  | 342 | error_log("%s: dlsym(\"%s\") failed", getprogname(), symbol); | 
|  | 343 | } | 
| Christopher Ferris | 885f3b9 | 2013-05-21 17:48:01 -0700 | [diff] [blame] | 344 | } | 
| Elliott Hughes | c4d1fec | 2012-08-28 14:15:04 -0700 | [diff] [blame] | 345 |  | 
| Christopher Ferris | 885f3b9 | 2013-05-21 17:48:01 -0700 | [diff] [blame] | 346 | static void InitMalloc(void* malloc_impl_handler, MallocDebug* table, const char* prefix) { | 
| Christopher Ferris | a403780 | 2014-06-09 19:14:11 -0700 | [diff] [blame] | 347 | __libc_format_log(ANDROID_LOG_INFO, "libc", "%s: using libc.debug.malloc %d (%s)\n", | 
|  | 348 | getprogname(), g_malloc_debug_level, prefix); | 
| Elliott Hughes | c4d1fec | 2012-08-28 14:15:04 -0700 | [diff] [blame] | 349 |  | 
| Christopher Ferris | a403780 | 2014-06-09 19:14:11 -0700 | [diff] [blame] | 350 | InitMallocFunction<MallocDebugCalloc>(malloc_impl_handler, &table->calloc, prefix, "calloc"); | 
|  | 351 | InitMallocFunction<MallocDebugFree>(malloc_impl_handler, &table->free, prefix, "free"); | 
|  | 352 | InitMallocFunction<MallocDebugMallinfo>(malloc_impl_handler, &table->mallinfo, prefix, "mallinfo"); | 
|  | 353 | InitMallocFunction<MallocDebugMalloc>(malloc_impl_handler, &table->malloc, prefix, "malloc"); | 
|  | 354 | InitMallocFunction<MallocDebugMallocUsableSize>(malloc_impl_handler, &table->malloc_usable_size, prefix, "malloc_usable_size"); | 
|  | 355 | InitMallocFunction<MallocDebugMemalign>(malloc_impl_handler, &table->memalign, prefix, "memalign"); | 
|  | 356 | InitMallocFunction<MallocDebugPosixMemalign>(malloc_impl_handler, &table->posix_memalign, prefix, "posix_memalign"); | 
| Dan Albert | e5fdaa4 | 2014-06-14 01:04:31 +0000 | [diff] [blame] | 357 | #if defined(HAVE_DEPRECATED_MALLOC_FUNCS) | 
| Christopher Ferris | a403780 | 2014-06-09 19:14:11 -0700 | [diff] [blame] | 358 | InitMallocFunction<MallocDebugPvalloc>(malloc_impl_handler, &table->pvalloc, prefix, "pvalloc"); | 
| Dan Albert | e5fdaa4 | 2014-06-14 01:04:31 +0000 | [diff] [blame] | 359 | #endif | 
| Christopher Ferris | a403780 | 2014-06-09 19:14:11 -0700 | [diff] [blame] | 360 | InitMallocFunction<MallocDebugRealloc>(malloc_impl_handler, &table->realloc, prefix, "realloc"); | 
| Dan Albert | e5fdaa4 | 2014-06-14 01:04:31 +0000 | [diff] [blame] | 361 | #if defined(HAVE_DEPRECATED_MALLOC_FUNCS) | 
| Christopher Ferris | a403780 | 2014-06-09 19:14:11 -0700 | [diff] [blame] | 362 | InitMallocFunction<MallocDebugValloc>(malloc_impl_handler, &table->valloc, prefix, "valloc"); | 
| Dan Albert | e5fdaa4 | 2014-06-14 01:04:31 +0000 | [diff] [blame] | 363 | #endif | 
| Elliott Hughes | c4d1fec | 2012-08-28 14:15:04 -0700 | [diff] [blame] | 364 | } | 
|  | 365 |  | 
| Christopher Ferris | a403780 | 2014-06-09 19:14:11 -0700 | [diff] [blame] | 366 | // Initializes memory allocation framework once per process. | 
| Josh Gao | 3c8fc2f | 2015-10-08 14:49:26 -0700 | [diff] [blame] | 367 | static void malloc_init_impl(libc_globals* globals) { | 
| Christopher Ferris | a403780 | 2014-06-09 19:14:11 -0700 | [diff] [blame] | 368 | const char* so_name = NULL; | 
|  | 369 | MallocDebugInit malloc_debug_initialize = NULL; | 
|  | 370 | unsigned int qemu_running = 0; | 
|  | 371 | unsigned int memcheck_enabled = 0; | 
|  | 372 | char env[PROP_VALUE_MAX]; | 
|  | 373 | char memcheck_tracing[PROP_VALUE_MAX]; | 
|  | 374 | char debug_program[PROP_VALUE_MAX]; | 
| Vladimir Chtchetkine | b74ceb2 | 2009-11-17 14:13:38 -0800 | [diff] [blame] | 375 |  | 
| Christopher Ferris | a403780 | 2014-06-09 19:14:11 -0700 | [diff] [blame] | 376 | // Get custom malloc debug level. Note that emulator started with | 
|  | 377 | // memory checking option will have priority over debug level set in | 
|  | 378 | // libc.debug.malloc system property. | 
|  | 379 | if (__system_property_get("ro.kernel.qemu", env) && atoi(env)) { | 
|  | 380 | qemu_running = 1; | 
|  | 381 | if (__system_property_get("ro.kernel.memcheck", memcheck_tracing)) { | 
|  | 382 | if (memcheck_tracing[0] != '0') { | 
|  | 383 | // Emulator has started with memory tracing enabled. Enforce it. | 
|  | 384 | g_malloc_debug_level = 20; | 
|  | 385 | memcheck_enabled = 1; | 
|  | 386 | } | 
| Vladimir Chtchetkine | 75fba68 | 2010-02-12 08:59:58 -0800 | [diff] [blame] | 387 | } | 
| Christopher Ferris | a403780 | 2014-06-09 19:14:11 -0700 | [diff] [blame] | 388 | } | 
| Vladimir Chtchetkine | 75fba68 | 2010-02-12 08:59:58 -0800 | [diff] [blame] | 389 |  | 
| Christopher Ferris | a403780 | 2014-06-09 19:14:11 -0700 | [diff] [blame] | 390 | // If debug level has not been set by memcheck option in the emulator, | 
|  | 391 | // lets grab it from libc.debug.malloc system property. | 
|  | 392 | if (g_malloc_debug_level == 0 && __system_property_get("libc.debug.malloc", env)) { | 
|  | 393 | g_malloc_debug_level = atoi(env); | 
|  | 394 | } | 
|  | 395 |  | 
|  | 396 | // Debug level 0 means that we should use default allocation routines. | 
|  | 397 | if (g_malloc_debug_level == 0) { | 
|  | 398 | return; | 
|  | 399 | } | 
|  | 400 |  | 
|  | 401 | // If libc.debug.malloc.program is set and is not a substring of progname, | 
|  | 402 | // then exit. | 
|  | 403 | if (__system_property_get("libc.debug.malloc.program", debug_program)) { | 
|  | 404 | if (!strstr(getprogname(), debug_program)) { | 
|  | 405 | return; | 
| Vladimir Chtchetkine | b74ceb2 | 2009-11-17 14:13:38 -0800 | [diff] [blame] | 406 | } | 
| Christopher Ferris | a403780 | 2014-06-09 19:14:11 -0700 | [diff] [blame] | 407 | } | 
| Vladimir Chtchetkine | b74ceb2 | 2009-11-17 14:13:38 -0800 | [diff] [blame] | 408 |  | 
| Christopher Ferris | a403780 | 2014-06-09 19:14:11 -0700 | [diff] [blame] | 409 | // mksh is way too leaky. http://b/7291287. | 
|  | 410 | if (g_malloc_debug_level >= 10) { | 
|  | 411 | if (strcmp(getprogname(), "sh") == 0 || strcmp(getprogname(), "/system/bin/sh") == 0) { | 
|  | 412 | return; | 
| Vladimir Chtchetkine | b74ceb2 | 2009-11-17 14:13:38 -0800 | [diff] [blame] | 413 | } | 
| Christopher Ferris | a403780 | 2014-06-09 19:14:11 -0700 | [diff] [blame] | 414 | } | 
| Vladimir Chtchetkine | b74ceb2 | 2009-11-17 14:13:38 -0800 | [diff] [blame] | 415 |  | 
| Christopher Ferris | a403780 | 2014-06-09 19:14:11 -0700 | [diff] [blame] | 416 | // Choose the appropriate .so for the requested debug level. | 
|  | 417 | switch (g_malloc_debug_level) { | 
|  | 418 | case 1: | 
|  | 419 | case 5: | 
|  | 420 | case 10: | 
|  | 421 | so_name = "libc_malloc_debug_leak.so"; | 
|  | 422 | break; | 
|  | 423 | case 20: | 
|  | 424 | // Quick check: debug level 20 can only be handled in emulator. | 
|  | 425 | if (!qemu_running) { | 
|  | 426 | error_log("%s: Debug level %d can only be set in emulator\n", | 
| Elliott Hughes | 8e52e8f | 2014-06-04 12:07:11 -0700 | [diff] [blame] | 427 | getprogname(), g_malloc_debug_level); | 
| Christopher Ferris | a403780 | 2014-06-09 19:14:11 -0700 | [diff] [blame] | 428 | return; | 
|  | 429 | } | 
|  | 430 | // Make sure that memory checking has been enabled in emulator. | 
|  | 431 | if (!memcheck_enabled) { | 
|  | 432 | error_log("%s: Memory checking is not enabled in the emulator\n", getprogname()); | 
|  | 433 | return; | 
|  | 434 | } | 
|  | 435 | so_name = "libc_malloc_debug_qemu.so"; | 
|  | 436 | break; | 
|  | 437 | default: | 
|  | 438 | error_log("%s: Debug level %d is unknown\n", getprogname(), g_malloc_debug_level); | 
|  | 439 | return; | 
|  | 440 | } | 
|  | 441 |  | 
|  | 442 | // Load .so that implements the required malloc debugging functionality. | 
| Dmitriy Ivanov | 84c10c2 | 2015-03-23 14:58:45 -0700 | [diff] [blame] | 443 | void* malloc_impl_handle = dlopen(so_name, RTLD_NOW); | 
| Christopher Ferris | a403780 | 2014-06-09 19:14:11 -0700 | [diff] [blame] | 444 | if (malloc_impl_handle == NULL) { | 
|  | 445 | error_log("%s: Missing module %s required for malloc debug level %d: %s", | 
|  | 446 | getprogname(), so_name, g_malloc_debug_level, dlerror()); | 
|  | 447 | return; | 
|  | 448 | } | 
|  | 449 |  | 
|  | 450 | // Initialize malloc debugging in the loaded module. | 
|  | 451 | malloc_debug_initialize = reinterpret_cast<MallocDebugInit>(dlsym(malloc_impl_handle, | 
|  | 452 | "malloc_debug_initialize")); | 
|  | 453 | if (malloc_debug_initialize == NULL) { | 
|  | 454 | error_log("%s: Initialization routine is not found in %s\n", getprogname(), so_name); | 
|  | 455 | dlclose(malloc_impl_handle); | 
|  | 456 | return; | 
|  | 457 | } | 
| Christopher Ferris | dda1c6c | 2014-07-09 17:16:07 -0700 | [diff] [blame] | 458 | if (!malloc_debug_initialize(&g_hash_table, &__libc_malloc_default_dispatch)) { | 
| Christopher Ferris | a403780 | 2014-06-09 19:14:11 -0700 | [diff] [blame] | 459 | dlclose(malloc_impl_handle); | 
|  | 460 | return; | 
|  | 461 | } | 
|  | 462 |  | 
|  | 463 | if (g_malloc_debug_level == 20) { | 
|  | 464 | // For memory checker we need to do extra initialization. | 
|  | 465 | typedef int (*MemCheckInit)(int, const char*); | 
|  | 466 | MemCheckInit memcheck_initialize = | 
|  | 467 | reinterpret_cast<MemCheckInit>(dlsym(malloc_impl_handle, "memcheck_initialize")); | 
|  | 468 | if (memcheck_initialize == NULL) { | 
|  | 469 | error_log("%s: memcheck_initialize routine is not found in %s\n", | 
|  | 470 | getprogname(), so_name); | 
|  | 471 | dlclose(malloc_impl_handle); | 
|  | 472 | return; | 
| Vladimir Chtchetkine | b74ceb2 | 2009-11-17 14:13:38 -0800 | [diff] [blame] | 473 | } | 
| Christopher Ferris | a403780 | 2014-06-09 19:14:11 -0700 | [diff] [blame] | 474 |  | 
|  | 475 | if (memcheck_initialize(MALLOC_ALIGNMENT, memcheck_tracing)) { | 
|  | 476 | dlclose(malloc_impl_handle); | 
|  | 477 | return; | 
|  | 478 | } | 
|  | 479 | } | 
|  | 480 |  | 
|  | 481 | // No need to init the dispatch table because we can only get | 
|  | 482 | // here if debug level is 1, 5, 10, or 20. | 
| Josh Gao | 3c8fc2f | 2015-10-08 14:49:26 -0700 | [diff] [blame] | 483 | MallocDebug malloc_dispatch_table; | 
| Christopher Ferris | a403780 | 2014-06-09 19:14:11 -0700 | [diff] [blame] | 484 | switch (g_malloc_debug_level) { | 
|  | 485 | case 1: | 
|  | 486 | InitMalloc(malloc_impl_handle, &malloc_dispatch_table, "leak"); | 
|  | 487 | break; | 
|  | 488 | case 5: | 
|  | 489 | InitMalloc(malloc_impl_handle, &malloc_dispatch_table, "fill"); | 
|  | 490 | break; | 
|  | 491 | case 10: | 
|  | 492 | InitMalloc(malloc_impl_handle, &malloc_dispatch_table, "chk"); | 
|  | 493 | break; | 
|  | 494 | case 20: | 
|  | 495 | InitMalloc(malloc_impl_handle, &malloc_dispatch_table, "qemu_instrumented"); | 
|  | 496 | break; | 
|  | 497 | default: | 
|  | 498 | break; | 
|  | 499 | } | 
|  | 500 |  | 
|  | 501 | // Make sure dispatch table is initialized | 
|  | 502 | if ((malloc_dispatch_table.calloc == NULL) || | 
|  | 503 | (malloc_dispatch_table.free == NULL) || | 
|  | 504 | (malloc_dispatch_table.mallinfo == NULL) || | 
|  | 505 | (malloc_dispatch_table.malloc == NULL) || | 
|  | 506 | (malloc_dispatch_table.malloc_usable_size == NULL) || | 
|  | 507 | (malloc_dispatch_table.memalign == NULL) || | 
|  | 508 | (malloc_dispatch_table.posix_memalign == NULL) || | 
| Dan Albert | e5fdaa4 | 2014-06-14 01:04:31 +0000 | [diff] [blame] | 509 | #if defined(HAVE_DEPRECATED_MALLOC_FUNCS) | 
| Christopher Ferris | a403780 | 2014-06-09 19:14:11 -0700 | [diff] [blame] | 510 | (malloc_dispatch_table.pvalloc == NULL) || | 
| Dan Albert | e5fdaa4 | 2014-06-14 01:04:31 +0000 | [diff] [blame] | 511 | #endif | 
|  | 512 | (malloc_dispatch_table.realloc == NULL) | 
|  | 513 | #if defined(HAVE_DEPRECATED_MALLOC_FUNCS) | 
|  | 514 | || (malloc_dispatch_table.valloc == NULL) | 
|  | 515 | #endif | 
|  | 516 | ) { | 
| Christopher Ferris | a403780 | 2014-06-09 19:14:11 -0700 | [diff] [blame] | 517 | error_log("%s: some symbols for libc.debug.malloc level %d were not found (see above)", | 
|  | 518 | getprogname(), g_malloc_debug_level); | 
|  | 519 | dlclose(malloc_impl_handle); | 
|  | 520 | } else { | 
| Josh Gao | 3c8fc2f | 2015-10-08 14:49:26 -0700 | [diff] [blame] | 521 | globals->malloc_dispatch = malloc_dispatch_table; | 
| Christopher Ferris | a403780 | 2014-06-09 19:14:11 -0700 | [diff] [blame] | 522 | libc_malloc_impl_handle = malloc_impl_handle; | 
|  | 523 | } | 
| Vladimir Chtchetkine | b74ceb2 | 2009-11-17 14:13:38 -0800 | [diff] [blame] | 524 | } | 
|  | 525 |  | 
| Elliott Hughes | c4d1fec | 2012-08-28 14:15:04 -0700 | [diff] [blame] | 526 | static void malloc_fini_impl() { | 
| Christopher Ferris | a403780 | 2014-06-09 19:14:11 -0700 | [diff] [blame] | 527 | if (libc_malloc_impl_handle != NULL) { | 
|  | 528 | MallocDebugFini malloc_debug_finalize = | 
|  | 529 | reinterpret_cast<MallocDebugFini>(dlsym(libc_malloc_impl_handle, "malloc_debug_finalize")); | 
|  | 530 | if (malloc_debug_finalize != NULL) { | 
| Christopher Ferris | efc134d | 2015-09-03 15:01:59 -0700 | [diff] [blame] | 531 | // Our BSD stdio implementation doesn't close the standard streams, | 
|  | 532 | // it only flushes them. And it doesn't do that until its atexit | 
|  | 533 | // handler is run, and we run first! It's great that other unclosed | 
|  | 534 | // FILE*s show up as malloc leaks, but we need to manually clean up | 
|  | 535 | // the standard streams ourselves. | 
|  | 536 | fclose(stdin); | 
|  | 537 | fclose(stdout); | 
|  | 538 | fclose(stderr); | 
|  | 539 |  | 
| Christopher Ferris | a403780 | 2014-06-09 19:14:11 -0700 | [diff] [blame] | 540 | malloc_debug_finalize(g_malloc_debug_level); | 
| Iliyan Malchev | e1dd3c2 | 2012-05-29 14:22:42 -0700 | [diff] [blame] | 541 | } | 
| Christopher Ferris | a403780 | 2014-06-09 19:14:11 -0700 | [diff] [blame] | 542 | } | 
| Iliyan Malchev | e1dd3c2 | 2012-05-29 14:22:42 -0700 | [diff] [blame] | 543 | } | 
|  | 544 |  | 
| Vladimir Chtchetkine | b74ceb2 | 2009-11-17 14:13:38 -0800 | [diff] [blame] | 545 | #endif  // !LIBC_STATIC | 
| Vladimir Chtchetkine | b74ceb2 | 2009-11-17 14:13:38 -0800 | [diff] [blame] | 546 |  | 
| Christopher Ferris | a403780 | 2014-06-09 19:14:11 -0700 | [diff] [blame] | 547 | // Initializes memory allocation framework. | 
| Josh Gao | 3c8fc2f | 2015-10-08 14:49:26 -0700 | [diff] [blame] | 548 | // This routine is called from __libc_init routines in libc_init_dynamic.cpp. | 
|  | 549 | __LIBC_HIDDEN__ void __libc_init_malloc(libc_globals* globals) { | 
|  | 550 | (void)globals; | 
| Christopher Ferris | a403780 | 2014-06-09 19:14:11 -0700 | [diff] [blame] | 551 | #if !defined(LIBC_STATIC) | 
| Josh Gao | 3c8fc2f | 2015-10-08 14:49:26 -0700 | [diff] [blame] | 552 | malloc_init_impl(globals); | 
|  | 553 | #endif | 
| Vladimir Chtchetkine | b74ceb2 | 2009-11-17 14:13:38 -0800 | [diff] [blame] | 554 | } | 
| Iliyan Malchev | e1dd3c2 | 2012-05-29 14:22:42 -0700 | [diff] [blame] | 555 |  | 
| Kito Cheng | ea48974 | 2013-04-12 16:13:34 +0800 | [diff] [blame] | 556 | extern "C" __LIBC_HIDDEN__ void malloc_debug_fini() { | 
| Christopher Ferris | a403780 | 2014-06-09 19:14:11 -0700 | [diff] [blame] | 557 | #if !defined(LIBC_STATIC) | 
| Elliott Hughes | 8e52e8f | 2014-06-04 12:07:11 -0700 | [diff] [blame] | 558 | static pthread_once_t malloc_fini_once_ctl = PTHREAD_ONCE_INIT; | 
|  | 559 | if (pthread_once(&malloc_fini_once_ctl, malloc_fini_impl)) { | 
|  | 560 | error_log("Unable to finalize malloc_debug component."); | 
|  | 561 | } | 
| Christopher Ferris | a403780 | 2014-06-09 19:14:11 -0700 | [diff] [blame] | 562 | #endif  // !LIBC_STATIC | 
| Iliyan Malchev | e1dd3c2 | 2012-05-29 14:22:42 -0700 | [diff] [blame] | 563 | } |