[ACPICA]
[reactos.git] / reactos / drivers / bus / acpi / acpica / utilities / uttrack.c
1 /******************************************************************************
2 *
3 * Module Name: uttrack - Memory allocation tracking routines (debug only)
4 *
5 *****************************************************************************/
6
7 /******************************************************************************
8 *
9 * 1. Copyright Notice
10 *
11 * Some or all of this work - Copyright (c) 1999 - 2015, Intel Corp.
12 * All rights reserved.
13 *
14 * 2. License
15 *
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.
20 *
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
27 *
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;
36 *
37 * The above copyright and patent license is granted only if the following
38 * conditions are met:
39 *
40 * 3. Conditions
41 *
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.
53 *
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.
65 *
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.
71 *
72 * 3.4. Intel retains all right, title, and interest in and to the Original
73 * Intel Code.
74 *
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.
79 *
80 * 4. Disclaimer and Export Compliance
81 *
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.
89 *
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.
98 *
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.
113 *
114 *****************************************************************************/
115
116 /*
117 * These procedures are used for tracking memory leaks in the subsystem, and
118 * they get compiled out when the ACPI_DBG_TRACK_ALLOCATIONS is not set.
119 *
120 * Each memory allocation is tracked via a doubly linked list. Each
121 * element contains the caller's component, module name, function name, and
122 * line number. AcpiUtAllocate and AcpiUtAllocateZeroed call
123 * AcpiUtTrackAllocation to add an element to the list; deletion
124 * occurs in the body of AcpiUtFree.
125 */
126
127 #include "acpi.h"
128 #include "accommon.h"
129
130 #ifdef ACPI_DBG_TRACK_ALLOCATIONS
131
132 #define _COMPONENT ACPI_UTILITIES
133 ACPI_MODULE_NAME ("uttrack")
134
135
136 /* Local prototypes */
137
138 static ACPI_DEBUG_MEM_BLOCK *
139 AcpiUtFindAllocation (
140 ACPI_DEBUG_MEM_BLOCK *Allocation);
141
142 static ACPI_STATUS
143 AcpiUtTrackAllocation (
144 ACPI_DEBUG_MEM_BLOCK *Address,
145 ACPI_SIZE Size,
146 UINT8 AllocType,
147 UINT32 Component,
148 const char *Module,
149 UINT32 Line);
150
151 static ACPI_STATUS
152 AcpiUtRemoveAllocation (
153 ACPI_DEBUG_MEM_BLOCK *Address,
154 UINT32 Component,
155 const char *Module,
156 UINT32 Line);
157
158
159 /*******************************************************************************
160 *
161 * FUNCTION: AcpiUtCreateList
162 *
163 * PARAMETERS: CacheName - Ascii name for the cache
164 * ObjectSize - Size of each cached object
165 * ReturnCache - Where the new cache object is returned
166 *
167 * RETURN: Status
168 *
169 * DESCRIPTION: Create a local memory list for tracking purposed
170 *
171 ******************************************************************************/
172
173 ACPI_STATUS
174 AcpiUtCreateList (
175 char *ListName,
176 UINT16 ObjectSize,
177 ACPI_MEMORY_LIST **ReturnCache)
178 {
179 ACPI_MEMORY_LIST *Cache;
180
181
182 Cache = AcpiOsAllocate (sizeof (ACPI_MEMORY_LIST));
183 if (!Cache)
184 {
185 return (AE_NO_MEMORY);
186 }
187
188 memset (Cache, 0, sizeof (ACPI_MEMORY_LIST));
189
190 Cache->ListName = ListName;
191 Cache->ObjectSize = ObjectSize;
192
193 *ReturnCache = Cache;
194 return (AE_OK);
195 }
196
197
198 /*******************************************************************************
199 *
200 * FUNCTION: AcpiUtAllocateAndTrack
201 *
202 * PARAMETERS: Size - Size of the allocation
203 * Component - Component type of caller
204 * Module - Source file name of caller
205 * Line - Line number of caller
206 *
207 * RETURN: Address of the allocated memory on success, NULL on failure.
208 *
209 * DESCRIPTION: The subsystem's equivalent of malloc.
210 *
211 ******************************************************************************/
212
213 void *
214 AcpiUtAllocateAndTrack (
215 ACPI_SIZE Size,
216 UINT32 Component,
217 const char *Module,
218 UINT32 Line)
219 {
220 ACPI_DEBUG_MEM_BLOCK *Allocation;
221 ACPI_STATUS Status;
222
223
224 /* Check for an inadvertent size of zero bytes */
225
226 if (!Size)
227 {
228 ACPI_WARNING ((Module, Line,
229 "Attempt to allocate zero bytes, allocating 1 byte"));
230 Size = 1;
231 }
232
233 Allocation = AcpiOsAllocate (Size + sizeof (ACPI_DEBUG_MEM_HEADER));
234 if (!Allocation)
235 {
236 /* Report allocation error */
237
238 ACPI_WARNING ((Module, Line,
239 "Could not allocate size %u", (UINT32) Size));
240
241 return (NULL);
242 }
243
244 Status = AcpiUtTrackAllocation (Allocation, Size,
245 ACPI_MEM_MALLOC, Component, Module, Line);
246 if (ACPI_FAILURE (Status))
247 {
248 AcpiOsFree (Allocation);
249 return (NULL);
250 }
251
252 AcpiGbl_GlobalList->TotalAllocated++;
253 AcpiGbl_GlobalList->TotalSize += (UINT32) Size;
254 AcpiGbl_GlobalList->CurrentTotalSize += (UINT32) Size;
255 if (AcpiGbl_GlobalList->CurrentTotalSize > AcpiGbl_GlobalList->MaxOccupied)
256 {
257 AcpiGbl_GlobalList->MaxOccupied = AcpiGbl_GlobalList->CurrentTotalSize;
258 }
259
260 return ((void *) &Allocation->UserSpace);
261 }
262
263
264 /*******************************************************************************
265 *
266 * FUNCTION: AcpiUtAllocateZeroedAndTrack
267 *
268 * PARAMETERS: Size - Size of the allocation
269 * Component - Component type of caller
270 * Module - Source file name of caller
271 * Line - Line number of caller
272 *
273 * RETURN: Address of the allocated memory on success, NULL on failure.
274 *
275 * DESCRIPTION: Subsystem equivalent of calloc.
276 *
277 ******************************************************************************/
278
279 void *
280 AcpiUtAllocateZeroedAndTrack (
281 ACPI_SIZE Size,
282 UINT32 Component,
283 const char *Module,
284 UINT32 Line)
285 {
286 ACPI_DEBUG_MEM_BLOCK *Allocation;
287 ACPI_STATUS Status;
288
289
290 /* Check for an inadvertent size of zero bytes */
291
292 if (!Size)
293 {
294 ACPI_WARNING ((Module, Line,
295 "Attempt to allocate zero bytes, allocating 1 byte"));
296 Size = 1;
297 }
298
299 Allocation = AcpiOsAllocateZeroed (Size + sizeof (ACPI_DEBUG_MEM_HEADER));
300 if (!Allocation)
301 {
302 /* Report allocation error */
303
304 ACPI_ERROR ((Module, Line,
305 "Could not allocate size %u", (UINT32) Size));
306 return (NULL);
307 }
308
309 Status = AcpiUtTrackAllocation (Allocation, Size,
310 ACPI_MEM_CALLOC, Component, Module, Line);
311 if (ACPI_FAILURE (Status))
312 {
313 AcpiOsFree (Allocation);
314 return (NULL);
315 }
316
317 AcpiGbl_GlobalList->TotalAllocated++;
318 AcpiGbl_GlobalList->TotalSize += (UINT32) Size;
319 AcpiGbl_GlobalList->CurrentTotalSize += (UINT32) Size;
320 if (AcpiGbl_GlobalList->CurrentTotalSize > AcpiGbl_GlobalList->MaxOccupied)
321 {
322 AcpiGbl_GlobalList->MaxOccupied = AcpiGbl_GlobalList->CurrentTotalSize;
323 }
324
325 return ((void *) &Allocation->UserSpace);
326 }
327
328
329 /*******************************************************************************
330 *
331 * FUNCTION: AcpiUtFreeAndTrack
332 *
333 * PARAMETERS: Allocation - Address of the memory to deallocate
334 * Component - Component type of caller
335 * Module - Source file name of caller
336 * Line - Line number of caller
337 *
338 * RETURN: None
339 *
340 * DESCRIPTION: Frees the memory at Allocation
341 *
342 ******************************************************************************/
343
344 void
345 AcpiUtFreeAndTrack (
346 void *Allocation,
347 UINT32 Component,
348 const char *Module,
349 UINT32 Line)
350 {
351 ACPI_DEBUG_MEM_BLOCK *DebugBlock;
352 ACPI_STATUS Status;
353
354
355 ACPI_FUNCTION_TRACE_PTR (UtFree, Allocation);
356
357
358 if (NULL == Allocation)
359 {
360 ACPI_ERROR ((Module, Line,
361 "Attempt to delete a NULL address"));
362
363 return_VOID;
364 }
365
366 DebugBlock = ACPI_CAST_PTR (ACPI_DEBUG_MEM_BLOCK,
367 (((char *) Allocation) - sizeof (ACPI_DEBUG_MEM_HEADER)));
368
369 AcpiGbl_GlobalList->TotalFreed++;
370 AcpiGbl_GlobalList->CurrentTotalSize -= DebugBlock->Size;
371
372 Status = AcpiUtRemoveAllocation (DebugBlock,
373 Component, Module, Line);
374 if (ACPI_FAILURE (Status))
375 {
376 ACPI_EXCEPTION ((AE_INFO, Status, "Could not free memory"));
377 }
378
379 AcpiOsFree (DebugBlock);
380 ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS, "%p freed (block %p)\n",
381 Allocation, DebugBlock));
382 return_VOID;
383 }
384
385
386 /*******************************************************************************
387 *
388 * FUNCTION: AcpiUtFindAllocation
389 *
390 * PARAMETERS: Allocation - Address of allocated memory
391 *
392 * RETURN: Three cases:
393 * 1) List is empty, NULL is returned.
394 * 2) Element was found. Returns Allocation parameter.
395 * 3) Element was not found. Returns position where it should be
396 * inserted into the list.
397 *
398 * DESCRIPTION: Searches for an element in the global allocation tracking list.
399 * If the element is not found, returns the location within the
400 * list where the element should be inserted.
401 *
402 * Note: The list is ordered by larger-to-smaller addresses.
403 *
404 * This global list is used to detect memory leaks in ACPICA as
405 * well as other issues such as an attempt to release the same
406 * internal object more than once. Although expensive as far
407 * as cpu time, this list is much more helpful for finding these
408 * types of issues than using memory leak detectors outside of
409 * the ACPICA code.
410 *
411 ******************************************************************************/
412
413 static ACPI_DEBUG_MEM_BLOCK *
414 AcpiUtFindAllocation (
415 ACPI_DEBUG_MEM_BLOCK *Allocation)
416 {
417 ACPI_DEBUG_MEM_BLOCK *Element;
418
419
420 Element = AcpiGbl_GlobalList->ListHead;
421 if (!Element)
422 {
423 return (NULL);
424 }
425
426 /*
427 * Search for the address.
428 *
429 * Note: List is ordered by larger-to-smaller addresses, on the
430 * assumption that a new allocation usually has a larger address
431 * than previous allocations.
432 */
433 while (Element > Allocation)
434 {
435 /* Check for end-of-list */
436
437 if (!Element->Next)
438 {
439 return (Element);
440 }
441
442 Element = Element->Next;
443 }
444
445 if (Element == Allocation)
446 {
447 return (Element);
448 }
449
450 return (Element->Previous);
451 }
452
453
454 /*******************************************************************************
455 *
456 * FUNCTION: AcpiUtTrackAllocation
457 *
458 * PARAMETERS: Allocation - Address of allocated memory
459 * Size - Size of the allocation
460 * AllocType - MEM_MALLOC or MEM_CALLOC
461 * Component - Component type of caller
462 * Module - Source file name of caller
463 * Line - Line number of caller
464 *
465 * RETURN: Status
466 *
467 * DESCRIPTION: Inserts an element into the global allocation tracking list.
468 *
469 ******************************************************************************/
470
471 static ACPI_STATUS
472 AcpiUtTrackAllocation (
473 ACPI_DEBUG_MEM_BLOCK *Allocation,
474 ACPI_SIZE Size,
475 UINT8 AllocType,
476 UINT32 Component,
477 const char *Module,
478 UINT32 Line)
479 {
480 ACPI_MEMORY_LIST *MemList;
481 ACPI_DEBUG_MEM_BLOCK *Element;
482 ACPI_STATUS Status = AE_OK;
483
484
485 ACPI_FUNCTION_TRACE_PTR (UtTrackAllocation, Allocation);
486
487
488 if (AcpiGbl_DisableMemTracking)
489 {
490 return_ACPI_STATUS (AE_OK);
491 }
492
493 MemList = AcpiGbl_GlobalList;
494 Status = AcpiUtAcquireMutex (ACPI_MTX_MEMORY);
495 if (ACPI_FAILURE (Status))
496 {
497 return_ACPI_STATUS (Status);
498 }
499
500 /*
501 * Search the global list for this address to make sure it is not
502 * already present. This will catch several kinds of problems.
503 */
504 Element = AcpiUtFindAllocation (Allocation);
505 if (Element == Allocation)
506 {
507 ACPI_ERROR ((AE_INFO,
508 "UtTrackAllocation: Allocation (%p) already present in global list!",
509 Allocation));
510 goto UnlockAndExit;
511 }
512
513 /* Fill in the instance data */
514
515 Allocation->Size = (UINT32) Size;
516 Allocation->AllocType = AllocType;
517 Allocation->Component = Component;
518 Allocation->Line = Line;
519
520 strncpy (Allocation->Module, Module, ACPI_MAX_MODULE_NAME);
521 Allocation->Module[ACPI_MAX_MODULE_NAME-1] = 0;
522
523 if (!Element)
524 {
525 /* Insert at list head */
526
527 if (MemList->ListHead)
528 {
529 ((ACPI_DEBUG_MEM_BLOCK *)(MemList->ListHead))->Previous = Allocation;
530 }
531
532 Allocation->Next = MemList->ListHead;
533 Allocation->Previous = NULL;
534
535 MemList->ListHead = Allocation;
536 }
537 else
538 {
539 /* Insert after element */
540
541 Allocation->Next = Element->Next;
542 Allocation->Previous = Element;
543
544 if (Element->Next)
545 {
546 (Element->Next)->Previous = Allocation;
547 }
548
549 Element->Next = Allocation;
550 }
551
552
553 UnlockAndExit:
554 Status = AcpiUtReleaseMutex (ACPI_MTX_MEMORY);
555 return_ACPI_STATUS (Status);
556 }
557
558
559 /*******************************************************************************
560 *
561 * FUNCTION: AcpiUtRemoveAllocation
562 *
563 * PARAMETERS: Allocation - Address of allocated memory
564 * Component - Component type of caller
565 * Module - Source file name of caller
566 * Line - Line number of caller
567 *
568 * RETURN: Status
569 *
570 * DESCRIPTION: Deletes an element from the global allocation tracking list.
571 *
572 ******************************************************************************/
573
574 static ACPI_STATUS
575 AcpiUtRemoveAllocation (
576 ACPI_DEBUG_MEM_BLOCK *Allocation,
577 UINT32 Component,
578 const char *Module,
579 UINT32 Line)
580 {
581 ACPI_MEMORY_LIST *MemList;
582 ACPI_STATUS Status;
583
584
585 ACPI_FUNCTION_NAME (UtRemoveAllocation);
586
587
588 if (AcpiGbl_DisableMemTracking)
589 {
590 return (AE_OK);
591 }
592
593 MemList = AcpiGbl_GlobalList;
594 if (NULL == MemList->ListHead)
595 {
596 /* No allocations! */
597
598 ACPI_ERROR ((Module, Line,
599 "Empty allocation list, nothing to free!"));
600
601 return (AE_OK);
602 }
603
604 Status = AcpiUtAcquireMutex (ACPI_MTX_MEMORY);
605 if (ACPI_FAILURE (Status))
606 {
607 return (Status);
608 }
609
610 /* Unlink */
611
612 if (Allocation->Previous)
613 {
614 (Allocation->Previous)->Next = Allocation->Next;
615 }
616 else
617 {
618 MemList->ListHead = Allocation->Next;
619 }
620
621 if (Allocation->Next)
622 {
623 (Allocation->Next)->Previous = Allocation->Previous;
624 }
625
626 ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS, "Freeing %p, size 0%X\n",
627 &Allocation->UserSpace, Allocation->Size));
628
629 /* Mark the segment as deleted */
630
631 memset (&Allocation->UserSpace, 0xEA, Allocation->Size);
632
633 Status = AcpiUtReleaseMutex (ACPI_MTX_MEMORY);
634 return (Status);
635 }
636
637
638 /*******************************************************************************
639 *
640 * FUNCTION: AcpiUtDumpAllocationInfo
641 *
642 * PARAMETERS: None
643 *
644 * RETURN: None
645 *
646 * DESCRIPTION: Print some info about the outstanding allocations.
647 *
648 ******************************************************************************/
649
650 void
651 AcpiUtDumpAllocationInfo (
652 void)
653 {
654 /*
655 ACPI_MEMORY_LIST *MemList;
656 */
657
658 ACPI_FUNCTION_TRACE (UtDumpAllocationInfo);
659
660 /*
661 ACPI_DEBUG_PRINT (TRACE_ALLOCATIONS | TRACE_TABLES,
662 ("%30s: %4d (%3d Kb)\n", "Current allocations",
663 MemList->CurrentCount,
664 ROUND_UP_TO_1K (MemList->CurrentSize)));
665
666 ACPI_DEBUG_PRINT (TRACE_ALLOCATIONS | TRACE_TABLES,
667 ("%30s: %4d (%3d Kb)\n", "Max concurrent allocations",
668 MemList->MaxConcurrentCount,
669 ROUND_UP_TO_1K (MemList->MaxConcurrentSize)));
670
671
672 ACPI_DEBUG_PRINT (TRACE_ALLOCATIONS | TRACE_TABLES,
673 ("%30s: %4d (%3d Kb)\n", "Total (all) internal objects",
674 RunningObjectCount,
675 ROUND_UP_TO_1K (RunningObjectSize)));
676
677 ACPI_DEBUG_PRINT (TRACE_ALLOCATIONS | TRACE_TABLES,
678 ("%30s: %4d (%3d Kb)\n", "Total (all) allocations",
679 RunningAllocCount,
680 ROUND_UP_TO_1K (RunningAllocSize)));
681
682
683 ACPI_DEBUG_PRINT (TRACE_ALLOCATIONS | TRACE_TABLES,
684 ("%30s: %4d (%3d Kb)\n", "Current Nodes",
685 AcpiGbl_CurrentNodeCount,
686 ROUND_UP_TO_1K (AcpiGbl_CurrentNodeSize)));
687
688 ACPI_DEBUG_PRINT (TRACE_ALLOCATIONS | TRACE_TABLES,
689 ("%30s: %4d (%3d Kb)\n", "Max Nodes",
690 AcpiGbl_MaxConcurrentNodeCount,
691 ROUND_UP_TO_1K ((AcpiGbl_MaxConcurrentNodeCount *
692 sizeof (ACPI_NAMESPACE_NODE)))));
693 */
694 return_VOID;
695 }
696
697
698 /*******************************************************************************
699 *
700 * FUNCTION: AcpiUtDumpAllocations
701 *
702 * PARAMETERS: Component - Component(s) to dump info for.
703 * Module - Module to dump info for. NULL means all.
704 *
705 * RETURN: None
706 *
707 * DESCRIPTION: Print a list of all outstanding allocations.
708 *
709 ******************************************************************************/
710
711 void
712 AcpiUtDumpAllocations (
713 UINT32 Component,
714 const char *Module)
715 {
716 ACPI_DEBUG_MEM_BLOCK *Element;
717 ACPI_DESCRIPTOR *Descriptor;
718 UINT32 NumOutstanding = 0;
719 UINT8 DescriptorType;
720
721
722 ACPI_FUNCTION_TRACE (UtDumpAllocations);
723
724
725 if (AcpiGbl_DisableMemTracking)
726 {
727 return_VOID;
728 }
729
730 /*
731 * Walk the allocation list.
732 */
733 if (ACPI_FAILURE (AcpiUtAcquireMutex (ACPI_MTX_MEMORY)))
734 {
735 return_VOID;
736 }
737
738 Element = AcpiGbl_GlobalList->ListHead;
739 while (Element)
740 {
741 if ((Element->Component & Component) &&
742 ((Module == NULL) || (0 == strcmp (Module, Element->Module))))
743 {
744 Descriptor = ACPI_CAST_PTR (ACPI_DESCRIPTOR, &Element->UserSpace);
745
746 if (Element->Size < sizeof (ACPI_COMMON_DESCRIPTOR))
747 {
748 AcpiOsPrintf ("%p Length 0x%04X %9.9s-%u "
749 "[Not a Descriptor - too small]\n",
750 Descriptor, Element->Size, Element->Module,
751 Element->Line);
752 }
753 else
754 {
755 /* Ignore allocated objects that are in a cache */
756
757 if (ACPI_GET_DESCRIPTOR_TYPE (Descriptor) != ACPI_DESC_TYPE_CACHED)
758 {
759 AcpiOsPrintf ("%p Length 0x%04X %9.9s-%u [%s] ",
760 Descriptor, Element->Size, Element->Module,
761 Element->Line, AcpiUtGetDescriptorName (Descriptor));
762
763 /* Validate the descriptor type using Type field and length */
764
765 DescriptorType = 0; /* Not a valid descriptor type */
766
767 switch (ACPI_GET_DESCRIPTOR_TYPE (Descriptor))
768 {
769 case ACPI_DESC_TYPE_OPERAND:
770
771 if (Element->Size == sizeof (ACPI_OPERAND_OBJECT))
772 {
773 DescriptorType = ACPI_DESC_TYPE_OPERAND;
774 }
775 break;
776
777 case ACPI_DESC_TYPE_PARSER:
778
779 if (Element->Size == sizeof (ACPI_PARSE_OBJECT))
780 {
781 DescriptorType = ACPI_DESC_TYPE_PARSER;
782 }
783 break;
784
785 case ACPI_DESC_TYPE_NAMED:
786
787 if (Element->Size == sizeof (ACPI_NAMESPACE_NODE))
788 {
789 DescriptorType = ACPI_DESC_TYPE_NAMED;
790 }
791 break;
792
793 default:
794
795 break;
796 }
797
798 /* Display additional info for the major descriptor types */
799
800 switch (DescriptorType)
801 {
802 case ACPI_DESC_TYPE_OPERAND:
803
804 AcpiOsPrintf ("%12.12s RefCount 0x%04X\n",
805 AcpiUtGetTypeName (Descriptor->Object.Common.Type),
806 Descriptor->Object.Common.ReferenceCount);
807 break;
808
809 case ACPI_DESC_TYPE_PARSER:
810
811 AcpiOsPrintf ("AmlOpcode 0x%04hX\n",
812 Descriptor->Op.Asl.AmlOpcode);
813 break;
814
815 case ACPI_DESC_TYPE_NAMED:
816
817 AcpiOsPrintf ("%4.4s\n",
818 AcpiUtGetNodeName (&Descriptor->Node));
819 break;
820
821 default:
822
823 AcpiOsPrintf ( "\n");
824 break;
825 }
826 }
827 }
828
829 NumOutstanding++;
830 }
831
832 Element = Element->Next;
833 }
834
835 (void) AcpiUtReleaseMutex (ACPI_MTX_MEMORY);
836
837 /* Print summary */
838
839 if (!NumOutstanding)
840 {
841 ACPI_INFO ((AE_INFO, "No outstanding allocations"));
842 }
843 else
844 {
845 ACPI_ERROR ((AE_INFO, "%u(0x%X) Outstanding allocations",
846 NumOutstanding, NumOutstanding));
847 }
848
849 return_VOID;
850 }
851
852 #endif /* ACPI_DBG_TRACK_ALLOCATIONS */