/* * These procedures are used for tracking memory leaks in the subsystem, and * they get compiled out when the ACPI_DBG_TRACK_ALLOCATIONS is not set. * * Each memory allocation is tracked via a doubly linked list. Each * element contains the caller's component, module name, function name, and * line number. acpi_ut_allocate and acpi_ut_allocate_zeroed call * acpi_ut_track_allocation to add an element to the list; deletion * occurs in the body of acpi_ut_free.
*/
/******************************************************************************* * * FUNCTION: acpi_ut_create_list * * PARAMETERS: cache_name - Ascii name for the cache * object_size - Size of each cached object * return_cache - Where the new cache object is returned * * RETURN: Status * * DESCRIPTION: Create a local memory list for tracking purposed *
******************************************************************************/
/******************************************************************************* * * FUNCTION: acpi_ut_allocate_and_track * * PARAMETERS: size - Size of the allocation * component - Component type of caller * module - Source file name of caller * line - Line number of caller * * RETURN: Address of the allocated memory on success, NULL on failure. * * DESCRIPTION: The subsystem's equivalent of malloc. *
******************************************************************************/
if (acpi_gbl_global_list->current_total_size >
acpi_gbl_global_list->max_occupied) {
acpi_gbl_global_list->max_occupied =
acpi_gbl_global_list->current_total_size;
}
return ((void *)&allocation->user_space);
}
/******************************************************************************* * * FUNCTION: acpi_ut_allocate_zeroed_and_track * * PARAMETERS: size - Size of the allocation * component - Component type of caller * module - Source file name of caller * line - Line number of caller * * RETURN: Address of the allocated memory on success, NULL on failure. * * DESCRIPTION: Subsystem equivalent of calloc. *
******************************************************************************/
if (acpi_gbl_global_list->current_total_size >
acpi_gbl_global_list->max_occupied) {
acpi_gbl_global_list->max_occupied =
acpi_gbl_global_list->current_total_size;
}
return ((void *)&allocation->user_space);
}
/******************************************************************************* * * FUNCTION: acpi_ut_free_and_track * * PARAMETERS: allocation - Address of the memory to deallocate * component - Component type of caller * module - Source file name of caller * line - Line number of caller * * RETURN: None * * DESCRIPTION: Frees the memory at Allocation *
******************************************************************************/
/******************************************************************************* * * FUNCTION: acpi_ut_find_allocation * * PARAMETERS: allocation - Address of allocated memory * * RETURN: Three cases: * 1) List is empty, NULL is returned. * 2) Element was found. Returns Allocation parameter. * 3) Element was not found. Returns position where it should be * inserted into the list. * * DESCRIPTION: Searches for an element in the global allocation tracking list. * If the element is not found, returns the location within the * list where the element should be inserted. * * Note: The list is ordered by larger-to-smaller addresses. * * This global list is used to detect memory leaks in ACPICA as * well as other issues such as an attempt to release the same * internal object more than once. Although expensive as far * as cpu time, this list is much more helpful for finding these * types of issues than using memory leak detectors outside of * the ACPICA code. *
******************************************************************************/
element = acpi_gbl_global_list->list_head; if (!element) { return (NULL);
}
/* * Search for the address. * * Note: List is ordered by larger-to-smaller addresses, on the * assumption that a new allocation usually has a larger address * than previous allocations.
*/ while (element > allocation) {
/* Check for end-of-list */
if (!element->next) { return (element);
}
element = element->next;
}
if (element == allocation) { return (element);
}
return (element->previous);
}
/******************************************************************************* * * FUNCTION: acpi_ut_track_allocation * * PARAMETERS: allocation - Address of allocated memory * size - Size of the allocation * alloc_type - MEM_MALLOC or MEM_CALLOC * component - Component type of caller * module - Source file name of caller * line - Line number of caller * * RETURN: Status * * DESCRIPTION: Inserts an element into the global allocation tracking list. *
******************************************************************************/
if (acpi_gbl_disable_mem_tracking) {
return_ACPI_STATUS(AE_OK);
}
mem_list = acpi_gbl_global_list;
status = acpi_ut_acquire_mutex(ACPI_MTX_MEMORY); if (ACPI_FAILURE(status)) {
return_ACPI_STATUS(status);
}
/* * Search the global list for this address to make sure it is not * already present. This will catch several kinds of problems.
*/
element = acpi_ut_find_allocation(allocation); if (element == allocation) {
ACPI_ERROR((AE_INFO, "UtTrackAllocation: Allocation (%p) already present in global list!",
allocation)); goto unlock_and_exit;
}
if (element->next) {
(element->next)->previous = allocation;
}
element->next = allocation;
}
unlock_and_exit:
status = acpi_ut_release_mutex(ACPI_MTX_MEMORY);
return_ACPI_STATUS(status);
}
/******************************************************************************* * * FUNCTION: acpi_ut_remove_allocation * * PARAMETERS: allocation - Address of allocated memory * component - Component type of caller * module - Source file name of caller * line - Line number of caller * * RETURN: Status * * DESCRIPTION: Deletes an element from the global allocation tracking list. *
******************************************************************************/
/******************************************************************************* * * FUNCTION: acpi_ut_dump_allocations * * PARAMETERS: component - Component(s) to dump info for. * module - Module to dump info for. NULL means all. * * RETURN: None * * DESCRIPTION: Print a list of all outstanding allocations. *
******************************************************************************/
if (acpi_gbl_disable_mem_tracking) {
return_VOID;
}
/* * Walk the allocation list.
*/ if (ACPI_FAILURE(acpi_ut_acquire_mutex(ACPI_MTX_MEMORY))) {
return_VOID;
}
if (!acpi_gbl_global_list) { gotoexit;
}
element = acpi_gbl_global_list->list_head; while (element) { if ((element->component & component) &&
((module == NULL)
|| (0 == strcmp(module, element->module)))) {
descriptor =
ACPI_CAST_PTR(union acpi_descriptor,
&element->user_space);
if (element->size < sizeof(struct acpi_common_descriptor)) {
acpi_os_printf("%p Length 0x%04X %9.9s-%4.4u " "[Not a Descriptor - too small]\n",
descriptor, element->size,
element->module, element->line);
} else { /* Ignore allocated objects that are in a cache */
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.