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