FreeBSD/sys/contrib/dev/acpica/components/utilities/uttrack.c
/*******************************************************************************
 *
 * 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.
 *
 ******************************************************************************/


Status

Inserts an element into the global allocation tracking list.
Status Inserts an element into the global allocation tracking list .
static ACPI_STATUS
AcpiUtTrackAllocation (
    ACPI_DEBUG_MEM_BLOCK    *Allocation,
    ACPI_SIZE               Size,
    UINT8                   AllocType,
    UINT32                  Component,
    const char              *Module,
    UINT32                  Line)
{
    ACPI_MEMORY_LIST        *MemList;
    ACPI_DEBUG_MEM_BLOCK    *Element;
    ACPI_STATUS             Status = AE_OK;
    ACPI_FUNCTION_TRACE_PTR (UtTrackAllocation, Allocation);
    if (AcpiGbl_DisableMemTracking)
    {
        return_ACPI_STATUS (AE_OK);
    }
    MemList = AcpiGbl_GlobalList;
    Status = AcpiUtAcquireMutex (ACPI_MTX_MEMORY);
    if (ACPI_FAILURE (Status))
    {
        return_ACPI_STATUS (Status);
    }
    Element = AcpiUtFindAllocation (Allocation);
    if (Element == Allocation)
    {
        ACPI_ERROR ((AE_INFO,
            "UtTrackAllocation: Allocation (%p) already present in global list!",
            Allocation));
        goto UnlockAndExit;
    }
    Allocation->Size = (UINT32) Size;
    Allocation->AllocType = AllocType;
    Allocation->Component = Component;
    Allocation->Line = Line;
    strncpy (Allocation->Module, Module, ACPI_MAX_MODULE_NAME);
    Allocation->Module[ACPI_MAX_MODULE_NAME-1] = 0;
    if (!Element)
    {
        if (MemList->ListHead)
        {
            ((ACPI_DEBUG_MEM_BLOCK *)(MemList->ListHead))->Previous =
                Allocation;
        }
        Allocation->Next = MemList->ListHead;
        Allocation->Previous = NULL;
        MemList->ListHead = Allocation;
    }
    else
    {
        Allocation->Next = Element->Next;
        Allocation->Previous = Element;
        if (Element->Next)
        {
            (Element->Next)->Previous = Allocation;
        }
        Element->Next = Allocation;
    }
UnlockAndExit:
    Status = AcpiUtReleaseMutex (ACPI_MTX_MEMORY);
    return_ACPI_STATUS (Status);
}
static ACPI_STATUS AcpiUtTrackAllocation ( ACPI_DEBUG_MEM_BLOCK * Allocation , ACPI_SIZE Size , UINT8 AllocType , UINT32 Component , const char * Module , UINT32 Line ) { ACPI_MEMORY_LIST * MemList ; ACPI_DEBUG_MEM_BLOCK * Element ; ACPI_STATUS Status = AE_OK ; ACPI_FUNCTION_TRACE_PTR ( UtTrackAllocation , Allocation ) ; if ( AcpiGbl_DisableMemTracking ) { return_ACPI_STATUS ( AE_OK ) ; } MemList = AcpiGbl_GlobalList ; Status = AcpiUtAcquireMutex ( ACPI_MTX_MEMORY ) ; if ( ACPI_FAILURE ( Status ) ) { return_ACPI_STATUS ( Status ) ; } Element = AcpiUtFindAllocation ( Allocation ) ; if ( Element == Allocation ) { ACPI_ERROR ( ( AE_INFO , " " , Allocation ) ) ; goto UnlockAndExit ; } Allocation -> Size = ( UINT32 ) Size ; Allocation -> AllocType = AllocType ; Allocation -> Component = Component ; Allocation -> Line = Line ; strncpy ( Allocation -> Module , Module , ACPI_MAX_MODULE_NAME ) ; Allocation -> Module [ ACPI_MAX_MODULE_NAME - 1 ] = 0 ; if ( ! Element ) { if ( MemList -> ListHead ) { ( ( ACPI_DEBUG_MEM_BLOCK * ) ( MemList -> ListHead ) ) -> Previous = Allocation ; } Allocation -> Next = MemList -> ListHead ; Allocation -> Previous = NULL ; MemList -> ListHead = Allocation ; } else { Allocation -> Next = Element -> Next ; Allocation -> Previous = Element ; if ( Element -> Next ) { ( Element -> Next ) -> Previous = Allocation ; } Element -> Next = Allocation ; } UnlockAndExit : Status = AcpiUtReleaseMutex ( ACPI_MTX_MEMORY ) ; return_ACPI_STATUS ( Status ) ; }
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
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
/*
     * Search the global list for this address to make sure it is not
     * already present. This will catch several kinds of problems.
     */ /* Fill in the instance data */ /* Insert at list head */ /* Insert after element */