utalloc.c (91116) | utalloc.c (99679) |
---|---|
1/****************************************************************************** 2 * 3 * Module Name: utalloc - local cache and memory allocation routines | 1/****************************************************************************** 2 * 3 * Module Name: utalloc - local cache and memory allocation routines |
4 * $Revision: 121 $ | 4 * $Revision: 127 $ |
5 * 6 *****************************************************************************/ 7 8/****************************************************************************** 9 * 10 * 1. Copyright Notice 11 * 12 * Some or all of this work - Copyright (c) 1999 - 2002, Intel Corp. --- 99 unchanged lines hidden (view full) --- 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" | 5 * 6 *****************************************************************************/ 7 8/****************************************************************************** 9 * 10 * 1. Copyright Notice 11 * 12 * Some or all of this work - Copyright (c) 1999 - 2002, Intel Corp. --- 99 unchanged lines hidden (view full) --- 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 ACPI_MODULE_NAME ("utalloc") 127 128 129/****************************************************************************** 130 * 131 * FUNCTION: AcpiUtReleaseToCache --- 35 unchanged lines hidden (view full) --- 167 if (ACPI_FAILURE (AcpiUtAcquireMutex (ACPI_MTX_CACHES))) 168 { 169 return; 170 } 171 172 /* Mark the object as cached */ 173 174 ACPI_MEMSET (Object, 0xCA, CacheInfo->ObjectSize); | 120 121#define _COMPONENT ACPI_UTILITIES 122 ACPI_MODULE_NAME ("utalloc") 123 124 125/****************************************************************************** 126 * 127 * FUNCTION: AcpiUtReleaseToCache --- 35 unchanged lines hidden (view full) --- 163 if (ACPI_FAILURE (AcpiUtAcquireMutex (ACPI_MTX_CACHES))) 164 { 165 return; 166 } 167 168 /* Mark the object as cached */ 169 170 ACPI_MEMSET (Object, 0xCA, CacheInfo->ObjectSize); |
175 ACPI_SET_DESCRIPTOR_TYPE (Object, ACPI_CACHED_OBJECT); | 171 ACPI_SET_DESCRIPTOR_TYPE (Object, ACPI_DESC_TYPE_CACHED); |
176 177 /* Put the object at the head of the cache list */ 178 | 172 173 /* Put the object at the head of the cache list */ 174 |
179 * (char **) (((char *) Object) + CacheInfo->LinkOffset) = CacheInfo->ListHead; | 175 * (ACPI_CAST_INDIRECT_PTR (char, &(((char *) Object)[CacheInfo->LinkOffset]))) = CacheInfo->ListHead; |
180 CacheInfo->ListHead = Object; 181 CacheInfo->CacheDepth++; 182 183 (void) AcpiUtReleaseMutex (ACPI_MTX_CACHES); 184 } 185} 186 187 --- 32 unchanged lines hidden (view full) --- 220 221 /* Check the cache first */ 222 223 if (CacheInfo->ListHead) 224 { 225 /* There is an object available, use it */ 226 227 Object = CacheInfo->ListHead; | 176 CacheInfo->ListHead = Object; 177 CacheInfo->CacheDepth++; 178 179 (void) AcpiUtReleaseMutex (ACPI_MTX_CACHES); 180 } 181} 182 183 --- 32 unchanged lines hidden (view full) --- 216 217 /* Check the cache first */ 218 219 if (CacheInfo->ListHead) 220 { 221 /* There is an object available, use it */ 222 223 Object = CacheInfo->ListHead; |
228 CacheInfo->ListHead = * (char **) (((char *) Object) + CacheInfo->LinkOffset); | 224 CacheInfo->ListHead = *(ACPI_CAST_INDIRECT_PTR (char, &(((char *) Object)[CacheInfo->LinkOffset]))); |
229 230 ACPI_MEM_TRACKING (CacheInfo->CacheHits++); 231 CacheInfo->CacheDepth--; 232 233#ifdef ACPI_DBG_TRACK_ALLOCATIONS 234 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Object %p from %s\n", 235 Object, AcpiGbl_MemoryLists[ListId].ListName)); 236#endif --- 50 unchanged lines hidden (view full) --- 287 ACPI_FUNCTION_ENTRY (); 288 289 290 CacheInfo = &AcpiGbl_MemoryLists[ListId]; 291 while (CacheInfo->ListHead) 292 { 293 /* Delete one cached state object */ 294 | 225 226 ACPI_MEM_TRACKING (CacheInfo->CacheHits++); 227 CacheInfo->CacheDepth--; 228 229#ifdef ACPI_DBG_TRACK_ALLOCATIONS 230 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Object %p from %s\n", 231 Object, AcpiGbl_MemoryLists[ListId].ListName)); 232#endif --- 50 unchanged lines hidden (view full) --- 283 ACPI_FUNCTION_ENTRY (); 284 285 286 CacheInfo = &AcpiGbl_MemoryLists[ListId]; 287 while (CacheInfo->ListHead) 288 { 289 /* Delete one cached state object */ 290 |
295 Next = * (char **) (((char *) CacheInfo->ListHead) + CacheInfo->LinkOffset); | 291 Next = *(ACPI_CAST_INDIRECT_PTR (char, &(((char *) CacheInfo->ListHead)[CacheInfo->LinkOffset]))); |
296 ACPI_MEM_FREE (CacheInfo->ListHead); 297 298 CacheInfo->ListHead = Next; 299 CacheInfo->CacheDepth--; 300 } 301} 302 303 --- 163 unchanged lines hidden (view full) --- 467 } 468 469 Allocation = AcpiOsAllocate (Size); 470 if (!Allocation) 471 { 472 /* Report allocation error */ 473 474 _ACPI_REPORT_ERROR (Module, Line, Component, | 292 ACPI_MEM_FREE (CacheInfo->ListHead); 293 294 CacheInfo->ListHead = Next; 295 CacheInfo->CacheDepth--; 296 } 297} 298 299 --- 163 unchanged lines hidden (view full) --- 463 } 464 465 Allocation = AcpiOsAllocate (Size); 466 if (!Allocation) 467 { 468 /* Report allocation error */ 469 470 _ACPI_REPORT_ERROR (Module, Line, Component, |
475 ("UtAllocate: Could not allocate size %X\n", Size)); | 471 ("UtAllocate: Could not allocate size %X\n", (UINT32) Size)); |
476 477 return_PTR (NULL); 478 } 479 480 return_PTR (Allocation); 481} 482 483 --- 35 unchanged lines hidden (view full) --- 519 } 520 521 Allocation = AcpiOsAllocate (Size); 522 if (!Allocation) 523 { 524 /* Report allocation error */ 525 526 _ACPI_REPORT_ERROR (Module, Line, Component, | 472 473 return_PTR (NULL); 474 } 475 476 return_PTR (Allocation); 477} 478 479 --- 35 unchanged lines hidden (view full) --- 515 } 516 517 Allocation = AcpiOsAllocate (Size); 518 if (!Allocation) 519 { 520 /* Report allocation error */ 521 522 _ACPI_REPORT_ERROR (Module, Line, Component, |
527 ("UtCallocate: Could not allocate size %X\n", Size)); | 523 ("UtCallocate: Could not allocate size %X\n", (UINT32) Size)); |
528 return_PTR (NULL); 529 } 530 531 /* Clear the memory block */ 532 533 ACPI_MEMSET (Allocation, 0, Size); 534 return_PTR (Allocation); 535} --- 88 unchanged lines hidden (view full) --- 624 625 Allocation = AcpiUtCallocate (Size + sizeof (ACPI_DEBUG_MEM_BLOCK), Component, 626 Module, Line); 627 if (!Allocation) 628 { 629 /* Report allocation error */ 630 631 _ACPI_REPORT_ERROR (Module, Line, Component, | 524 return_PTR (NULL); 525 } 526 527 /* Clear the memory block */ 528 529 ACPI_MEMSET (Allocation, 0, Size); 530 return_PTR (Allocation); 531} --- 88 unchanged lines hidden (view full) --- 620 621 Allocation = AcpiUtCallocate (Size + sizeof (ACPI_DEBUG_MEM_BLOCK), Component, 622 Module, Line); 623 if (!Allocation) 624 { 625 /* Report allocation error */ 626 627 _ACPI_REPORT_ERROR (Module, Line, Component, |
632 ("UtCallocate: Could not allocate size %X\n", Size)); | 628 ("UtCallocate: Could not allocate size %X\n", (UINT32) Size)); |
633 return (NULL); 634 } 635 636 Status = AcpiUtTrackAllocation (ACPI_MEM_LIST_GLOBAL, Allocation, Size, 637 ACPI_MEM_CALLOC, Component, Module, Line); 638 if (ACPI_FAILURE (Status)) 639 { 640 AcpiOsFree (Allocation); --- 25 unchanged lines hidden (view full) --- 666void 667AcpiUtFreeAndTrack ( 668 void *Allocation, 669 UINT32 Component, 670 NATIVE_CHAR *Module, 671 UINT32 Line) 672{ 673 ACPI_DEBUG_MEM_BLOCK *DebugBlock; | 629 return (NULL); 630 } 631 632 Status = AcpiUtTrackAllocation (ACPI_MEM_LIST_GLOBAL, Allocation, Size, 633 ACPI_MEM_CALLOC, Component, Module, Line); 634 if (ACPI_FAILURE (Status)) 635 { 636 AcpiOsFree (Allocation); --- 25 unchanged lines hidden (view full) --- 662void 663AcpiUtFreeAndTrack ( 664 void *Allocation, 665 UINT32 Component, 666 NATIVE_CHAR *Module, 667 UINT32 Line) 668{ 669 ACPI_DEBUG_MEM_BLOCK *DebugBlock; |
670 ACPI_STATUS Status; |
|
674 675 676 ACPI_FUNCTION_TRACE_PTR ("UtFree", Allocation); 677 678 679 if (NULL == Allocation) 680 { 681 _ACPI_REPORT_ERROR (Module, Line, Component, 682 ("AcpiUtFree: Attempt to delete a NULL address\n")); 683 684 return_VOID; 685 } 686 | 671 672 673 ACPI_FUNCTION_TRACE_PTR ("UtFree", Allocation); 674 675 676 if (NULL == Allocation) 677 { 678 _ACPI_REPORT_ERROR (Module, Line, Component, 679 ("AcpiUtFree: Attempt to delete a NULL address\n")); 680 681 return_VOID; 682 } 683 |
687 DebugBlock = (ACPI_DEBUG_MEM_BLOCK *) 688 (((char *) Allocation) - sizeof (ACPI_DEBUG_MEM_HEADER)); | 684 DebugBlock = ACPI_CAST_PTR (ACPI_DEBUG_MEM_BLOCK, 685 (((char *) Allocation) - sizeof (ACPI_DEBUG_MEM_HEADER))); |
689 690 AcpiGbl_MemoryLists[ACPI_MEM_LIST_GLOBAL].TotalFreed++; 691 AcpiGbl_MemoryLists[ACPI_MEM_LIST_GLOBAL].CurrentTotalSize -= DebugBlock->Size; 692 | 686 687 AcpiGbl_MemoryLists[ACPI_MEM_LIST_GLOBAL].TotalFreed++; 688 AcpiGbl_MemoryLists[ACPI_MEM_LIST_GLOBAL].CurrentTotalSize -= DebugBlock->Size; 689 |
693 AcpiUtRemoveAllocation (ACPI_MEM_LIST_GLOBAL, DebugBlock, 694 Component, Module, Line); | 690 Status = AcpiUtRemoveAllocation (ACPI_MEM_LIST_GLOBAL, DebugBlock, 691 Component, Module, Line); 692 if (ACPI_FAILURE (Status)) 693 { 694 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Could not free memory, %s\n", 695 AcpiFormatException (Status))); 696 } 697 |
695 AcpiOsFree (DebugBlock); 696 697 ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS, "%p freed\n", Allocation)); 698 699 return_VOID; 700} 701 702 --- 286 unchanged lines hidden (view full) --- 989 ******************************************************************************/ 990 991void 992AcpiUtDumpAllocations ( 993 UINT32 Component, 994 NATIVE_CHAR *Module) 995{ 996 ACPI_DEBUG_MEM_BLOCK *Element; | 698 AcpiOsFree (DebugBlock); 699 700 ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS, "%p freed\n", Allocation)); 701 702 return_VOID; 703} 704 705 --- 286 unchanged lines hidden (view full) --- 992 ******************************************************************************/ 993 994void 995AcpiUtDumpAllocations ( 996 UINT32 Component, 997 NATIVE_CHAR *Module) 998{ 999 ACPI_DEBUG_MEM_BLOCK *Element; |
1000 ACPI_DESCRIPTOR *Descriptor; |
|
997 UINT32 NumOutstanding = 0; 998 999 1000 ACPI_FUNCTION_TRACE ("UtDumpAllocations"); 1001 1002 1003 /* 1004 * Walk the allocation list. --- 6 unchanged lines hidden (view full) --- 1011 Element = AcpiGbl_MemoryLists[0].ListHead; 1012 while (Element) 1013 { 1014 if ((Element->Component & Component) && 1015 ((Module == NULL) || (0 == ACPI_STRCMP (Module, Element->Module)))) 1016 { 1017 /* Ignore allocated objects that are in a cache */ 1018 | 1001 UINT32 NumOutstanding = 0; 1002 1003 1004 ACPI_FUNCTION_TRACE ("UtDumpAllocations"); 1005 1006 1007 /* 1008 * Walk the allocation list. --- 6 unchanged lines hidden (view full) --- 1015 Element = AcpiGbl_MemoryLists[0].ListHead; 1016 while (Element) 1017 { 1018 if ((Element->Component & Component) && 1019 ((Module == NULL) || (0 == ACPI_STRCMP (Module, Element->Module)))) 1020 { 1021 /* Ignore allocated objects that are in a cache */ 1022 |
1019 if (((ACPI_OPERAND_OBJECT *)(&Element->UserSpace))->Common.Type != ACPI_CACHED_OBJECT) | 1023 Descriptor = ACPI_CAST_PTR (ACPI_DESCRIPTOR, &Element->UserSpace); 1024 if (Descriptor->DescriptorId != ACPI_DESC_TYPE_CACHED) |
1020 { 1021 AcpiOsPrintf ("%p Len %04X %9.9s-%d ", | 1025 { 1026 AcpiOsPrintf ("%p Len %04X %9.9s-%d ", |
1022 &Element->UserSpace, Element->Size, Element->Module, | 1027 Descriptor, Element->Size, Element->Module, |
1023 Element->Line); 1024 1025 /* Most of the elements will be internal objects. */ 1026 | 1028 Element->Line); 1029 1030 /* Most of the elements will be internal objects. */ 1031 |
1027 switch (ACPI_GET_DESCRIPTOR_TYPE (&Element->UserSpace)) | 1032 switch (ACPI_GET_DESCRIPTOR_TYPE (Descriptor)) |
1028 { | 1033 { |
1029 case ACPI_DESC_TYPE_INTERNAL: 1030 AcpiOsPrintf ("ObjType %12.12s R%d", 1031 AcpiUtGetTypeName (((ACPI_OPERAND_OBJECT *)(&Element->UserSpace))->Common.Type), 1032 ((ACPI_OPERAND_OBJECT *)(&Element->UserSpace))->Common.ReferenceCount); | 1034 case ACPI_DESC_TYPE_OPERAND: 1035 AcpiOsPrintf ("ObjType %12.12s R%hd", 1036 AcpiUtGetTypeName (Descriptor->Object.Common.Type), 1037 Descriptor->Object.Common.ReferenceCount); |
1033 break; 1034 1035 case ACPI_DESC_TYPE_PARSER: | 1038 break; 1039 1040 case ACPI_DESC_TYPE_PARSER: |
1036 AcpiOsPrintf ("ParseObj Opcode %04X", 1037 ((ACPI_PARSE_OBJECT *)(&Element->UserSpace))->Opcode); | 1041 AcpiOsPrintf ("ParseObj AmlOpcode %04hX", 1042 Descriptor->Op.Asl.AmlOpcode); |
1038 break; 1039 1040 case ACPI_DESC_TYPE_NAMED: 1041 AcpiOsPrintf ("Node %4.4s", | 1043 break; 1044 1045 case ACPI_DESC_TYPE_NAMED: 1046 AcpiOsPrintf ("Node %4.4s", |
1042 (char *) &((ACPI_NAMESPACE_NODE *)(&Element->UserSpace))->Name); | 1047 Descriptor->Node.Name.Ascii); |
1043 break; 1044 1045 case ACPI_DESC_TYPE_STATE: 1046 AcpiOsPrintf ("Untyped StateObj"); 1047 break; 1048 1049 case ACPI_DESC_TYPE_STATE_UPDATE: 1050 AcpiOsPrintf ("UPDATE StateObj"); --- 25 unchanged lines hidden (view full) --- 1076 1077 case ACPI_DESC_TYPE_STATE_NOTIFY: 1078 AcpiOsPrintf ("NOTIFY StateObj"); 1079 break; 1080 1081 case ACPI_DESC_TYPE_STATE_THREAD: 1082 AcpiOsPrintf ("THREAD StateObj"); 1083 break; | 1048 break; 1049 1050 case ACPI_DESC_TYPE_STATE: 1051 AcpiOsPrintf ("Untyped StateObj"); 1052 break; 1053 1054 case ACPI_DESC_TYPE_STATE_UPDATE: 1055 AcpiOsPrintf ("UPDATE StateObj"); --- 25 unchanged lines hidden (view full) --- 1081 1082 case ACPI_DESC_TYPE_STATE_NOTIFY: 1083 AcpiOsPrintf ("NOTIFY StateObj"); 1084 break; 1085 1086 case ACPI_DESC_TYPE_STATE_THREAD: 1087 AcpiOsPrintf ("THREAD StateObj"); 1088 break; |
1089 1090 default: 1091 /* All types should appear above */ 1092 break; |
|
1084 } 1085 1086 AcpiOsPrintf ( "\n"); 1087 NumOutstanding++; 1088 } 1089 } 1090 Element = Element->Next; 1091 } 1092 1093 (void) AcpiUtReleaseMutex (ACPI_MTX_MEMORY); 1094 1095 /* Print summary */ 1096 1097 if (!NumOutstanding) 1098 { 1099 ACPI_DEBUG_PRINT ((ACPI_DB_OK, | 1093 } 1094 1095 AcpiOsPrintf ( "\n"); 1096 NumOutstanding++; 1097 } 1098 } 1099 Element = Element->Next; 1100 } 1101 1102 (void) AcpiUtReleaseMutex (ACPI_MTX_MEMORY); 1103 1104 /* Print summary */ 1105 1106 if (!NumOutstanding) 1107 { 1108 ACPI_DEBUG_PRINT ((ACPI_DB_OK, |
1100 "No outstanding allocations.\n")); | 1109 "No outstanding allocations.\n")); |
1101 } 1102 else 1103 { 1104 ACPI_DEBUG_PRINT ((ACPI_DB_OK, 1105 "%d(%X) Outstanding allocations\n", 1106 NumOutstanding, NumOutstanding)); 1107 } 1108 1109 return_VOID; 1110} 1111 1112 1113#endif /* #ifdef ACPI_DBG_TRACK_ALLOCATIONS */ 1114 | 1110 } 1111 else 1112 { 1113 ACPI_DEBUG_PRINT ((ACPI_DB_OK, 1114 "%d(%X) Outstanding allocations\n", 1115 NumOutstanding, NumOutstanding)); 1116 } 1117 1118 return_VOID; 1119} 1120 1121 1122#endif /* #ifdef ACPI_DBG_TRACK_ALLOCATIONS */ 1123 |