/******************************************************************************
*
* Module Name: uttrack - Memory allocation tracking routines (debug only)
*
*****************************************************************************/
/*
* Copyright (C) 2000 - 2016, Intel Corp.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions, and the following disclaimer,
* without modification.
* 2. Redistributions in binary form must reproduce at minimum a disclaimer
* substantially similar to the "NO WARRANTY" disclaimer below
* ("Disclaimer") and any redistribution must be conditioned upon
* including a substantially similar Disclaimer requirement for further
* binary redistribution.
* 3. Neither the names of the above-listed copyright holders nor the names
* of any contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* Alternatively, this software may be distributed under the terms of the
* GNU General Public License ("GPL") version 2 as published by the Free
* Software Foundation.
*
* NO WARRANTY
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGES.
*/
/*
* 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. AcpiUtAllocate and AcpiUtAllocateZeroed call
* AcpiUtTrackAllocation to add an element to the list; deletion
* occurs in the body of AcpiUtFree.
*/
#include "acpi.h"
#include "accommon.h"
#ifdef ACPI_DBG_TRACK_ALLOCATIONS
ACPI_MODULE_NAME ("uttrack")
/* Local prototypes */
static ACPI_DEBUG_MEM_BLOCK *
static ACPI_STATUS
const char *Module,
static ACPI_STATUS
const char *Module,
/*******************************************************************************
*
* FUNCTION: AcpiUtCreateList
*
* PARAMETERS: CacheName - Ascii name for the cache
* ObjectSize - Size of each cached object
* ReturnCache - Where the new cache object is returned
*
* RETURN: Status
*
* DESCRIPTION: Create a local memory list for tracking purposed
*
******************************************************************************/
const char *ListName,
{
if (!Cache)
{
return (AE_NO_MEMORY);
}
*ReturnCache = Cache;
return (AE_OK);
}
/*******************************************************************************
*
* FUNCTION: AcpiUtAllocateAndTrack
*
* 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.
*
******************************************************************************/
void *
const char *Module,
{
/* Check for an inadvertent size of zero bytes */
if (!Size)
{
"Attempt to allocate zero bytes, allocating 1 byte"));
Size = 1;
}
if (!Allocation)
{
/* Report allocation error */
return (NULL);
}
if (ACPI_FAILURE (Status))
{
return (NULL);
}
{
}
return ((void *) &Allocation->UserSpace);
}
/*******************************************************************************
*
* FUNCTION: AcpiUtAllocateZeroedAndTrack
*
* 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.
*
******************************************************************************/
void *
const char *Module,
{
/* Check for an inadvertent size of zero bytes */
if (!Size)
{
"Attempt to allocate zero bytes, allocating 1 byte"));
Size = 1;
}
Size + sizeof (ACPI_DEBUG_MEM_HEADER));
if (!Allocation)
{
/* Report allocation error */
return (NULL);
}
if (ACPI_FAILURE (Status))
{
return (NULL);
}
{
}
return ((void *) &Allocation->UserSpace);
}
/*******************************************************************************
*
* FUNCTION: AcpiUtFreeAndTrack
*
* 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
*
******************************************************************************/
void
void *Allocation,
const char *Module,
{
if (NULL == Allocation)
{
"Attempt to delete a NULL address"));
}
(((char *) Allocation) - sizeof (ACPI_DEBUG_MEM_HEADER)));
if (ACPI_FAILURE (Status))
{
}
Allocation, DebugBlock));
}
/*******************************************************************************
*
* FUNCTION: AcpiUtFindAllocation
*
* 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.
*
******************************************************************************/
static ACPI_DEBUG_MEM_BLOCK *
{
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 */
{
return (Element);
}
}
if (Element == Allocation)
{
return (Element);
}
}
/*******************************************************************************
*
* FUNCTION: AcpiUtTrackAllocation
*
* PARAMETERS: Allocation - Address of allocated memory
* Size - Size of the allocation
* AllocType - 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.
*
******************************************************************************/
static ACPI_STATUS
const char *Module,
{
{
}
if (ACPI_FAILURE (Status))
{
}
/*
* Search the global list for this address to make sure it is not
* already present. This will catch several kinds of problems.
*/
if (Element == Allocation)
{
"UtTrackAllocation: Allocation (%p) already present in global list!",
Allocation));
goto UnlockAndExit;
}
/* Fill in the instance data */
if (!Element)
{
/* Insert at list head */
{
}
}
else
{
/* Insert after element */
{
}
}
}
/*******************************************************************************
*
* FUNCTION: AcpiUtRemoveAllocation
*
* 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.
*
******************************************************************************/
static ACPI_STATUS
const char *Module,
{
{
return (AE_OK);
}
{
/* No allocations! */
"Empty allocation list, nothing to free!"));
return (AE_OK);
}
if (ACPI_FAILURE (Status))
{
return (Status);
}
/* Unlink */
if (Allocation->Previous)
{
}
else
{
}
if (Allocation->Next)
{
}
/* Mark the segment as deleted */
return (Status);
}
/*******************************************************************************
*
* FUNCTION: AcpiUtDumpAllocationInfo
*
* PARAMETERS: None
*
* RETURN: None
*
* DESCRIPTION: Print some info about the outstanding allocations.
*
******************************************************************************/
void
void)
{
/*
ACPI_MEMORY_LIST *MemList;
*/
/*
ACPI_DEBUG_PRINT (TRACE_ALLOCATIONS | TRACE_TABLES,
("%30s: %4d (%3d Kb)\n", "Current allocations",
MemList->CurrentCount,
ROUND_UP_TO_1K (MemList->CurrentSize)));
ACPI_DEBUG_PRINT (TRACE_ALLOCATIONS | TRACE_TABLES,
("%30s: %4d (%3d Kb)\n", "Max concurrent allocations",
MemList->MaxConcurrentCount,
ROUND_UP_TO_1K (MemList->MaxConcurrentSize)));
ACPI_DEBUG_PRINT (TRACE_ALLOCATIONS | TRACE_TABLES,
("%30s: %4d (%3d Kb)\n", "Total (all) internal objects",
RunningObjectCount,
ROUND_UP_TO_1K (RunningObjectSize)));
ACPI_DEBUG_PRINT (TRACE_ALLOCATIONS | TRACE_TABLES,
("%30s: %4d (%3d Kb)\n", "Total (all) allocations",
RunningAllocCount,
ROUND_UP_TO_1K (RunningAllocSize)));
ACPI_DEBUG_PRINT (TRACE_ALLOCATIONS | TRACE_TABLES,
("%30s: %4d (%3d Kb)\n", "Current Nodes",
AcpiGbl_CurrentNodeCount,
ROUND_UP_TO_1K (AcpiGbl_CurrentNodeSize)));
ACPI_DEBUG_PRINT (TRACE_ALLOCATIONS | TRACE_TABLES,
("%30s: %4d (%3d Kb)\n", "Max Nodes",
AcpiGbl_MaxConcurrentNodeCount,
ROUND_UP_TO_1K ((AcpiGbl_MaxConcurrentNodeCount *
sizeof (ACPI_NAMESPACE_NODE)))));
*/
}
/*******************************************************************************
*
* FUNCTION: AcpiUtDumpAllocations
*
* 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.
*
******************************************************************************/
void
const char *Module)
{
{
}
/*
* Walk the allocation list.
*/
{
}
while (Element)
{
{
{
AcpiOsPrintf ("%p Length 0x%04X %9.9s-%u "
"[Not a Descriptor - too small]\n",
}
else
{
/* Ignore allocated objects that are in a cache */
if (ACPI_GET_DESCRIPTOR_TYPE (Descriptor) !=
{
AcpiOsPrintf ("%p Length 0x%04X %9.9s-%u [%s] ",
/* Validate the descriptor type using Type field and length */
DescriptorType = 0; /* Not a valid descriptor type */
switch (ACPI_GET_DESCRIPTOR_TYPE (Descriptor))
{
case ACPI_DESC_TYPE_OPERAND:
{
}
break;
case ACPI_DESC_TYPE_PARSER:
{
}
break;
case ACPI_DESC_TYPE_NAMED:
{
}
break;
default:
break;
}
/* Display additional info for the major descriptor types */
switch (DescriptorType)
{
case ACPI_DESC_TYPE_OPERAND:
AcpiOsPrintf ("%12.12s RefCount 0x%04X\n",
break;
case ACPI_DESC_TYPE_PARSER:
AcpiOsPrintf ("AmlOpcode 0x%04hX\n",
break;
case ACPI_DESC_TYPE_NAMED:
AcpiOsPrintf ("%4.4s\n",
break;
default:
AcpiOsPrintf ( "\n");
break;
}
}
}
}
}
(void) AcpiUtReleaseMutex (ACPI_MTX_MEMORY);
/* Print summary */
if (!NumOutstanding)
{
ACPI_INFO (("No outstanding allocations"));
}
else
{
}
}
#endif /* ACPI_DBG_TRACK_ALLOCATIONS */