uttrack.c revision 1.10 1 1.1 jruoho /******************************************************************************
2 1.1 jruoho *
3 1.1 jruoho * Module Name: uttrack - Memory allocation tracking routines (debug only)
4 1.1 jruoho *
5 1.1 jruoho *****************************************************************************/
6 1.1 jruoho
7 1.3 jruoho /*
8 1.8 christos * Copyright (C) 2000 - 2016, Intel Corp.
9 1.1 jruoho * All rights reserved.
10 1.1 jruoho *
11 1.3 jruoho * Redistribution and use in source and binary forms, with or without
12 1.3 jruoho * modification, are permitted provided that the following conditions
13 1.3 jruoho * are met:
14 1.3 jruoho * 1. Redistributions of source code must retain the above copyright
15 1.3 jruoho * notice, this list of conditions, and the following disclaimer,
16 1.3 jruoho * without modification.
17 1.3 jruoho * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 1.3 jruoho * substantially similar to the "NO WARRANTY" disclaimer below
19 1.3 jruoho * ("Disclaimer") and any redistribution must be conditioned upon
20 1.3 jruoho * including a substantially similar Disclaimer requirement for further
21 1.3 jruoho * binary redistribution.
22 1.3 jruoho * 3. Neither the names of the above-listed copyright holders nor the names
23 1.3 jruoho * of any contributors may be used to endorse or promote products derived
24 1.3 jruoho * from this software without specific prior written permission.
25 1.3 jruoho *
26 1.3 jruoho * Alternatively, this software may be distributed under the terms of the
27 1.3 jruoho * GNU General Public License ("GPL") version 2 as published by the Free
28 1.3 jruoho * Software Foundation.
29 1.3 jruoho *
30 1.3 jruoho * NO WARRANTY
31 1.3 jruoho * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 1.3 jruoho * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 1.3 jruoho * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 1.3 jruoho * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 1.3 jruoho * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 1.3 jruoho * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 1.3 jruoho * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 1.3 jruoho * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 1.3 jruoho * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 1.3 jruoho * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 1.3 jruoho * POSSIBILITY OF SUCH DAMAGES.
42 1.3 jruoho */
43 1.1 jruoho
44 1.1 jruoho /*
45 1.1 jruoho * These procedures are used for tracking memory leaks in the subsystem, and
46 1.1 jruoho * they get compiled out when the ACPI_DBG_TRACK_ALLOCATIONS is not set.
47 1.1 jruoho *
48 1.4 christos * Each memory allocation is tracked via a doubly linked list. Each
49 1.1 jruoho * element contains the caller's component, module name, function name, and
50 1.4 christos * line number. AcpiUtAllocate and AcpiUtAllocateZeroed call
51 1.1 jruoho * AcpiUtTrackAllocation to add an element to the list; deletion
52 1.1 jruoho * occurs in the body of AcpiUtFree.
53 1.1 jruoho */
54 1.1 jruoho
55 1.1 jruoho #include "acpi.h"
56 1.1 jruoho #include "accommon.h"
57 1.1 jruoho
58 1.1 jruoho #ifdef ACPI_DBG_TRACK_ALLOCATIONS
59 1.1 jruoho
60 1.1 jruoho #define _COMPONENT ACPI_UTILITIES
61 1.1 jruoho ACPI_MODULE_NAME ("uttrack")
62 1.1 jruoho
63 1.4 christos
64 1.1 jruoho /* Local prototypes */
65 1.1 jruoho
66 1.1 jruoho static ACPI_DEBUG_MEM_BLOCK *
67 1.1 jruoho AcpiUtFindAllocation (
68 1.4 christos ACPI_DEBUG_MEM_BLOCK *Allocation);
69 1.1 jruoho
70 1.1 jruoho static ACPI_STATUS
71 1.1 jruoho AcpiUtTrackAllocation (
72 1.1 jruoho ACPI_DEBUG_MEM_BLOCK *Address,
73 1.1 jruoho ACPI_SIZE Size,
74 1.1 jruoho UINT8 AllocType,
75 1.1 jruoho UINT32 Component,
76 1.1 jruoho const char *Module,
77 1.1 jruoho UINT32 Line);
78 1.1 jruoho
79 1.1 jruoho static ACPI_STATUS
80 1.1 jruoho AcpiUtRemoveAllocation (
81 1.1 jruoho ACPI_DEBUG_MEM_BLOCK *Address,
82 1.1 jruoho UINT32 Component,
83 1.1 jruoho const char *Module,
84 1.1 jruoho UINT32 Line);
85 1.1 jruoho
86 1.1 jruoho
87 1.1 jruoho /*******************************************************************************
88 1.1 jruoho *
89 1.1 jruoho * FUNCTION: AcpiUtCreateList
90 1.1 jruoho *
91 1.1 jruoho * PARAMETERS: CacheName - Ascii name for the cache
92 1.1 jruoho * ObjectSize - Size of each cached object
93 1.1 jruoho * ReturnCache - Where the new cache object is returned
94 1.1 jruoho *
95 1.1 jruoho * RETURN: Status
96 1.1 jruoho *
97 1.1 jruoho * DESCRIPTION: Create a local memory list for tracking purposed
98 1.1 jruoho *
99 1.1 jruoho ******************************************************************************/
100 1.1 jruoho
101 1.1 jruoho ACPI_STATUS
102 1.1 jruoho AcpiUtCreateList (
103 1.2 jruoho const char *ListName,
104 1.1 jruoho UINT16 ObjectSize,
105 1.1 jruoho ACPI_MEMORY_LIST **ReturnCache)
106 1.1 jruoho {
107 1.1 jruoho ACPI_MEMORY_LIST *Cache;
108 1.1 jruoho
109 1.1 jruoho
110 1.1 jruoho Cache = AcpiOsAllocate (sizeof (ACPI_MEMORY_LIST));
111 1.1 jruoho if (!Cache)
112 1.1 jruoho {
113 1.1 jruoho return (AE_NO_MEMORY);
114 1.1 jruoho }
115 1.1 jruoho
116 1.7 christos memset (Cache, 0, sizeof (ACPI_MEMORY_LIST));
117 1.1 jruoho
118 1.9 christos Cache->ListName = __UNCONST(ListName);
119 1.1 jruoho Cache->ObjectSize = ObjectSize;
120 1.1 jruoho
121 1.1 jruoho *ReturnCache = Cache;
122 1.1 jruoho return (AE_OK);
123 1.1 jruoho }
124 1.1 jruoho
125 1.1 jruoho
126 1.1 jruoho /*******************************************************************************
127 1.1 jruoho *
128 1.1 jruoho * FUNCTION: AcpiUtAllocateAndTrack
129 1.1 jruoho *
130 1.1 jruoho * PARAMETERS: Size - Size of the allocation
131 1.1 jruoho * Component - Component type of caller
132 1.1 jruoho * Module - Source file name of caller
133 1.1 jruoho * Line - Line number of caller
134 1.1 jruoho *
135 1.1 jruoho * RETURN: Address of the allocated memory on success, NULL on failure.
136 1.1 jruoho *
137 1.1 jruoho * DESCRIPTION: The subsystem's equivalent of malloc.
138 1.1 jruoho *
139 1.1 jruoho ******************************************************************************/
140 1.1 jruoho
141 1.1 jruoho void *
142 1.1 jruoho AcpiUtAllocateAndTrack (
143 1.1 jruoho ACPI_SIZE Size,
144 1.1 jruoho UINT32 Component,
145 1.1 jruoho const char *Module,
146 1.1 jruoho UINT32 Line)
147 1.1 jruoho {
148 1.1 jruoho ACPI_DEBUG_MEM_BLOCK *Allocation;
149 1.1 jruoho ACPI_STATUS Status;
150 1.1 jruoho
151 1.1 jruoho
152 1.4 christos /* Check for an inadvertent size of zero bytes */
153 1.4 christos
154 1.4 christos if (!Size)
155 1.4 christos {
156 1.4 christos ACPI_WARNING ((Module, Line,
157 1.4 christos "Attempt to allocate zero bytes, allocating 1 byte"));
158 1.4 christos Size = 1;
159 1.4 christos }
160 1.4 christos
161 1.4 christos Allocation = AcpiOsAllocate (Size + sizeof (ACPI_DEBUG_MEM_HEADER));
162 1.1 jruoho if (!Allocation)
163 1.1 jruoho {
164 1.4 christos /* Report allocation error */
165 1.4 christos
166 1.4 christos ACPI_WARNING ((Module, Line,
167 1.4 christos "Could not allocate size %u", (UINT32) Size));
168 1.4 christos
169 1.1 jruoho return (NULL);
170 1.1 jruoho }
171 1.1 jruoho
172 1.8 christos Status = AcpiUtTrackAllocation (
173 1.8 christos Allocation, Size, ACPI_MEM_MALLOC, Component, Module, Line);
174 1.1 jruoho if (ACPI_FAILURE (Status))
175 1.1 jruoho {
176 1.1 jruoho AcpiOsFree (Allocation);
177 1.1 jruoho return (NULL);
178 1.1 jruoho }
179 1.1 jruoho
180 1.1 jruoho AcpiGbl_GlobalList->TotalAllocated++;
181 1.1 jruoho AcpiGbl_GlobalList->TotalSize += (UINT32) Size;
182 1.1 jruoho AcpiGbl_GlobalList->CurrentTotalSize += (UINT32) Size;
183 1.8 christos
184 1.8 christos if (AcpiGbl_GlobalList->CurrentTotalSize >
185 1.8 christos AcpiGbl_GlobalList->MaxOccupied)
186 1.1 jruoho {
187 1.8 christos AcpiGbl_GlobalList->MaxOccupied =
188 1.8 christos AcpiGbl_GlobalList->CurrentTotalSize;
189 1.1 jruoho }
190 1.1 jruoho
191 1.1 jruoho return ((void *) &Allocation->UserSpace);
192 1.1 jruoho }
193 1.1 jruoho
194 1.1 jruoho
195 1.1 jruoho /*******************************************************************************
196 1.1 jruoho *
197 1.1 jruoho * FUNCTION: AcpiUtAllocateZeroedAndTrack
198 1.1 jruoho *
199 1.1 jruoho * PARAMETERS: Size - Size of the allocation
200 1.1 jruoho * Component - Component type of caller
201 1.1 jruoho * Module - Source file name of caller
202 1.1 jruoho * Line - Line number of caller
203 1.1 jruoho *
204 1.1 jruoho * RETURN: Address of the allocated memory on success, NULL on failure.
205 1.1 jruoho *
206 1.1 jruoho * DESCRIPTION: Subsystem equivalent of calloc.
207 1.1 jruoho *
208 1.1 jruoho ******************************************************************************/
209 1.1 jruoho
210 1.1 jruoho void *
211 1.1 jruoho AcpiUtAllocateZeroedAndTrack (
212 1.1 jruoho ACPI_SIZE Size,
213 1.1 jruoho UINT32 Component,
214 1.1 jruoho const char *Module,
215 1.1 jruoho UINT32 Line)
216 1.1 jruoho {
217 1.1 jruoho ACPI_DEBUG_MEM_BLOCK *Allocation;
218 1.1 jruoho ACPI_STATUS Status;
219 1.1 jruoho
220 1.1 jruoho
221 1.4 christos /* Check for an inadvertent size of zero bytes */
222 1.4 christos
223 1.4 christos if (!Size)
224 1.4 christos {
225 1.4 christos ACPI_WARNING ((Module, Line,
226 1.4 christos "Attempt to allocate zero bytes, allocating 1 byte"));
227 1.4 christos Size = 1;
228 1.4 christos }
229 1.4 christos
230 1.8 christos Allocation = AcpiOsAllocateZeroed (
231 1.8 christos Size + sizeof (ACPI_DEBUG_MEM_HEADER));
232 1.1 jruoho if (!Allocation)
233 1.1 jruoho {
234 1.1 jruoho /* Report allocation error */
235 1.1 jruoho
236 1.1 jruoho ACPI_ERROR ((Module, Line,
237 1.1 jruoho "Could not allocate size %u", (UINT32) Size));
238 1.1 jruoho return (NULL);
239 1.1 jruoho }
240 1.1 jruoho
241 1.1 jruoho Status = AcpiUtTrackAllocation (Allocation, Size,
242 1.8 christos ACPI_MEM_CALLOC, Component, Module, Line);
243 1.1 jruoho if (ACPI_FAILURE (Status))
244 1.1 jruoho {
245 1.1 jruoho AcpiOsFree (Allocation);
246 1.1 jruoho return (NULL);
247 1.1 jruoho }
248 1.1 jruoho
249 1.1 jruoho AcpiGbl_GlobalList->TotalAllocated++;
250 1.1 jruoho AcpiGbl_GlobalList->TotalSize += (UINT32) Size;
251 1.1 jruoho AcpiGbl_GlobalList->CurrentTotalSize += (UINT32) Size;
252 1.8 christos
253 1.8 christos if (AcpiGbl_GlobalList->CurrentTotalSize >
254 1.8 christos AcpiGbl_GlobalList->MaxOccupied)
255 1.1 jruoho {
256 1.8 christos AcpiGbl_GlobalList->MaxOccupied =
257 1.8 christos AcpiGbl_GlobalList->CurrentTotalSize;
258 1.1 jruoho }
259 1.1 jruoho
260 1.1 jruoho return ((void *) &Allocation->UserSpace);
261 1.1 jruoho }
262 1.1 jruoho
263 1.1 jruoho
264 1.1 jruoho /*******************************************************************************
265 1.1 jruoho *
266 1.1 jruoho * FUNCTION: AcpiUtFreeAndTrack
267 1.1 jruoho *
268 1.1 jruoho * PARAMETERS: Allocation - Address of the memory to deallocate
269 1.1 jruoho * Component - Component type of caller
270 1.1 jruoho * Module - Source file name of caller
271 1.1 jruoho * Line - Line number of caller
272 1.1 jruoho *
273 1.1 jruoho * RETURN: None
274 1.1 jruoho *
275 1.1 jruoho * DESCRIPTION: Frees the memory at Allocation
276 1.1 jruoho *
277 1.1 jruoho ******************************************************************************/
278 1.1 jruoho
279 1.1 jruoho void
280 1.1 jruoho AcpiUtFreeAndTrack (
281 1.1 jruoho void *Allocation,
282 1.1 jruoho UINT32 Component,
283 1.1 jruoho const char *Module,
284 1.1 jruoho UINT32 Line)
285 1.1 jruoho {
286 1.1 jruoho ACPI_DEBUG_MEM_BLOCK *DebugBlock;
287 1.1 jruoho ACPI_STATUS Status;
288 1.1 jruoho
289 1.1 jruoho
290 1.1 jruoho ACPI_FUNCTION_TRACE_PTR (UtFree, Allocation);
291 1.1 jruoho
292 1.1 jruoho
293 1.1 jruoho if (NULL == Allocation)
294 1.1 jruoho {
295 1.1 jruoho ACPI_ERROR ((Module, Line,
296 1.1 jruoho "Attempt to delete a NULL address"));
297 1.1 jruoho
298 1.1 jruoho return_VOID;
299 1.1 jruoho }
300 1.1 jruoho
301 1.1 jruoho DebugBlock = ACPI_CAST_PTR (ACPI_DEBUG_MEM_BLOCK,
302 1.8 christos (((char *) Allocation) - sizeof (ACPI_DEBUG_MEM_HEADER)));
303 1.1 jruoho
304 1.1 jruoho AcpiGbl_GlobalList->TotalFreed++;
305 1.1 jruoho AcpiGbl_GlobalList->CurrentTotalSize -= DebugBlock->Size;
306 1.1 jruoho
307 1.8 christos Status = AcpiUtRemoveAllocation (DebugBlock, Component, Module, Line);
308 1.1 jruoho if (ACPI_FAILURE (Status))
309 1.1 jruoho {
310 1.1 jruoho ACPI_EXCEPTION ((AE_INFO, Status, "Could not free memory"));
311 1.1 jruoho }
312 1.1 jruoho
313 1.1 jruoho AcpiOsFree (DebugBlock);
314 1.5 christos ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS, "%p freed (block %p)\n",
315 1.5 christos Allocation, DebugBlock));
316 1.1 jruoho return_VOID;
317 1.1 jruoho }
318 1.1 jruoho
319 1.1 jruoho
320 1.1 jruoho /*******************************************************************************
321 1.1 jruoho *
322 1.1 jruoho * FUNCTION: AcpiUtFindAllocation
323 1.1 jruoho *
324 1.1 jruoho * PARAMETERS: Allocation - Address of allocated memory
325 1.1 jruoho *
326 1.4 christos * RETURN: Three cases:
327 1.4 christos * 1) List is empty, NULL is returned.
328 1.4 christos * 2) Element was found. Returns Allocation parameter.
329 1.4 christos * 3) Element was not found. Returns position where it should be
330 1.4 christos * inserted into the list.
331 1.1 jruoho *
332 1.1 jruoho * DESCRIPTION: Searches for an element in the global allocation tracking list.
333 1.4 christos * If the element is not found, returns the location within the
334 1.4 christos * list where the element should be inserted.
335 1.4 christos *
336 1.4 christos * Note: The list is ordered by larger-to-smaller addresses.
337 1.4 christos *
338 1.4 christos * This global list is used to detect memory leaks in ACPICA as
339 1.4 christos * well as other issues such as an attempt to release the same
340 1.4 christos * internal object more than once. Although expensive as far
341 1.4 christos * as cpu time, this list is much more helpful for finding these
342 1.4 christos * types of issues than using memory leak detectors outside of
343 1.4 christos * the ACPICA code.
344 1.1 jruoho *
345 1.1 jruoho ******************************************************************************/
346 1.1 jruoho
347 1.1 jruoho static ACPI_DEBUG_MEM_BLOCK *
348 1.1 jruoho AcpiUtFindAllocation (
349 1.4 christos ACPI_DEBUG_MEM_BLOCK *Allocation)
350 1.1 jruoho {
351 1.1 jruoho ACPI_DEBUG_MEM_BLOCK *Element;
352 1.1 jruoho
353 1.1 jruoho
354 1.1 jruoho Element = AcpiGbl_GlobalList->ListHead;
355 1.4 christos if (!Element)
356 1.4 christos {
357 1.4 christos return (NULL);
358 1.4 christos }
359 1.1 jruoho
360 1.4 christos /*
361 1.4 christos * Search for the address.
362 1.4 christos *
363 1.4 christos * Note: List is ordered by larger-to-smaller addresses, on the
364 1.4 christos * assumption that a new allocation usually has a larger address
365 1.4 christos * than previous allocations.
366 1.4 christos */
367 1.4 christos while (Element > Allocation)
368 1.4 christos {
369 1.4 christos /* Check for end-of-list */
370 1.1 jruoho
371 1.4 christos if (!Element->Next)
372 1.1 jruoho {
373 1.1 jruoho return (Element);
374 1.1 jruoho }
375 1.1 jruoho
376 1.1 jruoho Element = Element->Next;
377 1.1 jruoho }
378 1.1 jruoho
379 1.4 christos if (Element == Allocation)
380 1.4 christos {
381 1.4 christos return (Element);
382 1.4 christos }
383 1.4 christos
384 1.4 christos return (Element->Previous);
385 1.1 jruoho }
386 1.1 jruoho
387 1.1 jruoho
388 1.1 jruoho /*******************************************************************************
389 1.1 jruoho *
390 1.1 jruoho * FUNCTION: AcpiUtTrackAllocation
391 1.1 jruoho *
392 1.1 jruoho * PARAMETERS: Allocation - Address of allocated memory
393 1.1 jruoho * Size - Size of the allocation
394 1.1 jruoho * AllocType - MEM_MALLOC or MEM_CALLOC
395 1.1 jruoho * Component - Component type of caller
396 1.1 jruoho * Module - Source file name of caller
397 1.1 jruoho * Line - Line number of caller
398 1.1 jruoho *
399 1.4 christos * RETURN: Status
400 1.1 jruoho *
401 1.1 jruoho * DESCRIPTION: Inserts an element into the global allocation tracking list.
402 1.1 jruoho *
403 1.1 jruoho ******************************************************************************/
404 1.1 jruoho
405 1.1 jruoho static ACPI_STATUS
406 1.1 jruoho AcpiUtTrackAllocation (
407 1.1 jruoho ACPI_DEBUG_MEM_BLOCK *Allocation,
408 1.1 jruoho ACPI_SIZE Size,
409 1.1 jruoho UINT8 AllocType,
410 1.1 jruoho UINT32 Component,
411 1.1 jruoho const char *Module,
412 1.1 jruoho UINT32 Line)
413 1.1 jruoho {
414 1.1 jruoho ACPI_MEMORY_LIST *MemList;
415 1.1 jruoho ACPI_DEBUG_MEM_BLOCK *Element;
416 1.1 jruoho ACPI_STATUS Status = AE_OK;
417 1.1 jruoho
418 1.1 jruoho
419 1.1 jruoho ACPI_FUNCTION_TRACE_PTR (UtTrackAllocation, Allocation);
420 1.1 jruoho
421 1.1 jruoho
422 1.1 jruoho if (AcpiGbl_DisableMemTracking)
423 1.1 jruoho {
424 1.1 jruoho return_ACPI_STATUS (AE_OK);
425 1.1 jruoho }
426 1.1 jruoho
427 1.1 jruoho MemList = AcpiGbl_GlobalList;
428 1.1 jruoho Status = AcpiUtAcquireMutex (ACPI_MTX_MEMORY);
429 1.1 jruoho if (ACPI_FAILURE (Status))
430 1.1 jruoho {
431 1.1 jruoho return_ACPI_STATUS (Status);
432 1.1 jruoho }
433 1.1 jruoho
434 1.1 jruoho /*
435 1.4 christos * Search the global list for this address to make sure it is not
436 1.4 christos * already present. This will catch several kinds of problems.
437 1.1 jruoho */
438 1.1 jruoho Element = AcpiUtFindAllocation (Allocation);
439 1.4 christos if (Element == Allocation)
440 1.1 jruoho {
441 1.1 jruoho ACPI_ERROR ((AE_INFO,
442 1.4 christos "UtTrackAllocation: Allocation (%p) already present in global list!",
443 1.1 jruoho Allocation));
444 1.1 jruoho goto UnlockAndExit;
445 1.1 jruoho }
446 1.1 jruoho
447 1.4 christos /* Fill in the instance data */
448 1.1 jruoho
449 1.8 christos Allocation->Size = (UINT32) Size;
450 1.1 jruoho Allocation->AllocType = AllocType;
451 1.1 jruoho Allocation->Component = Component;
452 1.8 christos Allocation->Line = Line;
453 1.1 jruoho
454 1.7 christos strncpy (Allocation->Module, Module, ACPI_MAX_MODULE_NAME);
455 1.1 jruoho Allocation->Module[ACPI_MAX_MODULE_NAME-1] = 0;
456 1.1 jruoho
457 1.4 christos if (!Element)
458 1.4 christos {
459 1.4 christos /* Insert at list head */
460 1.4 christos
461 1.4 christos if (MemList->ListHead)
462 1.4 christos {
463 1.8 christos ((ACPI_DEBUG_MEM_BLOCK *)(MemList->ListHead))->Previous =
464 1.8 christos Allocation;
465 1.4 christos }
466 1.4 christos
467 1.4 christos Allocation->Next = MemList->ListHead;
468 1.4 christos Allocation->Previous = NULL;
469 1.1 jruoho
470 1.4 christos MemList->ListHead = Allocation;
471 1.4 christos }
472 1.4 christos else
473 1.1 jruoho {
474 1.4 christos /* Insert after element */
475 1.4 christos
476 1.4 christos Allocation->Next = Element->Next;
477 1.4 christos Allocation->Previous = Element;
478 1.1 jruoho
479 1.4 christos if (Element->Next)
480 1.4 christos {
481 1.4 christos (Element->Next)->Previous = Allocation;
482 1.4 christos }
483 1.1 jruoho
484 1.4 christos Element->Next = Allocation;
485 1.4 christos }
486 1.1 jruoho
487 1.1 jruoho
488 1.1 jruoho UnlockAndExit:
489 1.1 jruoho Status = AcpiUtReleaseMutex (ACPI_MTX_MEMORY);
490 1.1 jruoho return_ACPI_STATUS (Status);
491 1.1 jruoho }
492 1.1 jruoho
493 1.1 jruoho
494 1.1 jruoho /*******************************************************************************
495 1.1 jruoho *
496 1.1 jruoho * FUNCTION: AcpiUtRemoveAllocation
497 1.1 jruoho *
498 1.1 jruoho * PARAMETERS: Allocation - Address of allocated memory
499 1.1 jruoho * Component - Component type of caller
500 1.1 jruoho * Module - Source file name of caller
501 1.1 jruoho * Line - Line number of caller
502 1.1 jruoho *
503 1.4 christos * RETURN: Status
504 1.1 jruoho *
505 1.1 jruoho * DESCRIPTION: Deletes an element from the global allocation tracking list.
506 1.1 jruoho *
507 1.1 jruoho ******************************************************************************/
508 1.1 jruoho
509 1.1 jruoho static ACPI_STATUS
510 1.1 jruoho AcpiUtRemoveAllocation (
511 1.1 jruoho ACPI_DEBUG_MEM_BLOCK *Allocation,
512 1.1 jruoho UINT32 Component,
513 1.1 jruoho const char *Module,
514 1.1 jruoho UINT32 Line)
515 1.1 jruoho {
516 1.1 jruoho ACPI_MEMORY_LIST *MemList;
517 1.1 jruoho ACPI_STATUS Status;
518 1.1 jruoho
519 1.1 jruoho
520 1.4 christos ACPI_FUNCTION_NAME (UtRemoveAllocation);
521 1.1 jruoho
522 1.1 jruoho
523 1.1 jruoho if (AcpiGbl_DisableMemTracking)
524 1.1 jruoho {
525 1.4 christos return (AE_OK);
526 1.1 jruoho }
527 1.1 jruoho
528 1.1 jruoho MemList = AcpiGbl_GlobalList;
529 1.1 jruoho if (NULL == MemList->ListHead)
530 1.1 jruoho {
531 1.1 jruoho /* No allocations! */
532 1.1 jruoho
533 1.1 jruoho ACPI_ERROR ((Module, Line,
534 1.1 jruoho "Empty allocation list, nothing to free!"));
535 1.1 jruoho
536 1.4 christos return (AE_OK);
537 1.1 jruoho }
538 1.1 jruoho
539 1.1 jruoho Status = AcpiUtAcquireMutex (ACPI_MTX_MEMORY);
540 1.1 jruoho if (ACPI_FAILURE (Status))
541 1.1 jruoho {
542 1.4 christos return (Status);
543 1.1 jruoho }
544 1.1 jruoho
545 1.1 jruoho /* Unlink */
546 1.1 jruoho
547 1.1 jruoho if (Allocation->Previous)
548 1.1 jruoho {
549 1.1 jruoho (Allocation->Previous)->Next = Allocation->Next;
550 1.1 jruoho }
551 1.1 jruoho else
552 1.1 jruoho {
553 1.1 jruoho MemList->ListHead = Allocation->Next;
554 1.1 jruoho }
555 1.1 jruoho
556 1.1 jruoho if (Allocation->Next)
557 1.1 jruoho {
558 1.1 jruoho (Allocation->Next)->Previous = Allocation->Previous;
559 1.1 jruoho }
560 1.1 jruoho
561 1.4 christos ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS, "Freeing %p, size 0%X\n",
562 1.4 christos &Allocation->UserSpace, Allocation->Size));
563 1.4 christos
564 1.1 jruoho /* Mark the segment as deleted */
565 1.1 jruoho
566 1.7 christos memset (&Allocation->UserSpace, 0xEA, Allocation->Size);
567 1.1 jruoho
568 1.1 jruoho Status = AcpiUtReleaseMutex (ACPI_MTX_MEMORY);
569 1.4 christos return (Status);
570 1.1 jruoho }
571 1.1 jruoho
572 1.1 jruoho
573 1.1 jruoho /*******************************************************************************
574 1.1 jruoho *
575 1.1 jruoho * FUNCTION: AcpiUtDumpAllocationInfo
576 1.1 jruoho *
577 1.4 christos * PARAMETERS: None
578 1.1 jruoho *
579 1.1 jruoho * RETURN: None
580 1.1 jruoho *
581 1.1 jruoho * DESCRIPTION: Print some info about the outstanding allocations.
582 1.1 jruoho *
583 1.1 jruoho ******************************************************************************/
584 1.1 jruoho
585 1.1 jruoho void
586 1.1 jruoho AcpiUtDumpAllocationInfo (
587 1.1 jruoho void)
588 1.1 jruoho {
589 1.1 jruoho /*
590 1.1 jruoho ACPI_MEMORY_LIST *MemList;
591 1.1 jruoho */
592 1.1 jruoho
593 1.1 jruoho ACPI_FUNCTION_TRACE (UtDumpAllocationInfo);
594 1.1 jruoho
595 1.1 jruoho /*
596 1.1 jruoho ACPI_DEBUG_PRINT (TRACE_ALLOCATIONS | TRACE_TABLES,
597 1.8 christos ("%30s: %4d (%3d Kb)\n", "Current allocations",
598 1.8 christos MemList->CurrentCount,
599 1.8 christos ROUND_UP_TO_1K (MemList->CurrentSize)));
600 1.1 jruoho
601 1.1 jruoho ACPI_DEBUG_PRINT (TRACE_ALLOCATIONS | TRACE_TABLES,
602 1.8 christos ("%30s: %4d (%3d Kb)\n", "Max concurrent allocations",
603 1.8 christos MemList->MaxConcurrentCount,
604 1.8 christos ROUND_UP_TO_1K (MemList->MaxConcurrentSize)));
605 1.1 jruoho
606 1.1 jruoho
607 1.1 jruoho ACPI_DEBUG_PRINT (TRACE_ALLOCATIONS | TRACE_TABLES,
608 1.8 christos ("%30s: %4d (%3d Kb)\n", "Total (all) internal objects",
609 1.8 christos RunningObjectCount,
610 1.8 christos ROUND_UP_TO_1K (RunningObjectSize)));
611 1.1 jruoho
612 1.1 jruoho ACPI_DEBUG_PRINT (TRACE_ALLOCATIONS | TRACE_TABLES,
613 1.8 christos ("%30s: %4d (%3d Kb)\n", "Total (all) allocations",
614 1.8 christos RunningAllocCount,
615 1.8 christos ROUND_UP_TO_1K (RunningAllocSize)));
616 1.1 jruoho
617 1.1 jruoho
618 1.1 jruoho ACPI_DEBUG_PRINT (TRACE_ALLOCATIONS | TRACE_TABLES,
619 1.8 christos ("%30s: %4d (%3d Kb)\n", "Current Nodes",
620 1.8 christos AcpiGbl_CurrentNodeCount,
621 1.8 christos ROUND_UP_TO_1K (AcpiGbl_CurrentNodeSize)));
622 1.1 jruoho
623 1.1 jruoho ACPI_DEBUG_PRINT (TRACE_ALLOCATIONS | TRACE_TABLES,
624 1.8 christos ("%30s: %4d (%3d Kb)\n", "Max Nodes",
625 1.8 christos AcpiGbl_MaxConcurrentNodeCount,
626 1.8 christos ROUND_UP_TO_1K ((AcpiGbl_MaxConcurrentNodeCount *
627 1.8 christos sizeof (ACPI_NAMESPACE_NODE)))));
628 1.1 jruoho */
629 1.1 jruoho return_VOID;
630 1.1 jruoho }
631 1.1 jruoho
632 1.1 jruoho
633 1.1 jruoho /*******************************************************************************
634 1.1 jruoho *
635 1.1 jruoho * FUNCTION: AcpiUtDumpAllocations
636 1.1 jruoho *
637 1.1 jruoho * PARAMETERS: Component - Component(s) to dump info for.
638 1.4 christos * Module - Module to dump info for. NULL means all.
639 1.1 jruoho *
640 1.1 jruoho * RETURN: None
641 1.1 jruoho *
642 1.1 jruoho * DESCRIPTION: Print a list of all outstanding allocations.
643 1.1 jruoho *
644 1.1 jruoho ******************************************************************************/
645 1.1 jruoho
646 1.1 jruoho void
647 1.1 jruoho AcpiUtDumpAllocations (
648 1.1 jruoho UINT32 Component,
649 1.1 jruoho const char *Module)
650 1.1 jruoho {
651 1.1 jruoho ACPI_DEBUG_MEM_BLOCK *Element;
652 1.1 jruoho ACPI_DESCRIPTOR *Descriptor;
653 1.1 jruoho UINT32 NumOutstanding = 0;
654 1.1 jruoho UINT8 DescriptorType;
655 1.1 jruoho
656 1.1 jruoho
657 1.1 jruoho ACPI_FUNCTION_TRACE (UtDumpAllocations);
658 1.1 jruoho
659 1.1 jruoho
660 1.1 jruoho if (AcpiGbl_DisableMemTracking)
661 1.1 jruoho {
662 1.4 christos return_VOID;
663 1.1 jruoho }
664 1.1 jruoho
665 1.1 jruoho /*
666 1.1 jruoho * Walk the allocation list.
667 1.1 jruoho */
668 1.1 jruoho if (ACPI_FAILURE (AcpiUtAcquireMutex (ACPI_MTX_MEMORY)))
669 1.1 jruoho {
670 1.4 christos return_VOID;
671 1.1 jruoho }
672 1.1 jruoho
673 1.1 jruoho Element = AcpiGbl_GlobalList->ListHead;
674 1.1 jruoho while (Element)
675 1.1 jruoho {
676 1.1 jruoho if ((Element->Component & Component) &&
677 1.7 christos ((Module == NULL) || (0 == strcmp (Module, Element->Module))))
678 1.1 jruoho {
679 1.8 christos Descriptor = ACPI_CAST_PTR (
680 1.8 christos ACPI_DESCRIPTOR, &Element->UserSpace);
681 1.1 jruoho
682 1.1 jruoho if (Element->Size < sizeof (ACPI_COMMON_DESCRIPTOR))
683 1.1 jruoho {
684 1.1 jruoho AcpiOsPrintf ("%p Length 0x%04X %9.9s-%u "
685 1.1 jruoho "[Not a Descriptor - too small]\n",
686 1.1 jruoho Descriptor, Element->Size, Element->Module,
687 1.1 jruoho Element->Line);
688 1.1 jruoho }
689 1.1 jruoho else
690 1.1 jruoho {
691 1.1 jruoho /* Ignore allocated objects that are in a cache */
692 1.1 jruoho
693 1.8 christos if (ACPI_GET_DESCRIPTOR_TYPE (Descriptor) !=
694 1.8 christos ACPI_DESC_TYPE_CACHED)
695 1.1 jruoho {
696 1.1 jruoho AcpiOsPrintf ("%p Length 0x%04X %9.9s-%u [%s] ",
697 1.1 jruoho Descriptor, Element->Size, Element->Module,
698 1.1 jruoho Element->Line, AcpiUtGetDescriptorName (Descriptor));
699 1.1 jruoho
700 1.1 jruoho /* Validate the descriptor type using Type field and length */
701 1.1 jruoho
702 1.1 jruoho DescriptorType = 0; /* Not a valid descriptor type */
703 1.1 jruoho
704 1.1 jruoho switch (ACPI_GET_DESCRIPTOR_TYPE (Descriptor))
705 1.1 jruoho {
706 1.1 jruoho case ACPI_DESC_TYPE_OPERAND:
707 1.4 christos
708 1.4 christos if (Element->Size == sizeof (ACPI_OPERAND_OBJECT))
709 1.1 jruoho {
710 1.1 jruoho DescriptorType = ACPI_DESC_TYPE_OPERAND;
711 1.1 jruoho }
712 1.1 jruoho break;
713 1.1 jruoho
714 1.1 jruoho case ACPI_DESC_TYPE_PARSER:
715 1.4 christos
716 1.4 christos if (Element->Size == sizeof (ACPI_PARSE_OBJECT))
717 1.1 jruoho {
718 1.1 jruoho DescriptorType = ACPI_DESC_TYPE_PARSER;
719 1.1 jruoho }
720 1.1 jruoho break;
721 1.1 jruoho
722 1.1 jruoho case ACPI_DESC_TYPE_NAMED:
723 1.4 christos
724 1.4 christos if (Element->Size == sizeof (ACPI_NAMESPACE_NODE))
725 1.1 jruoho {
726 1.1 jruoho DescriptorType = ACPI_DESC_TYPE_NAMED;
727 1.1 jruoho }
728 1.1 jruoho break;
729 1.1 jruoho
730 1.1 jruoho default:
731 1.4 christos
732 1.1 jruoho break;
733 1.1 jruoho }
734 1.1 jruoho
735 1.1 jruoho /* Display additional info for the major descriptor types */
736 1.1 jruoho
737 1.1 jruoho switch (DescriptorType)
738 1.1 jruoho {
739 1.1 jruoho case ACPI_DESC_TYPE_OPERAND:
740 1.4 christos
741 1.1 jruoho AcpiOsPrintf ("%12.12s RefCount 0x%04X\n",
742 1.1 jruoho AcpiUtGetTypeName (Descriptor->Object.Common.Type),
743 1.1 jruoho Descriptor->Object.Common.ReferenceCount);
744 1.1 jruoho break;
745 1.1 jruoho
746 1.1 jruoho case ACPI_DESC_TYPE_PARSER:
747 1.4 christos
748 1.1 jruoho AcpiOsPrintf ("AmlOpcode 0x%04hX\n",
749 1.1 jruoho Descriptor->Op.Asl.AmlOpcode);
750 1.1 jruoho break;
751 1.1 jruoho
752 1.1 jruoho case ACPI_DESC_TYPE_NAMED:
753 1.4 christos
754 1.1 jruoho AcpiOsPrintf ("%4.4s\n",
755 1.1 jruoho AcpiUtGetNodeName (&Descriptor->Node));
756 1.1 jruoho break;
757 1.1 jruoho
758 1.1 jruoho default:
759 1.4 christos
760 1.1 jruoho AcpiOsPrintf ( "\n");
761 1.1 jruoho break;
762 1.1 jruoho }
763 1.1 jruoho }
764 1.1 jruoho }
765 1.1 jruoho
766 1.1 jruoho NumOutstanding++;
767 1.1 jruoho }
768 1.1 jruoho
769 1.1 jruoho Element = Element->Next;
770 1.1 jruoho }
771 1.1 jruoho
772 1.1 jruoho (void) AcpiUtReleaseMutex (ACPI_MTX_MEMORY);
773 1.1 jruoho
774 1.1 jruoho /* Print summary */
775 1.1 jruoho
776 1.1 jruoho if (!NumOutstanding)
777 1.1 jruoho {
778 1.10 christos ACPI_INFO (("No outstanding allocations"));
779 1.1 jruoho }
780 1.1 jruoho else
781 1.1 jruoho {
782 1.1 jruoho ACPI_ERROR ((AE_INFO, "%u(0x%X) Outstanding allocations",
783 1.1 jruoho NumOutstanding, NumOutstanding));
784 1.1 jruoho }
785 1.1 jruoho
786 1.1 jruoho return_VOID;
787 1.1 jruoho }
788 1.1 jruoho
789 1.1 jruoho #endif /* ACPI_DBG_TRACK_ALLOCATIONS */
790