Sync ACPICA with Intel's version 20180508 (from previously 20170831).
[dragonfly.git] / sys / contrib / dev / acpica / source / components / utilities / uttrack.c
blob7905e5a1000206fef1178ecb7f7cb4c47ea8c91a
1 /******************************************************************************
3 * Module Name: uttrack - Memory allocation tracking routines (debug only)
5 *****************************************************************************/
7 /******************************************************************************
9 * 1. Copyright Notice
11 * Some or all of this work - Copyright (c) 1999 - 2018, Intel Corp.
12 * All rights reserved.
14 * 2. License
16 * 2.1. This is your license from Intel Corp. under its intellectual property
17 * rights. You may have additional license terms from the party that provided
18 * you this software, covering your right to use that party's intellectual
19 * property rights.
21 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
22 * copy of the source code appearing in this file ("Covered Code") an
23 * irrevocable, perpetual, worldwide license under Intel's copyrights in the
24 * base code distributed originally by Intel ("Original Intel Code") to copy,
25 * make derivatives, distribute, use and display any portion of the Covered
26 * Code in any form, with the right to sublicense such rights; and
28 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
29 * license (with the right to sublicense), under only those claims of Intel
30 * patents that are infringed by the Original Intel Code, to make, use, sell,
31 * offer to sell, and import the Covered Code and derivative works thereof
32 * solely to the minimum extent necessary to exercise the above copyright
33 * license, and in no event shall the patent license extend to any additions
34 * to or modifications of the Original Intel Code. No other license or right
35 * is granted directly or by implication, estoppel or otherwise;
37 * The above copyright and patent license is granted only if the following
38 * conditions are met:
40 * 3. Conditions
42 * 3.1. Redistribution of Source with Rights to Further Distribute Source.
43 * Redistribution of source code of any substantial portion of the Covered
44 * Code or modification with rights to further distribute source must include
45 * the above Copyright Notice, the above License, this list of Conditions,
46 * and the following Disclaimer and Export Compliance provision. In addition,
47 * Licensee must cause all Covered Code to which Licensee contributes to
48 * contain a file documenting the changes Licensee made to create that Covered
49 * Code and the date of any change. Licensee must include in that file the
50 * documentation of any changes made by any predecessor Licensee. Licensee
51 * must include a prominent statement that the modification is derived,
52 * directly or indirectly, from Original Intel Code.
54 * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
55 * Redistribution of source code of any substantial portion of the Covered
56 * Code or modification without rights to further distribute source must
57 * include the following Disclaimer and Export Compliance provision in the
58 * documentation and/or other materials provided with distribution. In
59 * addition, Licensee may not authorize further sublicense of source of any
60 * portion of the Covered Code, and must include terms to the effect that the
61 * license from Licensee to its licensee is limited to the intellectual
62 * property embodied in the software Licensee provides to its licensee, and
63 * not to intellectual property embodied in modifications its licensee may
64 * make.
66 * 3.3. Redistribution of Executable. Redistribution in executable form of any
67 * substantial portion of the Covered Code or modification must reproduce the
68 * above Copyright Notice, and the following Disclaimer and Export Compliance
69 * provision in the documentation and/or other materials provided with the
70 * distribution.
72 * 3.4. Intel retains all right, title, and interest in and to the Original
73 * Intel Code.
75 * 3.5. Neither the name Intel nor any other trademark owned or controlled by
76 * Intel shall be used in advertising or otherwise to promote the sale, use or
77 * other dealings in products derived from or relating to the Covered Code
78 * without prior written authorization from Intel.
80 * 4. Disclaimer and Export Compliance
82 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
83 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
84 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
85 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
86 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
87 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
88 * PARTICULAR PURPOSE.
90 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
91 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
92 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
93 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
94 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
95 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
96 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
97 * LIMITED REMEDY.
99 * 4.3. Licensee shall not export, either directly or indirectly, any of this
100 * software or system incorporating such software without first obtaining any
101 * required license or other approval from the U. S. Department of Commerce or
102 * any other agency or department of the United States Government. In the
103 * event Licensee exports any such software from the United States or
104 * re-exports any such software from a foreign destination, Licensee shall
105 * ensure that the distribution and export/re-export of the software is in
106 * compliance with all laws, regulations, orders, or other restrictions of the
107 * U.S. Export Administration Regulations. Licensee agrees that neither it nor
108 * any of its subsidiaries will export/re-export any technical data, process,
109 * software, or service, directly or indirectly, to any country for which the
110 * United States government or any agency thereof requires an export license,
111 * other governmental approval, or letter of assurance, without first obtaining
112 * such license, approval or letter.
114 *****************************************************************************
116 * Alternatively, you may choose to be licensed under the terms of the
117 * following license:
119 * Redistribution and use in source and binary forms, with or without
120 * modification, are permitted provided that the following conditions
121 * are met:
122 * 1. Redistributions of source code must retain the above copyright
123 * notice, this list of conditions, and the following disclaimer,
124 * without modification.
125 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
126 * substantially similar to the "NO WARRANTY" disclaimer below
127 * ("Disclaimer") and any redistribution must be conditioned upon
128 * including a substantially similar Disclaimer requirement for further
129 * binary redistribution.
130 * 3. Neither the names of the above-listed copyright holders nor the names
131 * of any contributors may be used to endorse or promote products derived
132 * from this software without specific prior written permission.
134 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
135 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
136 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
137 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
138 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
139 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
140 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
141 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
142 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
143 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
144 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
146 * Alternatively, you may choose to be licensed under the terms of the
147 * GNU General Public License ("GPL") version 2 as published by the Free
148 * Software Foundation.
150 *****************************************************************************/
153 * These procedures are used for tracking memory leaks in the subsystem, and
154 * they get compiled out when the ACPI_DBG_TRACK_ALLOCATIONS is not set.
156 * Each memory allocation is tracked via a doubly linked list. Each
157 * element contains the caller's component, module name, function name, and
158 * line number. AcpiUtAllocate and AcpiUtAllocateZeroed call
159 * AcpiUtTrackAllocation to add an element to the list; deletion
160 * occurs in the body of AcpiUtFree.
163 #include "acpi.h"
164 #include "accommon.h"
166 #ifdef ACPI_DBG_TRACK_ALLOCATIONS
168 #define _COMPONENT ACPI_UTILITIES
169 ACPI_MODULE_NAME ("uttrack")
172 /* Local prototypes */
174 static ACPI_DEBUG_MEM_BLOCK *
175 AcpiUtFindAllocation (
176 ACPI_DEBUG_MEM_BLOCK *Allocation);
178 static ACPI_STATUS
179 AcpiUtTrackAllocation (
180 ACPI_DEBUG_MEM_BLOCK *Address,
181 ACPI_SIZE Size,
182 UINT8 AllocType,
183 UINT32 Component,
184 const char *Module,
185 UINT32 Line);
187 static ACPI_STATUS
188 AcpiUtRemoveAllocation (
189 ACPI_DEBUG_MEM_BLOCK *Address,
190 UINT32 Component,
191 const char *Module,
192 UINT32 Line);
195 /*******************************************************************************
197 * FUNCTION: AcpiUtCreateList
199 * PARAMETERS: CacheName - Ascii name for the cache
200 * ObjectSize - Size of each cached object
201 * ReturnCache - Where the new cache object is returned
203 * RETURN: Status
205 * DESCRIPTION: Create a local memory list for tracking purposed
207 ******************************************************************************/
209 ACPI_STATUS
210 AcpiUtCreateList (
211 const char *ListName,
212 UINT16 ObjectSize,
213 ACPI_MEMORY_LIST **ReturnCache)
215 ACPI_MEMORY_LIST *Cache;
218 Cache = AcpiOsAllocateZeroed (sizeof (ACPI_MEMORY_LIST));
219 if (!Cache)
221 return (AE_NO_MEMORY);
224 Cache->ListName = ListName;
225 Cache->ObjectSize = ObjectSize;
227 *ReturnCache = Cache;
228 return (AE_OK);
232 /*******************************************************************************
234 * FUNCTION: AcpiUtAllocateAndTrack
236 * PARAMETERS: Size - Size of the allocation
237 * Component - Component type of caller
238 * Module - Source file name of caller
239 * Line - Line number of caller
241 * RETURN: Address of the allocated memory on success, NULL on failure.
243 * DESCRIPTION: The subsystem's equivalent of malloc.
245 ******************************************************************************/
247 void *
248 AcpiUtAllocateAndTrack (
249 ACPI_SIZE Size,
250 UINT32 Component,
251 const char *Module,
252 UINT32 Line)
254 ACPI_DEBUG_MEM_BLOCK *Allocation;
255 ACPI_STATUS Status;
258 /* Check for an inadvertent size of zero bytes */
260 if (!Size)
262 ACPI_WARNING ((Module, Line,
263 "Attempt to allocate zero bytes, allocating 1 byte"));
264 Size = 1;
267 Allocation = AcpiOsAllocate (Size + sizeof (ACPI_DEBUG_MEM_HEADER));
268 if (!Allocation)
270 /* Report allocation error */
272 ACPI_WARNING ((Module, Line,
273 "Could not allocate size %u", (UINT32) Size));
275 return (NULL);
278 Status = AcpiUtTrackAllocation (
279 Allocation, Size, ACPI_MEM_MALLOC, Component, Module, Line);
280 if (ACPI_FAILURE (Status))
282 AcpiOsFree (Allocation);
283 return (NULL);
286 AcpiGbl_GlobalList->TotalAllocated++;
287 AcpiGbl_GlobalList->TotalSize += (UINT32) Size;
288 AcpiGbl_GlobalList->CurrentTotalSize += (UINT32) Size;
290 if (AcpiGbl_GlobalList->CurrentTotalSize >
291 AcpiGbl_GlobalList->MaxOccupied)
293 AcpiGbl_GlobalList->MaxOccupied =
294 AcpiGbl_GlobalList->CurrentTotalSize;
297 return ((void *) &Allocation->UserSpace);
301 /*******************************************************************************
303 * FUNCTION: AcpiUtAllocateZeroedAndTrack
305 * PARAMETERS: Size - Size of the allocation
306 * Component - Component type of caller
307 * Module - Source file name of caller
308 * Line - Line number of caller
310 * RETURN: Address of the allocated memory on success, NULL on failure.
312 * DESCRIPTION: Subsystem equivalent of calloc.
314 ******************************************************************************/
316 void *
317 AcpiUtAllocateZeroedAndTrack (
318 ACPI_SIZE Size,
319 UINT32 Component,
320 const char *Module,
321 UINT32 Line)
323 ACPI_DEBUG_MEM_BLOCK *Allocation;
324 ACPI_STATUS Status;
327 /* Check for an inadvertent size of zero bytes */
329 if (!Size)
331 ACPI_WARNING ((Module, Line,
332 "Attempt to allocate zero bytes, allocating 1 byte"));
333 Size = 1;
336 Allocation = AcpiOsAllocateZeroed (
337 Size + sizeof (ACPI_DEBUG_MEM_HEADER));
338 if (!Allocation)
340 /* Report allocation error */
342 ACPI_ERROR ((Module, Line,
343 "Could not allocate size %u", (UINT32) Size));
344 return (NULL);
347 Status = AcpiUtTrackAllocation (Allocation, Size,
348 ACPI_MEM_CALLOC, Component, Module, Line);
349 if (ACPI_FAILURE (Status))
351 AcpiOsFree (Allocation);
352 return (NULL);
355 AcpiGbl_GlobalList->TotalAllocated++;
356 AcpiGbl_GlobalList->TotalSize += (UINT32) Size;
357 AcpiGbl_GlobalList->CurrentTotalSize += (UINT32) Size;
359 if (AcpiGbl_GlobalList->CurrentTotalSize >
360 AcpiGbl_GlobalList->MaxOccupied)
362 AcpiGbl_GlobalList->MaxOccupied =
363 AcpiGbl_GlobalList->CurrentTotalSize;
366 return ((void *) &Allocation->UserSpace);
370 /*******************************************************************************
372 * FUNCTION: AcpiUtFreeAndTrack
374 * PARAMETERS: Allocation - Address of the memory to deallocate
375 * Component - Component type of caller
376 * Module - Source file name of caller
377 * Line - Line number of caller
379 * RETURN: None
381 * DESCRIPTION: Frees the memory at Allocation
383 ******************************************************************************/
385 void
386 AcpiUtFreeAndTrack (
387 void *Allocation,
388 UINT32 Component,
389 const char *Module,
390 UINT32 Line)
392 ACPI_DEBUG_MEM_BLOCK *DebugBlock;
393 ACPI_STATUS Status;
396 ACPI_FUNCTION_TRACE_PTR (UtFree, Allocation);
399 if (NULL == Allocation)
401 ACPI_ERROR ((Module, Line,
402 "Attempt to delete a NULL address"));
404 return_VOID;
407 DebugBlock = ACPI_CAST_PTR (ACPI_DEBUG_MEM_BLOCK,
408 (((char *) Allocation) - sizeof (ACPI_DEBUG_MEM_HEADER)));
410 AcpiGbl_GlobalList->TotalFreed++;
411 AcpiGbl_GlobalList->CurrentTotalSize -= DebugBlock->Size;
413 Status = AcpiUtRemoveAllocation (DebugBlock, Component, Module, Line);
414 if (ACPI_FAILURE (Status))
416 ACPI_EXCEPTION ((AE_INFO, Status, "Could not free memory"));
419 AcpiOsFree (DebugBlock);
420 ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS, "%p freed (block %p)\n",
421 Allocation, DebugBlock));
422 return_VOID;
426 /*******************************************************************************
428 * FUNCTION: AcpiUtFindAllocation
430 * PARAMETERS: Allocation - Address of allocated memory
432 * RETURN: Three cases:
433 * 1) List is empty, NULL is returned.
434 * 2) Element was found. Returns Allocation parameter.
435 * 3) Element was not found. Returns position where it should be
436 * inserted into the list.
438 * DESCRIPTION: Searches for an element in the global allocation tracking list.
439 * If the element is not found, returns the location within the
440 * list where the element should be inserted.
442 * Note: The list is ordered by larger-to-smaller addresses.
444 * This global list is used to detect memory leaks in ACPICA as
445 * well as other issues such as an attempt to release the same
446 * internal object more than once. Although expensive as far
447 * as cpu time, this list is much more helpful for finding these
448 * types of issues than using memory leak detectors outside of
449 * the ACPICA code.
451 ******************************************************************************/
453 static ACPI_DEBUG_MEM_BLOCK *
454 AcpiUtFindAllocation (
455 ACPI_DEBUG_MEM_BLOCK *Allocation)
457 ACPI_DEBUG_MEM_BLOCK *Element;
460 Element = AcpiGbl_GlobalList->ListHead;
461 if (!Element)
463 return (NULL);
467 * Search for the address.
469 * Note: List is ordered by larger-to-smaller addresses, on the
470 * assumption that a new allocation usually has a larger address
471 * than previous allocations.
473 while (Element > Allocation)
475 /* Check for end-of-list */
477 if (!Element->Next)
479 return (Element);
482 Element = Element->Next;
485 if (Element == Allocation)
487 return (Element);
490 return (Element->Previous);
494 /*******************************************************************************
496 * FUNCTION: AcpiUtTrackAllocation
498 * PARAMETERS: Allocation - Address of allocated memory
499 * Size - Size of the allocation
500 * AllocType - MEM_MALLOC or MEM_CALLOC
501 * Component - Component type of caller
502 * Module - Source file name of caller
503 * Line - Line number of caller
505 * RETURN: Status
507 * DESCRIPTION: Inserts an element into the global allocation tracking list.
509 ******************************************************************************/
511 static ACPI_STATUS
512 AcpiUtTrackAllocation (
513 ACPI_DEBUG_MEM_BLOCK *Allocation,
514 ACPI_SIZE Size,
515 UINT8 AllocType,
516 UINT32 Component,
517 const char *Module,
518 UINT32 Line)
520 ACPI_MEMORY_LIST *MemList;
521 ACPI_DEBUG_MEM_BLOCK *Element;
522 ACPI_STATUS Status = AE_OK;
525 ACPI_FUNCTION_TRACE_PTR (UtTrackAllocation, Allocation);
528 if (AcpiGbl_DisableMemTracking)
530 return_ACPI_STATUS (AE_OK);
533 MemList = AcpiGbl_GlobalList;
534 Status = AcpiUtAcquireMutex (ACPI_MTX_MEMORY);
535 if (ACPI_FAILURE (Status))
537 return_ACPI_STATUS (Status);
541 * Search the global list for this address to make sure it is not
542 * already present. This will catch several kinds of problems.
544 Element = AcpiUtFindAllocation (Allocation);
545 if (Element == Allocation)
547 ACPI_ERROR ((AE_INFO,
548 "UtTrackAllocation: Allocation (%p) already present in global list!",
549 Allocation));
550 goto UnlockAndExit;
553 /* Fill in the instance data */
555 Allocation->Size = (UINT32) Size;
556 Allocation->AllocType = AllocType;
557 Allocation->Component = Component;
558 Allocation->Line = Line;
560 AcpiUtSafeStrncpy (Allocation->Module, (char *) Module, ACPI_MAX_MODULE_NAME);
562 if (!Element)
564 /* Insert at list head */
566 if (MemList->ListHead)
568 ((ACPI_DEBUG_MEM_BLOCK *)(MemList->ListHead))->Previous =
569 Allocation;
572 Allocation->Next = MemList->ListHead;
573 Allocation->Previous = NULL;
575 MemList->ListHead = Allocation;
577 else
579 /* Insert after element */
581 Allocation->Next = Element->Next;
582 Allocation->Previous = Element;
584 if (Element->Next)
586 (Element->Next)->Previous = Allocation;
589 Element->Next = Allocation;
593 UnlockAndExit:
594 Status = AcpiUtReleaseMutex (ACPI_MTX_MEMORY);
595 return_ACPI_STATUS (Status);
599 /*******************************************************************************
601 * FUNCTION: AcpiUtRemoveAllocation
603 * PARAMETERS: Allocation - Address of allocated memory
604 * Component - Component type of caller
605 * Module - Source file name of caller
606 * Line - Line number of caller
608 * RETURN: Status
610 * DESCRIPTION: Deletes an element from the global allocation tracking list.
612 ******************************************************************************/
614 static ACPI_STATUS
615 AcpiUtRemoveAllocation (
616 ACPI_DEBUG_MEM_BLOCK *Allocation,
617 UINT32 Component,
618 const char *Module,
619 UINT32 Line)
621 ACPI_MEMORY_LIST *MemList;
622 ACPI_STATUS Status;
625 ACPI_FUNCTION_NAME (UtRemoveAllocation);
628 if (AcpiGbl_DisableMemTracking)
630 return (AE_OK);
633 MemList = AcpiGbl_GlobalList;
634 if (NULL == MemList->ListHead)
636 /* No allocations! */
638 ACPI_ERROR ((Module, Line,
639 "Empty allocation list, nothing to free!"));
641 return (AE_OK);
644 Status = AcpiUtAcquireMutex (ACPI_MTX_MEMORY);
645 if (ACPI_FAILURE (Status))
647 return (Status);
650 /* Unlink */
652 if (Allocation->Previous)
654 (Allocation->Previous)->Next = Allocation->Next;
656 else
658 MemList->ListHead = Allocation->Next;
661 if (Allocation->Next)
663 (Allocation->Next)->Previous = Allocation->Previous;
666 ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS, "Freeing %p, size 0%X\n",
667 &Allocation->UserSpace, Allocation->Size));
669 /* Mark the segment as deleted */
671 memset (&Allocation->UserSpace, 0xEA, Allocation->Size);
673 Status = AcpiUtReleaseMutex (ACPI_MTX_MEMORY);
674 return (Status);
678 /*******************************************************************************
680 * FUNCTION: AcpiUtDumpAllocationInfo
682 * PARAMETERS: None
684 * RETURN: None
686 * DESCRIPTION: Print some info about the outstanding allocations.
688 ******************************************************************************/
690 void
691 AcpiUtDumpAllocationInfo (
692 void)
695 ACPI_MEMORY_LIST *MemList;
698 ACPI_FUNCTION_TRACE (UtDumpAllocationInfo);
701 ACPI_DEBUG_PRINT (TRACE_ALLOCATIONS | TRACE_TABLES,
702 ("%30s: %4d (%3d Kb)\n", "Current allocations",
703 MemList->CurrentCount,
704 ROUND_UP_TO_1K (MemList->CurrentSize)));
706 ACPI_DEBUG_PRINT (TRACE_ALLOCATIONS | TRACE_TABLES,
707 ("%30s: %4d (%3d Kb)\n", "Max concurrent allocations",
708 MemList->MaxConcurrentCount,
709 ROUND_UP_TO_1K (MemList->MaxConcurrentSize)));
712 ACPI_DEBUG_PRINT (TRACE_ALLOCATIONS | TRACE_TABLES,
713 ("%30s: %4d (%3d Kb)\n", "Total (all) internal objects",
714 RunningObjectCount,
715 ROUND_UP_TO_1K (RunningObjectSize)));
717 ACPI_DEBUG_PRINT (TRACE_ALLOCATIONS | TRACE_TABLES,
718 ("%30s: %4d (%3d Kb)\n", "Total (all) allocations",
719 RunningAllocCount,
720 ROUND_UP_TO_1K (RunningAllocSize)));
723 ACPI_DEBUG_PRINT (TRACE_ALLOCATIONS | TRACE_TABLES,
724 ("%30s: %4d (%3d Kb)\n", "Current Nodes",
725 AcpiGbl_CurrentNodeCount,
726 ROUND_UP_TO_1K (AcpiGbl_CurrentNodeSize)));
728 ACPI_DEBUG_PRINT (TRACE_ALLOCATIONS | TRACE_TABLES,
729 ("%30s: %4d (%3d Kb)\n", "Max Nodes",
730 AcpiGbl_MaxConcurrentNodeCount,
731 ROUND_UP_TO_1K ((AcpiGbl_MaxConcurrentNodeCount *
732 sizeof (ACPI_NAMESPACE_NODE)))));
734 return_VOID;
738 /*******************************************************************************
740 * FUNCTION: AcpiUtDumpAllocations
742 * PARAMETERS: Component - Component(s) to dump info for.
743 * Module - Module to dump info for. NULL means all.
745 * RETURN: None
747 * DESCRIPTION: Print a list of all outstanding allocations.
749 ******************************************************************************/
751 void
752 AcpiUtDumpAllocations (
753 UINT32 Component,
754 const char *Module)
756 ACPI_DEBUG_MEM_BLOCK *Element;
757 ACPI_DESCRIPTOR *Descriptor;
758 UINT32 NumOutstanding = 0;
759 UINT8 DescriptorType;
762 ACPI_FUNCTION_TRACE (UtDumpAllocations);
765 if (AcpiGbl_DisableMemTracking)
767 return_VOID;
771 * Walk the allocation list.
773 if (ACPI_FAILURE (AcpiUtAcquireMutex (ACPI_MTX_MEMORY)))
775 return_VOID;
778 if (!AcpiGbl_GlobalList)
780 goto Exit;
783 Element = AcpiGbl_GlobalList->ListHead;
784 while (Element)
786 if ((Element->Component & Component) &&
787 ((Module == NULL) || (0 == strcmp (Module, Element->Module))))
789 Descriptor = ACPI_CAST_PTR (
790 ACPI_DESCRIPTOR, &Element->UserSpace);
792 if (Element->Size < sizeof (ACPI_COMMON_DESCRIPTOR))
794 AcpiOsPrintf ("%p Length 0x%04X %9.9s-%4.4u "
795 "[Not a Descriptor - too small]\n",
796 Descriptor, Element->Size, Element->Module,
797 Element->Line);
799 else
801 /* Ignore allocated objects that are in a cache */
803 if (ACPI_GET_DESCRIPTOR_TYPE (Descriptor) !=
804 ACPI_DESC_TYPE_CACHED)
806 AcpiOsPrintf ("%p Length 0x%04X %9.9s-%4.4u [%s] ",
807 Descriptor, Element->Size, Element->Module,
808 Element->Line, AcpiUtGetDescriptorName (Descriptor));
810 /* Validate the descriptor type using Type field and length */
812 DescriptorType = 0; /* Not a valid descriptor type */
814 switch (ACPI_GET_DESCRIPTOR_TYPE (Descriptor))
816 case ACPI_DESC_TYPE_OPERAND:
818 if (Element->Size == sizeof (ACPI_OPERAND_OBJECT))
820 DescriptorType = ACPI_DESC_TYPE_OPERAND;
822 break;
824 case ACPI_DESC_TYPE_PARSER:
826 if (Element->Size == sizeof (ACPI_PARSE_OBJECT))
828 DescriptorType = ACPI_DESC_TYPE_PARSER;
830 break;
832 case ACPI_DESC_TYPE_NAMED:
834 if (Element->Size == sizeof (ACPI_NAMESPACE_NODE))
836 DescriptorType = ACPI_DESC_TYPE_NAMED;
838 break;
840 default:
842 break;
845 /* Display additional info for the major descriptor types */
847 switch (DescriptorType)
849 case ACPI_DESC_TYPE_OPERAND:
851 AcpiOsPrintf ("%12.12s RefCount 0x%04X\n",
852 AcpiUtGetTypeName (Descriptor->Object.Common.Type),
853 Descriptor->Object.Common.ReferenceCount);
854 break;
856 case ACPI_DESC_TYPE_PARSER:
858 AcpiOsPrintf ("AmlOpcode 0x%04hX\n",
859 Descriptor->Op.Asl.AmlOpcode);
860 break;
862 case ACPI_DESC_TYPE_NAMED:
864 AcpiOsPrintf ("%4.4s\n",
865 AcpiUtGetNodeName (&Descriptor->Node));
866 break;
868 default:
870 AcpiOsPrintf ( "\n");
871 break;
876 NumOutstanding++;
879 Element = Element->Next;
882 Exit:
883 (void) AcpiUtReleaseMutex (ACPI_MTX_MEMORY);
885 /* Print summary */
887 if (!NumOutstanding)
889 ACPI_INFO (("No outstanding allocations"));
891 else
893 ACPI_ERROR ((AE_INFO, "%u (0x%X) Outstanding cache allocations",
894 NumOutstanding, NumOutstanding));
897 return_VOID;
900 #endif /* ACPI_DBG_TRACK_ALLOCATIONS */