// Contains a thin layer that calls whatever real native allocator // has been defined. For the libc shared library, this allows the // implementation of a debug malloc that can intercept all of the allocation // calls and add special debugging code to attempt to catch allocation // errors. All of the debugging code is implemented in a separate shared // library that is only loaded when the property "libc.debug.malloc.options" // is set to a non-zero value.
extern"C"int mallopt(int param, int value) { // Some are handled by libc directly rather than by the allocator. if (param == M_BIONIC_SET_HEAP_TAGGING_LEVEL) {
ScopedPthreadMutexLocker locker(&g_heap_tagging_lock); return SetHeapTaggingLevel(static_cast<HeapTaggingLevel>(value));
} if (param == M_BIONIC_ZERO_INIT) { return SetHeapZeroInitialize(value);
}
// The rest we pass on... int retval; auto dispatch_table = GetDispatchTable(); if (__predict_false(dispatch_table != nullptr)) {
retval = dispatch_table->mallopt(param, value);
} else {
retval = Malloc(mallopt)(param, value);
}
// ============================================================================= // Exported for use by libmemunreachable. // =============================================================================
// Calls callback for every allocation in the anonymous heap mapping // [base, base+size). Must be called between malloc_disable and malloc_enable. // `base` in this can take either a tagged or untagged pointer, but we always // provide a tagged pointer to the `base` argument of `callback` if the kernel // supports tagged pointers. extern"C"int malloc_iterate(uintptr_t base, size_t size, void (*callback)(uintptr_t base, size_t size, void* arg), void* arg) { auto dispatch_table = GetDispatchTable(); // Wrap the malloc_iterate callback we were provided, in order to provide // pointer tagging support.
CallbackWrapperArg wrapper_arg;
wrapper_arg.callback = callback;
wrapper_arg.arg = arg;
uintptr_t untagged_base = reinterpret_cast<uintptr_t>(UntagPointer(reinterpret_cast<void*>(base))); if (__predict_false(dispatch_table != nullptr)) { return dispatch_table->malloc_iterate(
untagged_base, size, CallbackWrapper, &wrapper_arg);
} return Malloc(malloc_iterate)(
untagged_base, size, CallbackWrapper, &wrapper_arg);
}
// Disable calls to malloc so malloc_iterate gets a consistent view of // allocated memory. extern"C"void malloc_disable() { auto dispatch_table = GetDispatchTable(); if (__predict_false(dispatch_table != nullptr)) { return dispatch_table->malloc_disable();
} return Malloc(malloc_disable)();
}
// Re-enable calls to malloc after a previous call to malloc_disable. extern"C"void malloc_enable() { auto dispatch_table = GetDispatchTable(); if (__predict_false(dispatch_table != nullptr)) { return dispatch_table->malloc_enable();
} return Malloc(malloc_enable)();
}
// Initializes memory allocation framework. // This routine is called from __libc_init routines in libc_init_dynamic.cpp // and libc_init_static.cpp.
__BIONIC_WEAK_FOR_NATIVE_BRIDGE
__LIBC_HIDDEN__ void __libc_init_malloc(libc_globals* globals) { #if !defined(LIBC_STATIC)
MallocInitImpl(globals); #endif constchar* value = getenv("MALLOC_USE_APP_DEFAULTS"); if (value == nullptr || value[0] == '\0') { return;
}
// Normal apps currently turn off zero init for performance reasons.
SetHeapZeroInitialize(false);
// Do not call mallopt directly since that will try and lock the globals // data structure. int retval; auto dispatch_table = GetDispatchTable(); if (__predict_false(dispatch_table != nullptr)) {
retval = dispatch_table->mallopt(M_DECAY_TIME, 1);
} else {
retval = Malloc(mallopt)(M_DECAY_TIME, 1);
} if (retval == 1) {
globals->decay_time_enabled = true;
}
}
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.11 Sekunden
(vorverarbeitet am 2026-06-28)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.