![]() |
|
|||
File indexing completed on 2025-05-11 08:24:04
0001 /****************************************************************************** 0002 * 0003 * Module Name: uttrack - Memory allocation tracking routines (debug only) 0004 * 0005 *****************************************************************************/ 0006 0007 /****************************************************************************** 0008 * 0009 * 1. Copyright Notice 0010 * 0011 * Some or all of this work - Copyright (c) 1999 - 2024, Intel Corp. 0012 * All rights reserved. 0013 * 0014 * 2. License 0015 * 0016 * 2.1. This is your license from Intel Corp. under its intellectual property 0017 * rights. You may have additional license terms from the party that provided 0018 * you this software, covering your right to use that party's intellectual 0019 * property rights. 0020 * 0021 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a 0022 * copy of the source code appearing in this file ("Covered Code") an 0023 * irrevocable, perpetual, worldwide license under Intel's copyrights in the 0024 * base code distributed originally by Intel ("Original Intel Code") to copy, 0025 * make derivatives, distribute, use and display any portion of the Covered 0026 * Code in any form, with the right to sublicense such rights; and 0027 * 0028 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent 0029 * license (with the right to sublicense), under only those claims of Intel 0030 * patents that are infringed by the Original Intel Code, to make, use, sell, 0031 * offer to sell, and import the Covered Code and derivative works thereof 0032 * solely to the minimum extent necessary to exercise the above copyright 0033 * license, and in no event shall the patent license extend to any additions 0034 * to or modifications of the Original Intel Code. No other license or right 0035 * is granted directly or by implication, estoppel or otherwise; 0036 * 0037 * The above copyright and patent license is granted only if the following 0038 * conditions are met: 0039 * 0040 * 3. Conditions 0041 * 0042 * 3.1. Redistribution of Source with Rights to Further Distribute Source. 0043 * Redistribution of source code of any substantial portion of the Covered 0044 * Code or modification with rights to further distribute source must include 0045 * the above Copyright Notice, the above License, this list of Conditions, 0046 * and the following Disclaimer and Export Compliance provision. In addition, 0047 * Licensee must cause all Covered Code to which Licensee contributes to 0048 * contain a file documenting the changes Licensee made to create that Covered 0049 * Code and the date of any change. Licensee must include in that file the 0050 * documentation of any changes made by any predecessor Licensee. Licensee 0051 * must include a prominent statement that the modification is derived, 0052 * directly or indirectly, from Original Intel Code. 0053 * 0054 * 3.2. Redistribution of Source with no Rights to Further Distribute Source. 0055 * Redistribution of source code of any substantial portion of the Covered 0056 * Code or modification without rights to further distribute source must 0057 * include the following Disclaimer and Export Compliance provision in the 0058 * documentation and/or other materials provided with distribution. In 0059 * addition, Licensee may not authorize further sublicense of source of any 0060 * portion of the Covered Code, and must include terms to the effect that the 0061 * license from Licensee to its licensee is limited to the intellectual 0062 * property embodied in the software Licensee provides to its licensee, and 0063 * not to intellectual property embodied in modifications its licensee may 0064 * make. 0065 * 0066 * 3.3. Redistribution of Executable. Redistribution in executable form of any 0067 * substantial portion of the Covered Code or modification must reproduce the 0068 * above Copyright Notice, and the following Disclaimer and Export Compliance 0069 * provision in the documentation and/or other materials provided with the 0070 * distribution. 0071 * 0072 * 3.4. Intel retains all right, title, and interest in and to the Original 0073 * Intel Code. 0074 * 0075 * 3.5. Neither the name Intel nor any other trademark owned or controlled by 0076 * Intel shall be used in advertising or otherwise to promote the sale, use or 0077 * other dealings in products derived from or relating to the Covered Code 0078 * without prior written authorization from Intel. 0079 * 0080 * 4. Disclaimer and Export Compliance 0081 * 0082 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED 0083 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE 0084 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE, 0085 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY 0086 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY 0087 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A 0088 * PARTICULAR PURPOSE. 0089 * 0090 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES 0091 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR 0092 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT, 0093 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY 0094 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL 0095 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS 0096 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY 0097 * LIMITED REMEDY. 0098 * 0099 * 4.3. Licensee shall not export, either directly or indirectly, any of this 0100 * software or system incorporating such software without first obtaining any 0101 * required license or other approval from the U. S. Department of Commerce or 0102 * any other agency or department of the United States Government. In the 0103 * event Licensee exports any such software from the United States or 0104 * re-exports any such software from a foreign destination, Licensee shall 0105 * ensure that the distribution and export/re-export of the software is in 0106 * compliance with all laws, regulations, orders, or other restrictions of the 0107 * U.S. Export Administration Regulations. Licensee agrees that neither it nor 0108 * any of its subsidiaries will export/re-export any technical data, process, 0109 * software, or service, directly or indirectly, to any country for which the 0110 * United States government or any agency thereof requires an export license, 0111 * other governmental approval, or letter of assurance, without first obtaining 0112 * such license, approval or letter. 0113 * 0114 ***************************************************************************** 0115 * 0116 * Alternatively, you may choose to be licensed under the terms of the 0117 * following license: 0118 * 0119 * Redistribution and use in source and binary forms, with or without 0120 * modification, are permitted provided that the following conditions 0121 * are met: 0122 * 1. Redistributions of source code must retain the above copyright 0123 * notice, this list of conditions, and the following disclaimer, 0124 * without modification. 0125 * 2. Redistributions in binary form must reproduce at minimum a disclaimer 0126 * substantially similar to the "NO WARRANTY" disclaimer below 0127 * ("Disclaimer") and any redistribution must be conditioned upon 0128 * including a substantially similar Disclaimer requirement for further 0129 * binary redistribution. 0130 * 3. Neither the names of the above-listed copyright holders nor the names 0131 * of any contributors may be used to endorse or promote products derived 0132 * from this software without specific prior written permission. 0133 * 0134 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 0135 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 0136 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 0137 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 0138 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 0139 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 0140 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 0141 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 0142 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 0143 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 0144 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 0145 * 0146 * Alternatively, you may choose to be licensed under the terms of the 0147 * GNU General Public License ("GPL") version 2 as published by the Free 0148 * Software Foundation. 0149 * 0150 *****************************************************************************/ 0151 0152 /* 0153 * These procedures are used for tracking memory leaks in the subsystem, and 0154 * they get compiled out when the ACPI_DBG_TRACK_ALLOCATIONS is not set. 0155 * 0156 * Each memory allocation is tracked via a doubly linked list. Each 0157 * element contains the caller's component, module name, function name, and 0158 * line number. AcpiUtAllocate and AcpiUtAllocateZeroed call 0159 * AcpiUtTrackAllocation to add an element to the list; deletion 0160 * occurs in the body of AcpiUtFree. 0161 */ 0162 0163 #include "acpi.h" 0164 #include "accommon.h" 0165 0166 #ifdef ACPI_DBG_TRACK_ALLOCATIONS 0167 0168 #define _COMPONENT ACPI_UTILITIES 0169 ACPI_MODULE_NAME ("uttrack") 0170 0171 0172 /* Local prototypes */ 0173 0174 static ACPI_DEBUG_MEM_BLOCK * 0175 AcpiUtFindAllocation ( 0176 ACPI_DEBUG_MEM_BLOCK *Allocation); 0177 0178 static ACPI_STATUS 0179 AcpiUtTrackAllocation ( 0180 ACPI_DEBUG_MEM_BLOCK *Address, 0181 ACPI_SIZE Size, 0182 UINT8 AllocType, 0183 UINT32 Component, 0184 const char *Module, 0185 UINT32 Line); 0186 0187 static ACPI_STATUS 0188 AcpiUtRemoveAllocation ( 0189 ACPI_DEBUG_MEM_BLOCK *Address, 0190 UINT32 Component, 0191 const char *Module, 0192 UINT32 Line); 0193 0194 0195 /******************************************************************************* 0196 * 0197 * FUNCTION: AcpiUtCreateList 0198 * 0199 * PARAMETERS: CacheName - Ascii name for the cache 0200 * ObjectSize - Size of each cached object 0201 * ReturnCache - Where the new cache object is returned 0202 * 0203 * RETURN: Status 0204 * 0205 * DESCRIPTION: Create a local memory list for tracking purposed 0206 * 0207 ******************************************************************************/ 0208 0209 ACPI_STATUS 0210 AcpiUtCreateList ( 0211 const char *ListName, 0212 UINT16 ObjectSize, 0213 ACPI_MEMORY_LIST **ReturnCache) 0214 { 0215 ACPI_MEMORY_LIST *Cache; 0216 0217 0218 Cache = AcpiOsAllocateZeroed (sizeof (ACPI_MEMORY_LIST)); 0219 if (!Cache) 0220 { 0221 return (AE_NO_MEMORY); 0222 } 0223 0224 Cache->ListName = ListName; 0225 Cache->ObjectSize = ObjectSize; 0226 0227 *ReturnCache = Cache; 0228 return (AE_OK); 0229 } 0230 0231 0232 /******************************************************************************* 0233 * 0234 * FUNCTION: AcpiUtAllocateAndTrack 0235 * 0236 * PARAMETERS: Size - Size of the allocation 0237 * Component - Component type of caller 0238 * Module - Source file name of caller 0239 * Line - Line number of caller 0240 * 0241 * RETURN: Address of the allocated memory on success, NULL on failure. 0242 * 0243 * DESCRIPTION: The subsystem's equivalent of malloc. 0244 * 0245 ******************************************************************************/ 0246 0247 void * 0248 AcpiUtAllocateAndTrack ( 0249 ACPI_SIZE Size, 0250 UINT32 Component, 0251 const char *Module, 0252 UINT32 Line) 0253 { 0254 ACPI_DEBUG_MEM_BLOCK *Allocation; 0255 ACPI_STATUS Status; 0256 0257 0258 /* Check for an inadvertent size of zero bytes */ 0259 0260 if (!Size) 0261 { 0262 ACPI_WARNING ((Module, Line, 0263 "Attempt to allocate zero bytes, allocating 1 byte")); 0264 Size = 1; 0265 } 0266 0267 Allocation = AcpiOsAllocate (Size + sizeof (ACPI_DEBUG_MEM_HEADER)); 0268 if (!Allocation) 0269 { 0270 /* Report allocation error */ 0271 0272 ACPI_WARNING ((Module, Line, 0273 "Could not allocate size %u", (UINT32) Size)); 0274 0275 return (NULL); 0276 } 0277 0278 Status = AcpiUtTrackAllocation ( 0279 Allocation, Size, ACPI_MEM_MALLOC, Component, Module, Line); 0280 if (ACPI_FAILURE (Status)) 0281 { 0282 AcpiOsFree (Allocation); 0283 return (NULL); 0284 } 0285 0286 AcpiGbl_GlobalList->TotalAllocated++; 0287 AcpiGbl_GlobalList->TotalSize += (UINT32) Size; 0288 AcpiGbl_GlobalList->CurrentTotalSize += (UINT32) Size; 0289 0290 if (AcpiGbl_GlobalList->CurrentTotalSize > 0291 AcpiGbl_GlobalList->MaxOccupied) 0292 { 0293 AcpiGbl_GlobalList->MaxOccupied = 0294 AcpiGbl_GlobalList->CurrentTotalSize; 0295 } 0296 0297 return ((void *) &Allocation->UserSpace); 0298 } 0299 0300 0301 /******************************************************************************* 0302 * 0303 * FUNCTION: AcpiUtAllocateZeroedAndTrack 0304 * 0305 * PARAMETERS: Size - Size of the allocation 0306 * Component - Component type of caller 0307 * Module - Source file name of caller 0308 * Line - Line number of caller 0309 * 0310 * RETURN: Address of the allocated memory on success, NULL on failure. 0311 * 0312 * DESCRIPTION: Subsystem equivalent of calloc. 0313 * 0314 ******************************************************************************/ 0315 0316 void * 0317 AcpiUtAllocateZeroedAndTrack ( 0318 ACPI_SIZE Size, 0319 UINT32 Component, 0320 const char *Module, 0321 UINT32 Line) 0322 { 0323 ACPI_DEBUG_MEM_BLOCK *Allocation; 0324 ACPI_STATUS Status; 0325 0326 0327 /* Check for an inadvertent size of zero bytes */ 0328 0329 if (!Size) 0330 { 0331 ACPI_WARNING ((Module, Line, 0332 "Attempt to allocate zero bytes, allocating 1 byte")); 0333 Size = 1; 0334 } 0335 0336 Allocation = AcpiOsAllocateZeroed ( 0337 Size + sizeof (ACPI_DEBUG_MEM_HEADER)); 0338 if (!Allocation) 0339 { 0340 /* Report allocation error */ 0341 0342 ACPI_ERROR ((Module, Line, 0343 "Could not allocate size %u", (UINT32) Size)); 0344 return (NULL); 0345 } 0346 0347 Status = AcpiUtTrackAllocation (Allocation, Size, 0348 ACPI_MEM_CALLOC, Component, Module, Line); 0349 if (ACPI_FAILURE (Status)) 0350 { 0351 AcpiOsFree (Allocation); 0352 return (NULL); 0353 } 0354 0355 AcpiGbl_GlobalList->TotalAllocated++; 0356 AcpiGbl_GlobalList->TotalSize += (UINT32) Size; 0357 AcpiGbl_GlobalList->CurrentTotalSize += (UINT32) Size; 0358 0359 if (AcpiGbl_GlobalList->CurrentTotalSize > 0360 AcpiGbl_GlobalList->MaxOccupied) 0361 { 0362 AcpiGbl_GlobalList->MaxOccupied = 0363 AcpiGbl_GlobalList->CurrentTotalSize; 0364 } 0365 0366 return ((void *) &Allocation->UserSpace); 0367 } 0368 0369 0370 /******************************************************************************* 0371 * 0372 * FUNCTION: AcpiUtFreeAndTrack 0373 * 0374 * PARAMETERS: Allocation - Address of the memory to deallocate 0375 * Component - Component type of caller 0376 * Module - Source file name of caller 0377 * Line - Line number of caller 0378 * 0379 * RETURN: None 0380 * 0381 * DESCRIPTION: Frees the memory at Allocation 0382 * 0383 ******************************************************************************/ 0384 0385 void 0386 AcpiUtFreeAndTrack ( 0387 void *Allocation, 0388 UINT32 Component, 0389 const char *Module, 0390 UINT32 Line) 0391 { 0392 ACPI_DEBUG_MEM_BLOCK *DebugBlock; 0393 ACPI_STATUS Status; 0394 0395 0396 ACPI_FUNCTION_TRACE_PTR (UtFree, Allocation); 0397 0398 0399 if (NULL == Allocation) 0400 { 0401 ACPI_ERROR ((Module, Line, 0402 "Attempt to delete a NULL address")); 0403 0404 return_VOID; 0405 } 0406 0407 DebugBlock = ACPI_CAST_PTR (ACPI_DEBUG_MEM_BLOCK, 0408 (((char *) Allocation) - sizeof (ACPI_DEBUG_MEM_HEADER))); 0409 0410 AcpiGbl_GlobalList->TotalFreed++; 0411 AcpiGbl_GlobalList->CurrentTotalSize -= DebugBlock->Size; 0412 0413 Status = AcpiUtRemoveAllocation (DebugBlock, Component, Module, Line); 0414 if (ACPI_FAILURE (Status)) 0415 { 0416 ACPI_EXCEPTION ((AE_INFO, Status, "Could not free memory")); 0417 } 0418 0419 AcpiOsFree (DebugBlock); 0420 ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS, "%p freed (block %p)\n", 0421 Allocation, DebugBlock)); 0422 return_VOID; 0423 } 0424 0425 0426 /******************************************************************************* 0427 * 0428 * FUNCTION: AcpiUtFindAllocation 0429 * 0430 * PARAMETERS: Allocation - Address of allocated memory 0431 * 0432 * RETURN: Three cases: 0433 * 1) List is empty, NULL is returned. 0434 * 2) Element was found. Returns Allocation parameter. 0435 * 3) Element was not found. Returns position where it should be 0436 * inserted into the list. 0437 * 0438 * DESCRIPTION: Searches for an element in the global allocation tracking list. 0439 * If the element is not found, returns the location within the 0440 * list where the element should be inserted. 0441 * 0442 * Note: The list is ordered by larger-to-smaller addresses. 0443 * 0444 * This global list is used to detect memory leaks in ACPICA as 0445 * well as other issues such as an attempt to release the same 0446 * internal object more than once. Although expensive as far 0447 * as cpu time, this list is much more helpful for finding these 0448 * types of issues than using memory leak detectors outside of 0449 * the ACPICA code. 0450 * 0451 ******************************************************************************/ 0452 0453 static ACPI_DEBUG_MEM_BLOCK * 0454 AcpiUtFindAllocation ( 0455 ACPI_DEBUG_MEM_BLOCK *Allocation) 0456 { 0457 ACPI_DEBUG_MEM_BLOCK *Element; 0458 0459 0460 Element = AcpiGbl_GlobalList->ListHead; 0461 if (!Element) 0462 { 0463 return (NULL); 0464 } 0465 0466 /* 0467 * Search for the address. 0468 * 0469 * Note: List is ordered by larger-to-smaller addresses, on the 0470 * assumption that a new allocation usually has a larger address 0471 * than previous allocations. 0472 */ 0473 while (Element > Allocation) 0474 { 0475 /* Check for end-of-list */ 0476 0477 if (!Element->Next) 0478 { 0479 return (Element); 0480 } 0481 0482 Element = Element->Next; 0483 } 0484 0485 if (Element == Allocation) 0486 { 0487 return (Element); 0488 } 0489 0490 return (Element->Previous); 0491 } 0492 0493 0494 /******************************************************************************* 0495 * 0496 * FUNCTION: AcpiUtTrackAllocation 0497 * 0498 * PARAMETERS: Allocation - Address of allocated memory 0499 * Size - Size of the allocation 0500 * AllocType - MEM_MALLOC or MEM_CALLOC 0501 * Component - Component type of caller 0502 * Module - Source file name of caller 0503 * Line - Line number of caller 0504 * 0505 * RETURN: Status 0506 * 0507 * DESCRIPTION: Inserts an element into the global allocation tracking list. 0508 * 0509 ******************************************************************************/ 0510 0511 static ACPI_STATUS 0512 AcpiUtTrackAllocation ( 0513 ACPI_DEBUG_MEM_BLOCK *Allocation, 0514 ACPI_SIZE Size, 0515 UINT8 AllocType, 0516 UINT32 Component, 0517 const char *Module, 0518 UINT32 Line) 0519 { 0520 ACPI_MEMORY_LIST *MemList; 0521 ACPI_DEBUG_MEM_BLOCK *Element; 0522 ACPI_STATUS Status = AE_OK; 0523 0524 0525 ACPI_FUNCTION_TRACE_PTR (UtTrackAllocation, Allocation); 0526 0527 0528 if (AcpiGbl_DisableMemTracking) 0529 { 0530 return_ACPI_STATUS (AE_OK); 0531 } 0532 0533 MemList = AcpiGbl_GlobalList; 0534 Status = AcpiUtAcquireMutex (ACPI_MTX_MEMORY); 0535 if (ACPI_FAILURE (Status)) 0536 { 0537 return_ACPI_STATUS (Status); 0538 } 0539 0540 /* 0541 * Search the global list for this address to make sure it is not 0542 * already present. This will catch several kinds of problems. 0543 */ 0544 Element = AcpiUtFindAllocation (Allocation); 0545 if (Element == Allocation) 0546 { 0547 ACPI_ERROR ((AE_INFO, 0548 "UtTrackAllocation: Allocation (%p) already present in global list!", 0549 Allocation)); 0550 goto UnlockAndExit; 0551 } 0552 0553 /* Fill in the instance data */ 0554 0555 Allocation->Size = (UINT32) Size; 0556 Allocation->AllocType = AllocType; 0557 Allocation->Component = Component; 0558 Allocation->Line = Line; 0559 0560 AcpiUtSafeStrncpy (Allocation->Module, (char *) Module, ACPI_MAX_MODULE_NAME); 0561 0562 if (!Element) 0563 { 0564 /* Insert at list head */ 0565 0566 if (MemList->ListHead) 0567 { 0568 ((ACPI_DEBUG_MEM_BLOCK *)(MemList->ListHead))->Previous = 0569 Allocation; 0570 } 0571 0572 Allocation->Next = MemList->ListHead; 0573 Allocation->Previous = NULL; 0574 0575 MemList->ListHead = Allocation; 0576 } 0577 else 0578 { 0579 /* Insert after element */ 0580 0581 Allocation->Next = Element->Next; 0582 Allocation->Previous = Element; 0583 0584 if (Element->Next) 0585 { 0586 (Element->Next)->Previous = Allocation; 0587 } 0588 0589 Element->Next = Allocation; 0590 } 0591 0592 0593 UnlockAndExit: 0594 Status = AcpiUtReleaseMutex (ACPI_MTX_MEMORY); 0595 return_ACPI_STATUS (Status); 0596 } 0597 0598 0599 /******************************************************************************* 0600 * 0601 * FUNCTION: AcpiUtRemoveAllocation 0602 * 0603 * PARAMETERS: Allocation - Address of allocated memory 0604 * Component - Component type of caller 0605 * Module - Source file name of caller 0606 * Line - Line number of caller 0607 * 0608 * RETURN: Status 0609 * 0610 * DESCRIPTION: Deletes an element from the global allocation tracking list. 0611 * 0612 ******************************************************************************/ 0613 0614 static ACPI_STATUS 0615 AcpiUtRemoveAllocation ( 0616 ACPI_DEBUG_MEM_BLOCK *Allocation, 0617 UINT32 Component, 0618 const char *Module, 0619 UINT32 Line) 0620 { 0621 ACPI_MEMORY_LIST *MemList; 0622 ACPI_STATUS Status; 0623 0624 0625 ACPI_FUNCTION_NAME (UtRemoveAllocation); 0626 0627 0628 if (AcpiGbl_DisableMemTracking) 0629 { 0630 return (AE_OK); 0631 } 0632 0633 MemList = AcpiGbl_GlobalList; 0634 if (NULL == MemList->ListHead) 0635 { 0636 /* No allocations! */ 0637 0638 ACPI_ERROR ((Module, Line, 0639 "Empty allocation list, nothing to free!")); 0640 0641 return (AE_OK); 0642 } 0643 0644 Status = AcpiUtAcquireMutex (ACPI_MTX_MEMORY); 0645 if (ACPI_FAILURE (Status)) 0646 { 0647 return (Status); 0648 } 0649 0650 /* Unlink */ 0651 0652 if (Allocation->Previous) 0653 { 0654 (Allocation->Previous)->Next = Allocation->Next; 0655 } 0656 else 0657 { 0658 MemList->ListHead = Allocation->Next; 0659 } 0660 0661 if (Allocation->Next) 0662 { 0663 (Allocation->Next)->Previous = Allocation->Previous; 0664 } 0665 0666 ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS, "Freeing %p, size 0%X\n", 0667 &Allocation->UserSpace, Allocation->Size)); 0668 0669 /* Mark the segment as deleted */ 0670 0671 memset (&Allocation->UserSpace, 0xEA, Allocation->Size); 0672 0673 Status = AcpiUtReleaseMutex (ACPI_MTX_MEMORY); 0674 return (Status); 0675 } 0676 0677 0678 /******************************************************************************* 0679 * 0680 * FUNCTION: AcpiUtDumpAllocationInfo 0681 * 0682 * PARAMETERS: None 0683 * 0684 * RETURN: None 0685 * 0686 * DESCRIPTION: Print some info about the outstanding allocations. 0687 * 0688 ******************************************************************************/ 0689 0690 void 0691 AcpiUtDumpAllocationInfo ( 0692 void) 0693 { 0694 /* 0695 ACPI_MEMORY_LIST *MemList; 0696 */ 0697 0698 ACPI_FUNCTION_TRACE (UtDumpAllocationInfo); 0699 0700 /* 0701 ACPI_DEBUG_PRINT (TRACE_ALLOCATIONS | TRACE_TABLES, 0702 ("%30s: %4d (%3d Kb)\n", "Current allocations", 0703 MemList->CurrentCount, 0704 ROUND_UP_TO_1K (MemList->CurrentSize))); 0705 0706 ACPI_DEBUG_PRINT (TRACE_ALLOCATIONS | TRACE_TABLES, 0707 ("%30s: %4d (%3d Kb)\n", "Max concurrent allocations", 0708 MemList->MaxConcurrentCount, 0709 ROUND_UP_TO_1K (MemList->MaxConcurrentSize))); 0710 0711 0712 ACPI_DEBUG_PRINT (TRACE_ALLOCATIONS | TRACE_TABLES, 0713 ("%30s: %4d (%3d Kb)\n", "Total (all) internal objects", 0714 RunningObjectCount, 0715 ROUND_UP_TO_1K (RunningObjectSize))); 0716 0717 ACPI_DEBUG_PRINT (TRACE_ALLOCATIONS | TRACE_TABLES, 0718 ("%30s: %4d (%3d Kb)\n", "Total (all) allocations", 0719 RunningAllocCount, 0720 ROUND_UP_TO_1K (RunningAllocSize))); 0721 0722 0723 ACPI_DEBUG_PRINT (TRACE_ALLOCATIONS | TRACE_TABLES, 0724 ("%30s: %4d (%3d Kb)\n", "Current Nodes", 0725 AcpiGbl_CurrentNodeCount, 0726 ROUND_UP_TO_1K (AcpiGbl_CurrentNodeSize))); 0727 0728 ACPI_DEBUG_PRINT (TRACE_ALLOCATIONS | TRACE_TABLES, 0729 ("%30s: %4d (%3d Kb)\n", "Max Nodes", 0730 AcpiGbl_MaxConcurrentNodeCount, 0731 ROUND_UP_TO_1K ((AcpiGbl_MaxConcurrentNodeCount * 0732 sizeof (ACPI_NAMESPACE_NODE))))); 0733 */ 0734 return_VOID; 0735 } 0736 0737 0738 /******************************************************************************* 0739 * 0740 * FUNCTION: AcpiUtDumpAllocations 0741 * 0742 * PARAMETERS: Component - Component(s) to dump info for. 0743 * Module - Module to dump info for. NULL means all. 0744 * 0745 * RETURN: None 0746 * 0747 * DESCRIPTION: Print a list of all outstanding allocations. 0748 * 0749 ******************************************************************************/ 0750 0751 void 0752 AcpiUtDumpAllocations ( 0753 UINT32 Component, 0754 const char *Module) 0755 { 0756 ACPI_DEBUG_MEM_BLOCK *Element; 0757 ACPI_DESCRIPTOR *Descriptor; 0758 UINT32 NumOutstanding = 0; 0759 UINT8 DescriptorType; 0760 0761 0762 ACPI_FUNCTION_TRACE (UtDumpAllocations); 0763 0764 0765 if (AcpiGbl_DisableMemTracking) 0766 { 0767 return_VOID; 0768 } 0769 0770 /* 0771 * Walk the allocation list. 0772 */ 0773 if (ACPI_FAILURE (AcpiUtAcquireMutex (ACPI_MTX_MEMORY))) 0774 { 0775 return_VOID; 0776 } 0777 0778 if (!AcpiGbl_GlobalList) 0779 { 0780 goto Exit; 0781 } 0782 0783 Element = AcpiGbl_GlobalList->ListHead; 0784 while (Element) 0785 { 0786 if ((Element->Component & Component) && 0787 ((Module == NULL) || (0 == strcmp (Module, Element->Module)))) 0788 { 0789 Descriptor = ACPI_CAST_PTR ( 0790 ACPI_DESCRIPTOR, &Element->UserSpace); 0791 0792 if (Element->Size < sizeof (ACPI_COMMON_DESCRIPTOR)) 0793 { 0794 AcpiOsPrintf ("%p Length 0x%04X %9.9s-%4.4u " 0795 "[Not a Descriptor - too small]\n", 0796 Descriptor, Element->Size, Element->Module, 0797 Element->Line); 0798 } 0799 else 0800 { 0801 /* Ignore allocated objects that are in a cache */ 0802 0803 if (ACPI_GET_DESCRIPTOR_TYPE (Descriptor) != 0804 ACPI_DESC_TYPE_CACHED) 0805 { 0806 AcpiOsPrintf ("%p Length 0x%04X %9.9s-%4.4u [%s] ", 0807 Descriptor, Element->Size, Element->Module, 0808 Element->Line, AcpiUtGetDescriptorName (Descriptor)); 0809 0810 /* Optional object hex dump */ 0811 0812 if (AcpiGbl_VerboseLeakDump) 0813 { 0814 AcpiOsPrintf ("\n"); 0815 AcpiUtDumpBuffer ((UINT8 *) Descriptor, Element->Size, 0816 DB_BYTE_DISPLAY, 0); 0817 } 0818 0819 /* Validate the descriptor type using Type field and length */ 0820 0821 DescriptorType = 0; /* Not a valid descriptor type */ 0822 0823 switch (ACPI_GET_DESCRIPTOR_TYPE (Descriptor)) 0824 { 0825 case ACPI_DESC_TYPE_OPERAND: 0826 0827 if (Element->Size == sizeof (ACPI_OPERAND_OBJECT)) 0828 { 0829 DescriptorType = ACPI_DESC_TYPE_OPERAND; 0830 } 0831 break; 0832 0833 case ACPI_DESC_TYPE_PARSER: 0834 0835 if (Element->Size == sizeof (ACPI_PARSE_OBJECT)) 0836 { 0837 DescriptorType = ACPI_DESC_TYPE_PARSER; 0838 } 0839 break; 0840 0841 case ACPI_DESC_TYPE_NAMED: 0842 0843 if (Element->Size == sizeof (ACPI_NAMESPACE_NODE)) 0844 { 0845 DescriptorType = ACPI_DESC_TYPE_NAMED; 0846 } 0847 break; 0848 0849 default: 0850 0851 break; 0852 } 0853 0854 /* Display additional info for the major descriptor types */ 0855 0856 switch (DescriptorType) 0857 { 0858 case ACPI_DESC_TYPE_OPERAND: 0859 0860 AcpiOsPrintf ("%12.12s RefCount 0x%04X\n", 0861 AcpiUtGetTypeName (Descriptor->Object.Common.Type), 0862 Descriptor->Object.Common.ReferenceCount); 0863 break; 0864 0865 case ACPI_DESC_TYPE_PARSER: 0866 0867 AcpiOsPrintf ("AmlOpcode 0x%04X\n", 0868 Descriptor->Op.Asl.AmlOpcode); 0869 break; 0870 0871 case ACPI_DESC_TYPE_NAMED: 0872 0873 AcpiOsPrintf ("%4.4s\n", 0874 AcpiUtGetNodeName (&Descriptor->Node)); 0875 break; 0876 0877 default: 0878 0879 AcpiOsPrintf ( "\n"); 0880 break; 0881 } 0882 } 0883 } 0884 0885 NumOutstanding++; 0886 } 0887 0888 Element = Element->Next; 0889 } 0890 0891 Exit: 0892 (void) AcpiUtReleaseMutex (ACPI_MTX_MEMORY); 0893 0894 /* Print summary */ 0895 0896 if (!NumOutstanding) 0897 { 0898 ACPI_INFO (("No outstanding allocations")); 0899 } 0900 else 0901 { 0902 ACPI_ERROR ((AE_INFO, "%u (0x%X) Outstanding cache allocations", 0903 NumOutstanding, NumOutstanding)); 0904 } 0905 0906 return_VOID; 0907 } 0908 0909 #endif /* ACPI_DBG_TRACK_ALLOCATIONS */
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
![]() ![]() |