| 150 | } |
| 151 | |
| 152 | void MallocTracer::initialize() { |
| 153 | CodeCache* lib = Profiler::instance()->findLibraryByAddress((void*)MallocTracer::initialize); |
| 154 | assert(lib); |
| 155 | |
| 156 | resolveMallocSymbols(); |
| 157 | |
| 158 | SAVE_IMPORT(malloc); |
| 159 | SAVE_IMPORT(free); |
| 160 | SAVE_IMPORT(calloc); |
| 161 | SAVE_IMPORT(realloc); |
| 162 | SAVE_IMPORT(posix_memalign); |
| 163 | SAVE_IMPORT(aligned_alloc); |
| 164 | |
| 165 | detectNestedMalloc(); |
| 166 | |
| 167 | lib->mark( |
| 168 | [](const char* s) -> bool { |
| 169 | return strcmp(s, "malloc_hook") == 0 |
| 170 | || strcmp(s, "calloc_hook") == 0 |
| 171 | || strcmp(s, "realloc_hook") == 0 |
| 172 | || strcmp(s, "free_hook") == 0 |
| 173 | || strcmp(s, "posix_memalign_hook") == 0 |
| 174 | || strcmp(s, "aligned_alloc_hook") == 0; |
| 175 | }, |
| 176 | MARK_ASYNC_PROFILER); |
| 177 | } |
| 178 | |
| 179 | // To avoid complexity in hooking and tracking reentrancy, a TLS-based approach is not used. |
| 180 | // Reentrant allocation calls would result in double-accounting. However, this does not impact |
nothing calls this directly
no test coverage detected