Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygenuttrack.c
Go to the documentation of this file.
00001 /****************************************************************************** 00002 * 00003 * Module Name: uttrack - Memory allocation tracking routines (debug only) 00004 * 00005 *****************************************************************************/ 00006 00007 /****************************************************************************** 00008 * 00009 * 1. Copyright Notice 00010 * 00011 * Some or all of this work - Copyright (c) 1999 - 2011, Intel Corp. 00012 * All rights reserved. 00013 * 00014 * 2. License 00015 * 00016 * 2.1. This is your license from Intel Corp. under its intellectual property 00017 * rights. You may have additional license terms from the party that provided 00018 * you this software, covering your right to use that party's intellectual 00019 * property rights. 00020 * 00021 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a 00022 * copy of the source code appearing in this file ("Covered Code") an 00023 * irrevocable, perpetual, worldwide license under Intel's copyrights in the 00024 * base code distributed originally by Intel ("Original Intel Code") to copy, 00025 * make derivatives, distribute, use and display any portion of the Covered 00026 * Code in any form, with the right to sublicense such rights; and 00027 * 00028 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent 00029 * license (with the right to sublicense), under only those claims of Intel 00030 * patents that are infringed by the Original Intel Code, to make, use, sell, 00031 * offer to sell, and import the Covered Code and derivative works thereof 00032 * solely to the minimum extent necessary to exercise the above copyright 00033 * license, and in no event shall the patent license extend to any additions 00034 * to or modifications of the Original Intel Code. No other license or right 00035 * is granted directly or by implication, estoppel or otherwise; 00036 * 00037 * The above copyright and patent license is granted only if the following 00038 * conditions are met: 00039 * 00040 * 3. Conditions 00041 * 00042 * 3.1. Redistribution of Source with Rights to Further Distribute Source. 00043 * Redistribution of source code of any substantial portion of the Covered 00044 * Code or modification with rights to further distribute source must include 00045 * the above Copyright Notice, the above License, this list of Conditions, 00046 * and the following Disclaimer and Export Compliance provision. In addition, 00047 * Licensee must cause all Covered Code to which Licensee contributes to 00048 * contain a file documenting the changes Licensee made to create that Covered 00049 * Code and the date of any change. Licensee must include in that file the 00050 * documentation of any changes made by any predecessor Licensee. Licensee 00051 * must include a prominent statement that the modification is derived, 00052 * directly or indirectly, from Original Intel Code. 00053 * 00054 * 3.2. Redistribution of Source with no Rights to Further Distribute Source. 00055 * Redistribution of source code of any substantial portion of the Covered 00056 * Code or modification without rights to further distribute source must 00057 * include the following Disclaimer and Export Compliance provision in the 00058 * documentation and/or other materials provided with distribution. In 00059 * addition, Licensee may not authorize further sublicense of source of any 00060 * portion of the Covered Code, and must include terms to the effect that the 00061 * license from Licensee to its licensee is limited to the intellectual 00062 * property embodied in the software Licensee provides to its licensee, and 00063 * not to intellectual property embodied in modifications its licensee may 00064 * make. 00065 * 00066 * 3.3. Redistribution of Executable. Redistribution in executable form of any 00067 * substantial portion of the Covered Code or modification must reproduce the 00068 * above Copyright Notice, and the following Disclaimer and Export Compliance 00069 * provision in the documentation and/or other materials provided with the 00070 * distribution. 00071 * 00072 * 3.4. Intel retains all right, title, and interest in and to the Original 00073 * Intel Code. 00074 * 00075 * 3.5. Neither the name Intel nor any other trademark owned or controlled by 00076 * Intel shall be used in advertising or otherwise to promote the sale, use or 00077 * other dealings in products derived from or relating to the Covered Code 00078 * without prior written authorization from Intel. 00079 * 00080 * 4. Disclaimer and Export Compliance 00081 * 00082 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED 00083 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE 00084 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE, 00085 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY 00086 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY 00087 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A 00088 * PARTICULAR PURPOSE. 00089 * 00090 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES 00091 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR 00092 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT, 00093 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY 00094 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL 00095 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS 00096 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY 00097 * LIMITED REMEDY. 00098 * 00099 * 4.3. Licensee shall not export, either directly or indirectly, any of this 00100 * software or system incorporating such software without first obtaining any 00101 * required license or other approval from the U. S. Department of Commerce or 00102 * any other agency or department of the United States Government. In the 00103 * event Licensee exports any such software from the United States or 00104 * re-exports any such software from a foreign destination, Licensee shall 00105 * ensure that the distribution and export/re-export of the software is in 00106 * compliance with all laws, regulations, orders, or other restrictions of the 00107 * U.S. Export Administration Regulations. Licensee agrees that neither it nor 00108 * any of its subsidiaries will export/re-export any technical data, process, 00109 * software, or service, directly or indirectly, to any country for which the 00110 * United States government or any agency thereof requires an export license, 00111 * other governmental approval, or letter of assurance, without first obtaining 00112 * such license, approval or letter. 00113 * 00114 *****************************************************************************/ 00115 00116 /* 00117 * These procedures are used for tracking memory leaks in the subsystem, and 00118 * they get compiled out when the ACPI_DBG_TRACK_ALLOCATIONS is not set. 00119 * 00120 * Each memory allocation is tracked via a doubly linked list. Each 00121 * element contains the caller's component, module name, function name, and 00122 * line number. AcpiUtAllocate and AcpiUtAllocateZeroed call 00123 * AcpiUtTrackAllocation to add an element to the list; deletion 00124 * occurs in the body of AcpiUtFree. 00125 */ 00126 00127 #define __UTTRACK_C__ 00128 00129 #include "acpi.h" 00130 #include "accommon.h" 00131 00132 #ifdef ACPI_DBG_TRACK_ALLOCATIONS 00133 00134 #define _COMPONENT ACPI_UTILITIES 00135 ACPI_MODULE_NAME ("uttrack") 00136 00137 /* Local prototypes */ 00138 00139 static ACPI_DEBUG_MEM_BLOCK * 00140 AcpiUtFindAllocation ( 00141 void *Allocation); 00142 00143 static ACPI_STATUS 00144 AcpiUtTrackAllocation ( 00145 ACPI_DEBUG_MEM_BLOCK *Address, 00146 ACPI_SIZE Size, 00147 UINT8 AllocType, 00148 UINT32 Component, 00149 const char *Module, 00150 UINT32 Line); 00151 00152 static ACPI_STATUS 00153 AcpiUtRemoveAllocation ( 00154 ACPI_DEBUG_MEM_BLOCK *Address, 00155 UINT32 Component, 00156 const char *Module, 00157 UINT32 Line); 00158 00159 00160 /******************************************************************************* 00161 * 00162 * FUNCTION: AcpiUtCreateList 00163 * 00164 * PARAMETERS: CacheName - Ascii name for the cache 00165 * ObjectSize - Size of each cached object 00166 * ReturnCache - Where the new cache object is returned 00167 * 00168 * RETURN: Status 00169 * 00170 * DESCRIPTION: Create a local memory list for tracking purposed 00171 * 00172 ******************************************************************************/ 00173 00174 ACPI_STATUS 00175 AcpiUtCreateList ( 00176 char *ListName, 00177 UINT16 ObjectSize, 00178 ACPI_MEMORY_LIST **ReturnCache) 00179 { 00180 ACPI_MEMORY_LIST *Cache; 00181 00182 00183 Cache = AcpiOsAllocate (sizeof (ACPI_MEMORY_LIST)); 00184 if (!Cache) 00185 { 00186 return (AE_NO_MEMORY); 00187 } 00188 00189 ACPI_MEMSET (Cache, 0, sizeof (ACPI_MEMORY_LIST)); 00190 00191 Cache->ListName = ListName; 00192 Cache->ObjectSize = ObjectSize; 00193 00194 *ReturnCache = Cache; 00195 return (AE_OK); 00196 } 00197 00198 00199 /******************************************************************************* 00200 * 00201 * FUNCTION: AcpiUtAllocateAndTrack 00202 * 00203 * PARAMETERS: Size - Size of the allocation 00204 * Component - Component type of caller 00205 * Module - Source file name of caller 00206 * Line - Line number of caller 00207 * 00208 * RETURN: Address of the allocated memory on success, NULL on failure. 00209 * 00210 * DESCRIPTION: The subsystem's equivalent of malloc. 00211 * 00212 ******************************************************************************/ 00213 00214 void * 00215 AcpiUtAllocateAndTrack ( 00216 ACPI_SIZE Size, 00217 UINT32 Component, 00218 const char *Module, 00219 UINT32 Line) 00220 { 00221 ACPI_DEBUG_MEM_BLOCK *Allocation; 00222 ACPI_STATUS Status; 00223 00224 00225 Allocation = AcpiUtAllocate (Size + sizeof (ACPI_DEBUG_MEM_HEADER), 00226 Component, Module, Line); 00227 if (!Allocation) 00228 { 00229 return (NULL); 00230 } 00231 00232 Status = AcpiUtTrackAllocation (Allocation, Size, 00233 ACPI_MEM_MALLOC, Component, Module, Line); 00234 if (ACPI_FAILURE (Status)) 00235 { 00236 AcpiOsFree (Allocation); 00237 return (NULL); 00238 } 00239 00240 AcpiGbl_GlobalList->TotalAllocated++; 00241 AcpiGbl_GlobalList->TotalSize += (UINT32) Size; 00242 AcpiGbl_GlobalList->CurrentTotalSize += (UINT32) Size; 00243 if (AcpiGbl_GlobalList->CurrentTotalSize > AcpiGbl_GlobalList->MaxOccupied) 00244 { 00245 AcpiGbl_GlobalList->MaxOccupied = AcpiGbl_GlobalList->CurrentTotalSize; 00246 } 00247 00248 return ((void *) &Allocation->UserSpace); 00249 } 00250 00251 00252 /******************************************************************************* 00253 * 00254 * FUNCTION: AcpiUtAllocateZeroedAndTrack 00255 * 00256 * PARAMETERS: Size - Size of the allocation 00257 * Component - Component type of caller 00258 * Module - Source file name of caller 00259 * Line - Line number of caller 00260 * 00261 * RETURN: Address of the allocated memory on success, NULL on failure. 00262 * 00263 * DESCRIPTION: Subsystem equivalent of calloc. 00264 * 00265 ******************************************************************************/ 00266 00267 void * 00268 AcpiUtAllocateZeroedAndTrack ( 00269 ACPI_SIZE Size, 00270 UINT32 Component, 00271 const char *Module, 00272 UINT32 Line) 00273 { 00274 ACPI_DEBUG_MEM_BLOCK *Allocation; 00275 ACPI_STATUS Status; 00276 00277 00278 Allocation = AcpiUtAllocateZeroed (Size + sizeof (ACPI_DEBUG_MEM_HEADER), 00279 Component, Module, Line); 00280 if (!Allocation) 00281 { 00282 /* Report allocation error */ 00283 00284 ACPI_ERROR ((Module, Line, 00285 "Could not allocate size %u", (UINT32) Size)); 00286 return (NULL); 00287 } 00288 00289 Status = AcpiUtTrackAllocation (Allocation, Size, 00290 ACPI_MEM_CALLOC, Component, Module, Line); 00291 if (ACPI_FAILURE (Status)) 00292 { 00293 AcpiOsFree (Allocation); 00294 return (NULL); 00295 } 00296 00297 AcpiGbl_GlobalList->TotalAllocated++; 00298 AcpiGbl_GlobalList->TotalSize += (UINT32) Size; 00299 AcpiGbl_GlobalList->CurrentTotalSize += (UINT32) Size; 00300 if (AcpiGbl_GlobalList->CurrentTotalSize > AcpiGbl_GlobalList->MaxOccupied) 00301 { 00302 AcpiGbl_GlobalList->MaxOccupied = AcpiGbl_GlobalList->CurrentTotalSize; 00303 } 00304 00305 return ((void *) &Allocation->UserSpace); 00306 } 00307 00308 00309 /******************************************************************************* 00310 * 00311 * FUNCTION: AcpiUtFreeAndTrack 00312 * 00313 * PARAMETERS: Allocation - Address of the memory to deallocate 00314 * Component - Component type of caller 00315 * Module - Source file name of caller 00316 * Line - Line number of caller 00317 * 00318 * RETURN: None 00319 * 00320 * DESCRIPTION: Frees the memory at Allocation 00321 * 00322 ******************************************************************************/ 00323 00324 void 00325 AcpiUtFreeAndTrack ( 00326 void *Allocation, 00327 UINT32 Component, 00328 const char *Module, 00329 UINT32 Line) 00330 { 00331 ACPI_DEBUG_MEM_BLOCK *DebugBlock; 00332 ACPI_STATUS Status; 00333 00334 00335 ACPI_FUNCTION_TRACE_PTR (UtFree, Allocation); 00336 00337 00338 if (NULL == Allocation) 00339 { 00340 ACPI_ERROR ((Module, Line, 00341 "Attempt to delete a NULL address")); 00342 00343 return_VOID; 00344 } 00345 00346 DebugBlock = ACPI_CAST_PTR (ACPI_DEBUG_MEM_BLOCK, 00347 (((char *) Allocation) - sizeof (ACPI_DEBUG_MEM_HEADER))); 00348 00349 AcpiGbl_GlobalList->TotalFreed++; 00350 AcpiGbl_GlobalList->CurrentTotalSize -= DebugBlock->Size; 00351 00352 Status = AcpiUtRemoveAllocation (DebugBlock, 00353 Component, Module, Line); 00354 if (ACPI_FAILURE (Status)) 00355 { 00356 ACPI_EXCEPTION ((AE_INFO, Status, "Could not free memory")); 00357 } 00358 00359 AcpiOsFree (DebugBlock); 00360 ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS, "%p freed\n", Allocation)); 00361 return_VOID; 00362 } 00363 00364 00365 /******************************************************************************* 00366 * 00367 * FUNCTION: AcpiUtFindAllocation 00368 * 00369 * PARAMETERS: Allocation - Address of allocated memory 00370 * 00371 * RETURN: A list element if found; NULL otherwise. 00372 * 00373 * DESCRIPTION: Searches for an element in the global allocation tracking list. 00374 * 00375 ******************************************************************************/ 00376 00377 static ACPI_DEBUG_MEM_BLOCK * 00378 AcpiUtFindAllocation ( 00379 void *Allocation) 00380 { 00381 ACPI_DEBUG_MEM_BLOCK *Element; 00382 00383 00384 ACPI_FUNCTION_ENTRY (); 00385 00386 00387 Element = AcpiGbl_GlobalList->ListHead; 00388 00389 /* Search for the address. */ 00390 00391 while (Element) 00392 { 00393 if (Element == Allocation) 00394 { 00395 return (Element); 00396 } 00397 00398 Element = Element->Next; 00399 } 00400 00401 return (NULL); 00402 } 00403 00404 00405 /******************************************************************************* 00406 * 00407 * FUNCTION: AcpiUtTrackAllocation 00408 * 00409 * PARAMETERS: Allocation - Address of allocated memory 00410 * Size - Size of the allocation 00411 * AllocType - MEM_MALLOC or MEM_CALLOC 00412 * Component - Component type of caller 00413 * Module - Source file name of caller 00414 * Line - Line number of caller 00415 * 00416 * RETURN: None. 00417 * 00418 * DESCRIPTION: Inserts an element into the global allocation tracking list. 00419 * 00420 ******************************************************************************/ 00421 00422 static ACPI_STATUS 00423 AcpiUtTrackAllocation ( 00424 ACPI_DEBUG_MEM_BLOCK *Allocation, 00425 ACPI_SIZE Size, 00426 UINT8 AllocType, 00427 UINT32 Component, 00428 const char *Module, 00429 UINT32 Line) 00430 { 00431 ACPI_MEMORY_LIST *MemList; 00432 ACPI_DEBUG_MEM_BLOCK *Element; 00433 ACPI_STATUS Status = AE_OK; 00434 00435 00436 ACPI_FUNCTION_TRACE_PTR (UtTrackAllocation, Allocation); 00437 00438 00439 if (AcpiGbl_DisableMemTracking) 00440 { 00441 return_ACPI_STATUS (AE_OK); 00442 } 00443 00444 MemList = AcpiGbl_GlobalList; 00445 Status = AcpiUtAcquireMutex (ACPI_MTX_MEMORY); 00446 if (ACPI_FAILURE (Status)) 00447 { 00448 return_ACPI_STATUS (Status); 00449 } 00450 00451 /* 00452 * Search list for this address to make sure it is not already on the list. 00453 * This will catch several kinds of problems. 00454 */ 00455 Element = AcpiUtFindAllocation (Allocation); 00456 if (Element) 00457 { 00458 ACPI_ERROR ((AE_INFO, 00459 "UtTrackAllocation: Allocation already present in list! (%p)", 00460 Allocation)); 00461 00462 ACPI_ERROR ((AE_INFO, "Element %p Address %p", 00463 Element, Allocation)); 00464 00465 goto UnlockAndExit; 00466 } 00467 00468 /* Fill in the instance data. */ 00469 00470 Allocation->Size = (UINT32) Size; 00471 Allocation->AllocType = AllocType; 00472 Allocation->Component = Component; 00473 Allocation->Line = Line; 00474 00475 ACPI_STRNCPY (Allocation->Module, Module, ACPI_MAX_MODULE_NAME); 00476 Allocation->Module[ACPI_MAX_MODULE_NAME-1] = 0; 00477 00478 /* Insert at list head */ 00479 00480 if (MemList->ListHead) 00481 { 00482 ((ACPI_DEBUG_MEM_BLOCK *)(MemList->ListHead))->Previous = Allocation; 00483 } 00484 00485 Allocation->Next = MemList->ListHead; 00486 Allocation->Previous = NULL; 00487 00488 MemList->ListHead = Allocation; 00489 00490 00491 UnlockAndExit: 00492 Status = AcpiUtReleaseMutex (ACPI_MTX_MEMORY); 00493 return_ACPI_STATUS (Status); 00494 } 00495 00496 00497 /******************************************************************************* 00498 * 00499 * FUNCTION: AcpiUtRemoveAllocation 00500 * 00501 * PARAMETERS: Allocation - Address of allocated memory 00502 * Component - Component type of caller 00503 * Module - Source file name of caller 00504 * Line - Line number of caller 00505 * 00506 * RETURN: 00507 * 00508 * DESCRIPTION: Deletes an element from the global allocation tracking list. 00509 * 00510 ******************************************************************************/ 00511 00512 static ACPI_STATUS 00513 AcpiUtRemoveAllocation ( 00514 ACPI_DEBUG_MEM_BLOCK *Allocation, 00515 UINT32 Component, 00516 const char *Module, 00517 UINT32 Line) 00518 { 00519 ACPI_MEMORY_LIST *MemList; 00520 ACPI_STATUS Status; 00521 00522 00523 ACPI_FUNCTION_TRACE (UtRemoveAllocation); 00524 00525 00526 if (AcpiGbl_DisableMemTracking) 00527 { 00528 return_ACPI_STATUS (AE_OK); 00529 } 00530 00531 MemList = AcpiGbl_GlobalList; 00532 if (NULL == MemList->ListHead) 00533 { 00534 /* No allocations! */ 00535 00536 ACPI_ERROR ((Module, Line, 00537 "Empty allocation list, nothing to free!")); 00538 00539 return_ACPI_STATUS (AE_OK); 00540 } 00541 00542 Status = AcpiUtAcquireMutex (ACPI_MTX_MEMORY); 00543 if (ACPI_FAILURE (Status)) 00544 { 00545 return_ACPI_STATUS (Status); 00546 } 00547 00548 /* Unlink */ 00549 00550 if (Allocation->Previous) 00551 { 00552 (Allocation->Previous)->Next = Allocation->Next; 00553 } 00554 else 00555 { 00556 MemList->ListHead = Allocation->Next; 00557 } 00558 00559 if (Allocation->Next) 00560 { 00561 (Allocation->Next)->Previous = Allocation->Previous; 00562 } 00563 00564 /* Mark the segment as deleted */ 00565 00566 ACPI_MEMSET (&Allocation->UserSpace, 0xEA, Allocation->Size); 00567 00568 ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS, "Freeing size 0%X\n", 00569 Allocation->Size)); 00570 00571 Status = AcpiUtReleaseMutex (ACPI_MTX_MEMORY); 00572 return_ACPI_STATUS (Status); 00573 } 00574 00575 00576 /******************************************************************************* 00577 * 00578 * FUNCTION: AcpiUtDumpAllocationInfo 00579 * 00580 * PARAMETERS: 00581 * 00582 * RETURN: None 00583 * 00584 * DESCRIPTION: Print some info about the outstanding allocations. 00585 * 00586 ******************************************************************************/ 00587 00588 void 00589 AcpiUtDumpAllocationInfo ( 00590 void) 00591 { 00592 /* 00593 ACPI_MEMORY_LIST *MemList; 00594 */ 00595 00596 ACPI_FUNCTION_TRACE (UtDumpAllocationInfo); 00597 00598 /* 00599 ACPI_DEBUG_PRINT (TRACE_ALLOCATIONS | TRACE_TABLES, 00600 ("%30s: %4d (%3d Kb)\n", "Current allocations", 00601 MemList->CurrentCount, 00602 ROUND_UP_TO_1K (MemList->CurrentSize))); 00603 00604 ACPI_DEBUG_PRINT (TRACE_ALLOCATIONS | TRACE_TABLES, 00605 ("%30s: %4d (%3d Kb)\n", "Max concurrent allocations", 00606 MemList->MaxConcurrentCount, 00607 ROUND_UP_TO_1K (MemList->MaxConcurrentSize))); 00608 00609 00610 ACPI_DEBUG_PRINT (TRACE_ALLOCATIONS | TRACE_TABLES, 00611 ("%30s: %4d (%3d Kb)\n", "Total (all) internal objects", 00612 RunningObjectCount, 00613 ROUND_UP_TO_1K (RunningObjectSize))); 00614 00615 ACPI_DEBUG_PRINT (TRACE_ALLOCATIONS | TRACE_TABLES, 00616 ("%30s: %4d (%3d Kb)\n", "Total (all) allocations", 00617 RunningAllocCount, 00618 ROUND_UP_TO_1K (RunningAllocSize))); 00619 00620 00621 ACPI_DEBUG_PRINT (TRACE_ALLOCATIONS | TRACE_TABLES, 00622 ("%30s: %4d (%3d Kb)\n", "Current Nodes", 00623 AcpiGbl_CurrentNodeCount, 00624 ROUND_UP_TO_1K (AcpiGbl_CurrentNodeSize))); 00625 00626 ACPI_DEBUG_PRINT (TRACE_ALLOCATIONS | TRACE_TABLES, 00627 ("%30s: %4d (%3d Kb)\n", "Max Nodes", 00628 AcpiGbl_MaxConcurrentNodeCount, 00629 ROUND_UP_TO_1K ((AcpiGbl_MaxConcurrentNodeCount * 00630 sizeof (ACPI_NAMESPACE_NODE))))); 00631 */ 00632 return_VOID; 00633 } 00634 00635 00636 /******************************************************************************* 00637 * 00638 * FUNCTION: AcpiUtDumpAllocations 00639 * 00640 * PARAMETERS: Component - Component(s) to dump info for. 00641 * Module - Module to dump info for. NULL means all. 00642 * 00643 * RETURN: None 00644 * 00645 * DESCRIPTION: Print a list of all outstanding allocations. 00646 * 00647 ******************************************************************************/ 00648 00649 void 00650 AcpiUtDumpAllocations ( 00651 UINT32 Component, 00652 const char *Module) 00653 { 00654 ACPI_DEBUG_MEM_BLOCK *Element; 00655 ACPI_DESCRIPTOR *Descriptor; 00656 UINT32 NumOutstanding = 0; 00657 UINT8 DescriptorType; 00658 00659 00660 ACPI_FUNCTION_TRACE (UtDumpAllocations); 00661 00662 00663 if (AcpiGbl_DisableMemTracking) 00664 { 00665 return; 00666 } 00667 00668 /* 00669 * Walk the allocation list. 00670 */ 00671 if (ACPI_FAILURE (AcpiUtAcquireMutex (ACPI_MTX_MEMORY))) 00672 { 00673 return; 00674 } 00675 00676 Element = AcpiGbl_GlobalList->ListHead; 00677 while (Element) 00678 { 00679 if ((Element->Component & Component) && 00680 ((Module == NULL) || (0 == ACPI_STRCMP (Module, Element->Module)))) 00681 { 00682 Descriptor = ACPI_CAST_PTR (ACPI_DESCRIPTOR, &Element->UserSpace); 00683 00684 if (Element->Size < sizeof (ACPI_COMMON_DESCRIPTOR)) 00685 { 00686 AcpiOsPrintf ("%p Length 0x%04X %9.9s-%u " 00687 "[Not a Descriptor - too small]\n", 00688 Descriptor, Element->Size, Element->Module, 00689 Element->Line); 00690 } 00691 else 00692 { 00693 /* Ignore allocated objects that are in a cache */ 00694 00695 if (ACPI_GET_DESCRIPTOR_TYPE (Descriptor) != ACPI_DESC_TYPE_CACHED) 00696 { 00697 AcpiOsPrintf ("%p Length 0x%04X %9.9s-%u [%s] ", 00698 Descriptor, Element->Size, Element->Module, 00699 Element->Line, AcpiUtGetDescriptorName (Descriptor)); 00700 00701 /* Validate the descriptor type using Type field and length */ 00702 00703 DescriptorType = 0; /* Not a valid descriptor type */ 00704 00705 switch (ACPI_GET_DESCRIPTOR_TYPE (Descriptor)) 00706 { 00707 case ACPI_DESC_TYPE_OPERAND: 00708 if (Element->Size == sizeof (ACPI_DESC_TYPE_OPERAND)) 00709 { 00710 DescriptorType = ACPI_DESC_TYPE_OPERAND; 00711 } 00712 break; 00713 00714 case ACPI_DESC_TYPE_PARSER: 00715 if (Element->Size == sizeof (ACPI_DESC_TYPE_PARSER)) 00716 { 00717 DescriptorType = ACPI_DESC_TYPE_PARSER; 00718 } 00719 break; 00720 00721 case ACPI_DESC_TYPE_NAMED: 00722 if (Element->Size == sizeof (ACPI_DESC_TYPE_NAMED)) 00723 { 00724 DescriptorType = ACPI_DESC_TYPE_NAMED; 00725 } 00726 break; 00727 00728 default: 00729 break; 00730 } 00731 00732 /* Display additional info for the major descriptor types */ 00733 00734 switch (DescriptorType) 00735 { 00736 case ACPI_DESC_TYPE_OPERAND: 00737 AcpiOsPrintf ("%12.12s RefCount 0x%04X\n", 00738 AcpiUtGetTypeName (Descriptor->Object.Common.Type), 00739 Descriptor->Object.Common.ReferenceCount); 00740 break; 00741 00742 case ACPI_DESC_TYPE_PARSER: 00743 AcpiOsPrintf ("AmlOpcode 0x%04hX\n", 00744 Descriptor->Op.Asl.AmlOpcode); 00745 break; 00746 00747 case ACPI_DESC_TYPE_NAMED: 00748 AcpiOsPrintf ("%4.4s\n", 00749 AcpiUtGetNodeName (&Descriptor->Node)); 00750 break; 00751 00752 default: 00753 AcpiOsPrintf ( "\n"); 00754 break; 00755 } 00756 } 00757 } 00758 00759 NumOutstanding++; 00760 } 00761 00762 Element = Element->Next; 00763 } 00764 00765 (void) AcpiUtReleaseMutex (ACPI_MTX_MEMORY); 00766 00767 /* Print summary */ 00768 00769 if (!NumOutstanding) 00770 { 00771 ACPI_INFO ((AE_INFO, "No outstanding allocations")); 00772 } 00773 else 00774 { 00775 ACPI_ERROR ((AE_INFO, "%u(0x%X) Outstanding allocations", 00776 NumOutstanding, NumOutstanding)); 00777 } 00778 00779 return_VOID; 00780 } 00781 00782 #endif /* ACPI_DBG_TRACK_ALLOCATIONS */ 00783 Generated on Sun May 27 2012 04:27:24 for ReactOS by
1.7.6.1
|