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