utalloc.c revision 85756
1/****************************************************************************** 2 * 3 * Module Name: utalloc - local cache and memory allocation routines 4 * $Revision: 106 $ 5 * 6 *****************************************************************************/ 7 8/****************************************************************************** 9 * 10 * 1. Copyright Notice 11 * 12 * Some or all of this work - Copyright (c) 1999, 2000, 2001, Intel Corp. 13 * All rights reserved. 14 * 15 * 2. License 16 * 17 * 2.1. This is your license from Intel Corp. under its intellectual property 18 * rights. You may have additional license terms from the party that provided 19 * you this software, covering your right to use that party's intellectual 20 * property rights. 21 * 22 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a 23 * copy of the source code appearing in this file ("Covered Code") an 24 * irrevocable, perpetual, worldwide license under Intel's copyrights in the 25 * base code distributed originally by Intel ("Original Intel Code") to copy, 26 * make derivatives, distribute, use and display any portion of the Covered 27 * Code in any form, with the right to sublicense such rights; and 28 * 29 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent 30 * license (with the right to sublicense), under only those claims of Intel 31 * patents that are infringed by the Original Intel Code, to make, use, sell, 32 * offer to sell, and import the Covered Code and derivative works thereof 33 * solely to the minimum extent necessary to exercise the above copyright 34 * license, and in no event shall the patent license extend to any additions 35 * to or modifications of the Original Intel Code. No other license or right 36 * is granted directly or by implication, estoppel or otherwise; 37 * 38 * The above copyright and patent license is granted only if the following 39 * conditions are met: 40 * 41 * 3. Conditions 42 * 43 * 3.1. Redistribution of Source with Rights to Further Distribute Source. 44 * Redistribution of source code of any substantial portion of the Covered 45 * Code or modification with rights to further distribute source must include 46 * the above Copyright Notice, the above License, this list of Conditions, 47 * and the following Disclaimer and Export Compliance provision. In addition, 48 * Licensee must cause all Covered Code to which Licensee contributes to 49 * contain a file documenting the changes Licensee made to create that Covered 50 * Code and the date of any change. Licensee must include in that file the 51 * documentation of any changes made by any predecessor Licensee. Licensee 52 * must include a prominent statement that the modification is derived, 53 * directly or indirectly, from Original Intel Code. 54 * 55 * 3.2. Redistribution of Source with no Rights to Further Distribute Source. 56 * Redistribution of source code of any substantial portion of the Covered 57 * Code or modification without rights to further distribute source must 58 * include the following Disclaimer and Export Compliance provision in the 59 * documentation and/or other materials provided with distribution. In 60 * addition, Licensee may not authorize further sublicense of source of any 61 * portion of the Covered Code, and must include terms to the effect that the 62 * license from Licensee to its licensee is limited to the intellectual 63 * property embodied in the software Licensee provides to its licensee, and 64 * not to intellectual property embodied in modifications its licensee may 65 * make. 66 * 67 * 3.3. Redistribution of Executable. Redistribution in executable form of any 68 * substantial portion of the Covered Code or modification must reproduce the 69 * above Copyright Notice, and the following Disclaimer and Export Compliance 70 * provision in the documentation and/or other materials provided with the 71 * distribution. 72 * 73 * 3.4. Intel retains all right, title, and interest in and to the Original 74 * Intel Code. 75 * 76 * 3.5. Neither the name Intel nor any other trademark owned or controlled by 77 * Intel shall be used in advertising or otherwise to promote the sale, use or 78 * other dealings in products derived from or relating to the Covered Code 79 * without prior written authorization from Intel. 80 * 81 * 4. Disclaimer and Export Compliance 82 * 83 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED 84 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE 85 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE, 86 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY 87 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY 88 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A 89 * PARTICULAR PURPOSE. 90 * 91 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES 92 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR 93 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT, 94 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY 95 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL 96 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS 97 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY 98 * LIMITED REMEDY. 99 * 100 * 4.3. Licensee shall not export, either directly or indirectly, any of this 101 * software or system incorporating such software without first obtaining any 102 * required license or other approval from the U. S. Department of Commerce or 103 * any other agency or department of the United States Government. In the 104 * event Licensee exports any such software from the United States or 105 * re-exports any such software from a foreign destination, Licensee shall 106 * ensure that the distribution and export/re-export of the software is in 107 * compliance with all laws, regulations, orders, or other restrictions of the 108 * U.S. Export Administration Regulations. Licensee agrees that neither it nor 109 * any of its subsidiaries will export/re-export any technical data, process, 110 * software, or service, directly or indirectly, to any country for which the 111 * United States government or any agency thereof requires an export license, 112 * other governmental approval, or letter of assurance, without first obtaining 113 * such license, approval or letter. 114 * 115 *****************************************************************************/ 116 117#define __UTALLOC_C__ 118 119#include "acpi.h" 120#include "acparser.h" 121#include "acinterp.h" 122#include "acnamesp.h" 123#include "acglobal.h" 124 125#define _COMPONENT ACPI_UTILITIES 126 MODULE_NAME ("utalloc") 127 128 129/****************************************************************************** 130 * 131 * FUNCTION: AcpiUtReleaseToCache 132 * 133 * PARAMETERS: ListId - Memory list/cache ID 134 * Object - The object to be released 135 * 136 * RETURN: None 137 * 138 * DESCRIPTION: Release an object to the specified cache. If cache is full, 139 * the object is deleted. 140 * 141 ******************************************************************************/ 142 143void 144AcpiUtReleaseToCache ( 145 UINT32 ListId, 146 void *Object) 147{ 148 ACPI_MEMORY_LIST *CacheInfo; 149 150 151 FUNCTION_ENTRY (); 152 153 154 /* If walk cache is full, just free this wallkstate object */ 155 156 CacheInfo = &AcpiGbl_MemoryLists[ListId]; 157 if (CacheInfo->CacheDepth >= CacheInfo->MaxCacheDepth) 158 { 159 ACPI_MEM_FREE (Object); 160 ACPI_MEM_TRACKING (CacheInfo->TotalFreed++); 161 } 162 163 /* Otherwise put this object back into the cache */ 164 165 else 166 { 167 AcpiUtAcquireMutex (ACPI_MTX_CACHES); 168 169 /* Mark the object as cached */ 170 171 MEMSET (Object, 0xCA, CacheInfo->ObjectSize); 172 ((ACPI_OPERAND_OBJECT *) Object)->Common.DataType = ACPI_CACHED_OBJECT; 173 174 /* Put the object at the head of the cache list */ 175 176 * (char **) (((char *) Object) + CacheInfo->LinkOffset) = CacheInfo->ListHead; 177 CacheInfo->ListHead = Object; 178 CacheInfo->CacheDepth++; 179 180 AcpiUtReleaseMutex (ACPI_MTX_CACHES); 181 } 182} 183 184 185/****************************************************************************** 186 * 187 * FUNCTION: AcpiUtAcquireFromCache 188 * 189 * PARAMETERS: ListId - Memory list ID 190 * 191 * RETURN: A requested object. NULL if the object could not be 192 * allocated. 193 * 194 * DESCRIPTION: Get an object from the specified cache. If cache is empty, 195 * the object is allocated. 196 * 197 ******************************************************************************/ 198 199void * 200AcpiUtAcquireFromCache ( 201 UINT32 ListId) 202{ 203 ACPI_MEMORY_LIST *CacheInfo; 204 void *Object; 205 206 207 PROC_NAME ("UtAcquireFromCache"); 208 209 210 CacheInfo = &AcpiGbl_MemoryLists[ListId]; 211 AcpiUtAcquireMutex (ACPI_MTX_CACHES); 212 ACPI_MEM_TRACKING (CacheInfo->CacheRequests++); 213 214 /* Check the cache first */ 215 216 if (CacheInfo->ListHead) 217 { 218 /* There is an object available, use it */ 219 220 Object = CacheInfo->ListHead; 221 CacheInfo->ListHead = * (char **) (((char *) Object) + CacheInfo->LinkOffset); 222 223 ACPI_MEM_TRACKING (CacheInfo->CacheHits++); 224 CacheInfo->CacheDepth--; 225 226#ifdef ACPI_DBG_TRACK_ALLOCATIONS 227 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Object %p from %s\n", 228 Object, AcpiGbl_MemoryLists[ListId].ListName)); 229#endif 230 231 AcpiUtReleaseMutex (ACPI_MTX_CACHES); 232 233 /* Clear (zero) the previously used Object */ 234 235 MEMSET (Object, 0, CacheInfo->ObjectSize); 236 } 237 238 else 239 { 240 /* The cache is empty, create a new object */ 241 242 /* Avoid deadlock with ACPI_MEM_CALLOCATE */ 243 244 AcpiUtReleaseMutex (ACPI_MTX_CACHES); 245 246 Object = ACPI_MEM_CALLOCATE (CacheInfo->ObjectSize); 247 ACPI_MEM_TRACKING (CacheInfo->TotalAllocated++); 248 } 249 250 return (Object); 251} 252 253 254/****************************************************************************** 255 * 256 * FUNCTION: AcpiUtDeleteGenericCache 257 * 258 * PARAMETERS: ListId - Memory list ID 259 * 260 * RETURN: None 261 * 262 * DESCRIPTION: Free all objects within the requested cache. 263 * 264 ******************************************************************************/ 265 266void 267AcpiUtDeleteGenericCache ( 268 UINT32 ListId) 269{ 270 ACPI_MEMORY_LIST *CacheInfo; 271 char *Next; 272 273 274 FUNCTION_ENTRY (); 275 276 277 CacheInfo = &AcpiGbl_MemoryLists[ListId]; 278 while (CacheInfo->ListHead) 279 { 280 /* Delete one cached state object */ 281 282 Next = * (char **) (((char *) CacheInfo->ListHead) + CacheInfo->LinkOffset); 283 ACPI_MEM_FREE (CacheInfo->ListHead); 284 285 CacheInfo->ListHead = Next; 286 CacheInfo->CacheDepth--; 287 } 288} 289 290 291#ifdef ACPI_DBG_TRACK_ALLOCATIONS 292 293 294/* 295 * These procedures are used for tracking memory leaks in the subsystem, and 296 * they get compiled out when the ACPI_DBG_TRACK_ALLOCATIONS is not set. 297 * 298 * Each memory allocation is tracked via a doubly linked list. Each 299 * element contains the caller's component, module name, function name, and 300 * line number. AcpiUtAllocate and AcpiUtCallocate call 301 * AcpiUtTrackAllocation to add an element to the list; deletion 302 * occurs in the body of AcpiUtFree. 303 */ 304 305 306/******************************************************************************* 307 * 308 * FUNCTION: AcpiUtFindAllocation 309 * 310 * PARAMETERS: Address - Address of allocated memory 311 * 312 * RETURN: A list element if found; NULL otherwise. 313 * 314 * DESCRIPTION: Searches for an element in the global allocation tracking list. 315 * 316 ******************************************************************************/ 317 318ACPI_DEBUG_MEM_BLOCK * 319AcpiUtFindAllocation ( 320 UINT32 ListId, 321 void *Address) 322{ 323 ACPI_DEBUG_MEM_BLOCK *Element; 324 325 326 FUNCTION_ENTRY (); 327 328 329 if (ListId > ACPI_MEM_LIST_MAX) 330 { 331 return (NULL); 332 } 333 334 Element = AcpiGbl_MemoryLists[ListId].ListHead; 335 336 /* Search for the address. */ 337 338 while (Element) 339 { 340 if (Element == Address) 341 { 342 return (Element); 343 } 344 345 Element = Element->Next; 346 } 347 348 return (NULL); 349} 350 351 352/******************************************************************************* 353 * 354 * FUNCTION: AcpiUtTrackAllocation 355 * 356 * PARAMETERS: Address - Address of allocated memory 357 * Size - Size of the allocation 358 * AllocType - MEM_MALLOC or MEM_CALLOC 359 * Component - Component type of caller 360 * Module - Source file name of caller 361 * Line - Line number of caller 362 * 363 * RETURN: None. 364 * 365 * DESCRIPTION: Inserts an element into the global allocation tracking list. 366 * 367 ******************************************************************************/ 368 369ACPI_STATUS 370AcpiUtTrackAllocation ( 371 UINT32 ListId, 372 ACPI_DEBUG_MEM_BLOCK *Address, 373 UINT32 Size, 374 UINT8 AllocType, 375 UINT32 Component, 376 NATIVE_CHAR *Module, 377 UINT32 Line) 378{ 379 ACPI_MEMORY_LIST *MemList; 380 ACPI_DEBUG_MEM_BLOCK *Element; 381 ACPI_STATUS Status = AE_OK; 382 383 384 FUNCTION_TRACE_PTR ("UtTrackAllocation", Address); 385 386 387 if (ListId > ACPI_MEM_LIST_MAX) 388 { 389 return_ACPI_STATUS (AE_BAD_PARAMETER); 390 } 391 392 MemList = &AcpiGbl_MemoryLists[ListId]; 393 AcpiUtAcquireMutex (ACPI_MTX_MEMORY); 394 395 /* 396 * Search list for this address to make sure it is not already on the list. 397 * This will catch several kinds of problems. 398 */ 399 400 Element = AcpiUtFindAllocation (ListId, Address); 401 if (Element) 402 { 403 REPORT_ERROR (("UtTrackAllocation: Address already present in list! (%p)\n", 404 Address)); 405 406 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Element %p Address %p\n", Element, Address)); 407 408 goto UnlockAndExit; 409 } 410 411 /* Fill in the instance data. */ 412 413 Address->Size = Size; 414 Address->AllocType = AllocType; 415 Address->Component = Component; 416 Address->Line = Line; 417 418 STRNCPY (Address->Module, Module, MAX_MODULE_NAME); 419 420 /* Insert at list head */ 421 422 if (MemList->ListHead) 423 { 424 ((ACPI_DEBUG_MEM_BLOCK *)(MemList->ListHead))->Previous = Address; 425 } 426 427 Address->Next = MemList->ListHead; 428 Address->Previous = NULL; 429 430 MemList->ListHead = Address; 431 432 433UnlockAndExit: 434 AcpiUtReleaseMutex (ACPI_MTX_MEMORY); 435 return_ACPI_STATUS (Status); 436} 437 438 439/******************************************************************************* 440 * 441 * FUNCTION: AcpiUtRemoveAllocation 442 * 443 * PARAMETERS: Address - Address of allocated memory 444 * Component - Component type of caller 445 * Module - Source file name of caller 446 * Line - Line number of caller 447 * 448 * RETURN: 449 * 450 * DESCRIPTION: Deletes an element from the global allocation tracking list. 451 * 452 ******************************************************************************/ 453 454ACPI_STATUS 455AcpiUtRemoveAllocation ( 456 UINT32 ListId, 457 ACPI_DEBUG_MEM_BLOCK *Address, 458 UINT32 Component, 459 NATIVE_CHAR *Module, 460 UINT32 Line) 461{ 462 ACPI_MEMORY_LIST *MemList; 463 464 465 FUNCTION_TRACE ("UtRemoveAllocation"); 466 467 468 if (ListId > ACPI_MEM_LIST_MAX) 469 { 470 return_ACPI_STATUS (AE_BAD_PARAMETER); 471 } 472 473 MemList = &AcpiGbl_MemoryLists[ListId]; 474 if (NULL == MemList->ListHead) 475 { 476 /* No allocations! */ 477 478 _REPORT_ERROR (Module, Line, Component, 479 ("UtRemoveAllocation: Empty allocation list, nothing to free!\n")); 480 481 return_ACPI_STATUS (AE_OK); 482 } 483 484 485 AcpiUtAcquireMutex (ACPI_MTX_MEMORY); 486 487 /* Unlink */ 488 489 if (Address->Previous) 490 { 491 (Address->Previous)->Next = Address->Next; 492 } 493 else 494 { 495 MemList->ListHead = Address->Next; 496 } 497 498 if (Address->Next) 499 { 500 (Address->Next)->Previous = Address->Previous; 501 } 502 503 504 /* Mark the segment as deleted */ 505 506 MEMSET (&Address->UserSpace, 0xEA, Address->Size); 507 508 ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS, "Freeing size %X\n", Address->Size)); 509 510 AcpiUtReleaseMutex (ACPI_MTX_MEMORY); 511 return_ACPI_STATUS (AE_OK); 512} 513 514 515/******************************************************************************* 516 * 517 * FUNCTION: AcpiUtDumpAllocationInfo 518 * 519 * PARAMETERS: 520 * 521 * RETURN: None 522 * 523 * DESCRIPTION: Print some info about the outstanding allocations. 524 * 525 ******************************************************************************/ 526 527void 528AcpiUtDumpAllocationInfo ( 529 void) 530{ 531/* 532 ACPI_MEMORY_LIST *MemList; 533*/ 534 535 FUNCTION_TRACE ("UtDumpAllocationInfo"); 536 537/* 538 ACPI_DEBUG_PRINT (TRACE_ALLOCATIONS | TRACE_TABLES, 539 ("%30s: %4d (%3d Kb)\n", "Current allocations", 540 MemList->CurrentCount, 541 ROUND_UP_TO_1K (MemList->CurrentSize))); 542 543 ACPI_DEBUG_PRINT (TRACE_ALLOCATIONS | TRACE_TABLES, 544 ("%30s: %4d (%3d Kb)\n", "Max concurrent allocations", 545 MemList->MaxConcurrentCount, 546 ROUND_UP_TO_1K (MemList->MaxConcurrentSize))); 547 548 549 ACPI_DEBUG_PRINT (TRACE_ALLOCATIONS | TRACE_TABLES, 550 ("%30s: %4d (%3d Kb)\n", "Total (all) internal objects", 551 RunningObjectCount, 552 ROUND_UP_TO_1K (RunningObjectSize))); 553 554 ACPI_DEBUG_PRINT (TRACE_ALLOCATIONS | TRACE_TABLES, 555 ("%30s: %4d (%3d Kb)\n", "Total (all) allocations", 556 RunningAllocCount, 557 ROUND_UP_TO_1K (RunningAllocSize))); 558 559 560 ACPI_DEBUG_PRINT (TRACE_ALLOCATIONS | TRACE_TABLES, 561 ("%30s: %4d (%3d Kb)\n", "Current Nodes", 562 AcpiGbl_CurrentNodeCount, 563 ROUND_UP_TO_1K (AcpiGbl_CurrentNodeSize))); 564 565 ACPI_DEBUG_PRINT (TRACE_ALLOCATIONS | TRACE_TABLES, 566 ("%30s: %4d (%3d Kb)\n", "Max Nodes", 567 AcpiGbl_MaxConcurrentNodeCount, 568 ROUND_UP_TO_1K ((AcpiGbl_MaxConcurrentNodeCount * sizeof (ACPI_NAMESPACE_NODE))))); 569*/ 570 return_VOID; 571} 572 573 574/******************************************************************************* 575 * 576 * FUNCTION: AcpiUtDumpAllocations 577 * 578 * PARAMETERS: Component - Component(s) to dump info for. 579 * Module - Module to dump info for. NULL means all. 580 * 581 * RETURN: None 582 * 583 * DESCRIPTION: Print a list of all outstanding allocations. 584 * 585 ******************************************************************************/ 586 587void 588AcpiUtDumpAllocations ( 589 UINT32 Component, 590 NATIVE_CHAR *Module) 591{ 592 ACPI_DEBUG_MEM_BLOCK *Element; 593 UINT32 i; 594 595 596 FUNCTION_TRACE ("UtDumpAllocations"); 597 598 599 Element = AcpiGbl_MemoryLists[0].ListHead; 600 if (Element == NULL) 601 { 602 ACPI_DEBUG_PRINT ((ACPI_DB_OK, 603 "No outstanding allocations.\n")); 604 return_VOID; 605 } 606 607 608 /* 609 * Walk the allocation list. 610 */ 611 AcpiUtAcquireMutex (ACPI_MTX_MEMORY); 612 613 ACPI_DEBUG_PRINT ((ACPI_DB_OK, 614 "Outstanding allocations:\n")); 615 616 for (i = 1; ; i++) /* Just a counter */ 617 { 618 if ((Element->Component & Component) && 619 ((Module == NULL) || (0 == STRCMP (Module, Element->Module)))) 620 { 621 if (((ACPI_OPERAND_OBJECT *)(&Element->UserSpace))->Common.Type != ACPI_CACHED_OBJECT) 622 { 623 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_OK, 624 "%p Len %04X %9.9s-%d", 625 &Element->UserSpace, Element->Size, Element->Module, 626 Element->Line)); 627 628 /* Most of the elements will be internal objects. */ 629 630 switch (((ACPI_OPERAND_OBJECT *) 631 (&Element->UserSpace))->Common.DataType) 632 { 633 case ACPI_DESC_TYPE_INTERNAL: 634 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_OK, 635 " ObjType %12.12s R%d", 636 AcpiUtGetTypeName (((ACPI_OPERAND_OBJECT *)(&Element->UserSpace))->Common.Type), 637 ((ACPI_OPERAND_OBJECT *)(&Element->UserSpace))->Common.ReferenceCount)); 638 break; 639 640 case ACPI_DESC_TYPE_PARSER: 641 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_OK, 642 " ParseObj Opcode %04X", 643 ((ACPI_PARSE_OBJECT *)(&Element->UserSpace))->Opcode)); 644 break; 645 646 case ACPI_DESC_TYPE_NAMED: 647 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_OK, 648 " Node %4.4s", 649 (char*)&((ACPI_NAMESPACE_NODE *)(&Element->UserSpace))->Name)); 650 break; 651 652 case ACPI_DESC_TYPE_STATE: 653 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_OK, 654 " Untyped StateObj")); 655 break; 656 657 case ACPI_DESC_TYPE_STATE_UPDATE: 658 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_OK, 659 " UPDATE StateObj")); 660 break; 661 662 case ACPI_DESC_TYPE_STATE_PACKAGE: 663 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_OK, 664 " PACKAGE StateObj")); 665 break; 666 667 case ACPI_DESC_TYPE_STATE_CONTROL: 668 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_OK, 669 " CONTROL StateObj")); 670 break; 671 672 case ACPI_DESC_TYPE_STATE_RPSCOPE: 673 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_OK, 674 " ROOT-PARSE-SCOPE StateObj")); 675 break; 676 677 case ACPI_DESC_TYPE_STATE_PSCOPE: 678 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_OK, 679 " PARSE-SCOPE StateObj")); 680 break; 681 682 case ACPI_DESC_TYPE_STATE_WSCOPE: 683 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_OK, 684 " WALK-SCOPE StateObj")); 685 break; 686 687 case ACPI_DESC_TYPE_STATE_RESULT: 688 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_OK, 689 " RESULT StateObj")); 690 break; 691 692 case ACPI_DESC_TYPE_STATE_NOTIFY: 693 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_OK, 694 " NOTIFY StateObj")); 695 break; 696 } 697 698 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_OK, "\n")); 699 } 700 } 701 702 if (Element->Next == NULL) 703 { 704 break; 705 } 706 707 Element = Element->Next; 708 } 709 710 AcpiUtReleaseMutex (ACPI_MTX_MEMORY); 711 712 ACPI_DEBUG_PRINT ((ACPI_DB_OK, 713 "Total number of unfreed allocations = %d(%X)\n", i,i)); 714 715 716 return_VOID; 717 718} 719 720 721/******************************************************************************* 722 * 723 * FUNCTION: AcpiUtAllocate 724 * 725 * PARAMETERS: Size - Size of the allocation 726 * Component - Component type of caller 727 * Module - Source file name of caller 728 * Line - Line number of caller 729 * 730 * RETURN: Address of the allocated memory on success, NULL on failure. 731 * 732 * DESCRIPTION: The subsystem's equivalent of malloc. 733 * 734 ******************************************************************************/ 735 736void * 737AcpiUtAllocate ( 738 UINT32 Size, 739 UINT32 Component, 740 NATIVE_CHAR *Module, 741 UINT32 Line) 742{ 743 ACPI_DEBUG_MEM_BLOCK *Address; 744 ACPI_STATUS Status; 745 746 747 FUNCTION_TRACE_U32 ("UtAllocate", Size); 748 749 750 /* Check for an inadvertent size of zero bytes */ 751 752 if (!Size) 753 { 754 _REPORT_ERROR (Module, Line, Component, 755 ("UtAllocate: Attempt to allocate zero bytes\n")); 756 Size = 1; 757 } 758 759 Address = AcpiOsAllocate (Size + sizeof (ACPI_DEBUG_MEM_BLOCK)); 760 if (!Address) 761 { 762 /* Report allocation error */ 763 764 _REPORT_ERROR (Module, Line, Component, 765 ("UtAllocate: Could not allocate size %X\n", Size)); 766 767 return_PTR (NULL); 768 } 769 770 Status = AcpiUtTrackAllocation (ACPI_MEM_LIST_GLOBAL, Address, Size, 771 MEM_MALLOC, Component, Module, Line); 772 if (ACPI_FAILURE (Status)) 773 { 774 AcpiOsFree (Address); 775 return_PTR (NULL); 776 } 777 778 AcpiGbl_MemoryLists[ACPI_MEM_LIST_GLOBAL].TotalAllocated++; 779 AcpiGbl_MemoryLists[ACPI_MEM_LIST_GLOBAL].CurrentTotalSize += Size; 780 781 ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS, "%p Size %X\n", Address, Size)); 782 783 return_PTR ((void *) &Address->UserSpace); 784} 785 786 787/******************************************************************************* 788 * 789 * FUNCTION: AcpiUtCallocate 790 * 791 * PARAMETERS: Size - Size of the allocation 792 * Component - Component type of caller 793 * Module - Source file name of caller 794 * Line - Line number of caller 795 * 796 * RETURN: Address of the allocated memory on success, NULL on failure. 797 * 798 * DESCRIPTION: Subsystem equivalent of calloc. 799 * 800 ******************************************************************************/ 801 802void * 803AcpiUtCallocate ( 804 UINT32 Size, 805 UINT32 Component, 806 NATIVE_CHAR *Module, 807 UINT32 Line) 808{ 809 ACPI_DEBUG_MEM_BLOCK *Address; 810 ACPI_STATUS Status; 811 812 813 FUNCTION_TRACE_U32 ("UtCallocate", Size); 814 815 816 /* Check for an inadvertent size of zero bytes */ 817 818 if (!Size) 819 { 820 _REPORT_ERROR (Module, Line, Component, 821 ("UtCallocate: Attempt to allocate zero bytes\n")); 822 return_PTR (NULL); 823 } 824 825 826 Address = AcpiOsCallocate (Size + sizeof (ACPI_DEBUG_MEM_BLOCK)); 827 if (!Address) 828 { 829 /* Report allocation error */ 830 831 _REPORT_ERROR (Module, Line, Component, 832 ("UtCallocate: Could not allocate size %X\n", Size)); 833 return_PTR (NULL); 834 } 835 836 Status = AcpiUtTrackAllocation (ACPI_MEM_LIST_GLOBAL, Address, Size, 837 MEM_CALLOC, Component, Module, Line); 838 if (ACPI_FAILURE (Status)) 839 { 840 AcpiOsFree (Address); 841 return_PTR (NULL); 842 } 843 844 AcpiGbl_MemoryLists[ACPI_MEM_LIST_GLOBAL].TotalAllocated++; 845 AcpiGbl_MemoryLists[ACPI_MEM_LIST_GLOBAL].CurrentTotalSize += Size; 846 847 ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS, "%p Size %X\n", Address, Size)); 848 return_PTR ((void *) &Address->UserSpace); 849} 850 851 852/******************************************************************************* 853 * 854 * FUNCTION: AcpiUtFree 855 * 856 * PARAMETERS: Address - Address of the memory to deallocate 857 * Component - Component type of caller 858 * Module - Source file name of caller 859 * Line - Line number of caller 860 * 861 * RETURN: None 862 * 863 * DESCRIPTION: Frees the memory at Address 864 * 865 ******************************************************************************/ 866 867void 868AcpiUtFree ( 869 void *Address, 870 UINT32 Component, 871 NATIVE_CHAR *Module, 872 UINT32 Line) 873{ 874 ACPI_DEBUG_MEM_BLOCK *DebugBlock; 875 876 877 FUNCTION_TRACE_PTR ("UtFree", Address); 878 879 880 if (NULL == Address) 881 { 882 _REPORT_ERROR (Module, Line, Component, 883 ("AcpiUtFree: Trying to delete a NULL address\n")); 884 885 return_VOID; 886 } 887 888 DebugBlock = (ACPI_DEBUG_MEM_BLOCK *) 889 (((char *) Address) - sizeof (ACPI_DEBUG_MEM_HEADER)); 890 891 AcpiGbl_MemoryLists[ACPI_MEM_LIST_GLOBAL].TotalFreed++; 892 AcpiGbl_MemoryLists[ACPI_MEM_LIST_GLOBAL].CurrentTotalSize -= DebugBlock->Size; 893 894 AcpiUtRemoveAllocation (ACPI_MEM_LIST_GLOBAL, DebugBlock, 895 Component, Module, Line); 896 AcpiOsFree (DebugBlock); 897 898 ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS, "%p freed\n", Address)); 899 900 return_VOID; 901} 902 903#endif /* #ifdef ACPI_DBG_TRACK_ALLOCATIONS */ 904 905