utalloc.c revision 77424
1/******************************************************************************
2 *
3 * Module Name: utalloc - local memory allocation routines
4 *              $Revision: 90 $
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#ifdef ACPI_DEBUG_TRACK_ALLOCATIONS
130
131/*
132 * Most of this code is for tracking memory leaks in the subsystem, and it
133 * gets compiled out when the ACPI_DEBUG flag is not set.
134 * Every memory allocation is kept track of in a doubly linked list.  Each
135 * element contains the caller's component, module name, function name, and
136 * line number.  _UtAllocate and _UtCallocate call AcpiUtAddElementToAllocList
137 * to add an element to the list; deletion occurs in the bosy of _UtFree.
138 */
139
140
141/*******************************************************************************
142 *
143 * FUNCTION:    AcpiUtSearchAllocList
144 *
145 * PARAMETERS:  Address             - Address of allocated memory
146 *
147 * RETURN:      A list element if found; NULL otherwise.
148 *
149 * DESCRIPTION: Searches for an element in the global allocation tracking list.
150 *
151 ******************************************************************************/
152
153ACPI_ALLOCATION_INFO *
154AcpiUtSearchAllocList (
155    void                    *Address)
156{
157    ACPI_ALLOCATION_INFO    *Element = AcpiGbl_HeadAllocPtr;
158
159
160    /* Search for the address. */
161
162    while (Element)
163    {
164        if (Element->Address == Address)
165        {
166            return (Element);
167        }
168
169        Element = Element->Next;
170    }
171
172    return (NULL);
173}
174
175
176/*******************************************************************************
177 *
178 * FUNCTION:    AcpiUtAddElementToAllocList
179 *
180 * PARAMETERS:  Address             - Address of allocated memory
181 *              Size                - Size of the allocation
182 *              AllocType           - MEM_MALLOC or MEM_CALLOC
183 *              Component           - Component type of caller
184 *              Module              - Source file name of caller
185 *              Line                - Line number of caller
186 *
187 * RETURN:      None.
188 *
189 * DESCRIPTION: Inserts an element into the global allocation tracking list.
190 *
191 ******************************************************************************/
192
193ACPI_STATUS
194AcpiUtAddElementToAllocList (
195    void                    *Address,
196    UINT32                  Size,
197    UINT8                   AllocType,
198    UINT32                  Component,
199    NATIVE_CHAR             *Module,
200    UINT32                  Line)
201{
202    ACPI_ALLOCATION_INFO    *Element;
203    ACPI_STATUS             Status = AE_OK;
204
205
206    FUNCTION_TRACE_PTR ("UtAddElementToAllocList", Address);
207
208
209    AcpiUtAcquireMutex (ACPI_MTX_MEMORY);
210
211    /* Keep track of the running total of all allocations. */
212
213    AcpiGbl_CurrentAllocCount++;
214    AcpiGbl_RunningAllocCount++;
215
216    if (AcpiGbl_MaxConcurrentAllocCount < AcpiGbl_CurrentAllocCount)
217    {
218        AcpiGbl_MaxConcurrentAllocCount = AcpiGbl_CurrentAllocCount;
219    }
220
221    AcpiGbl_CurrentAllocSize += Size;
222    AcpiGbl_RunningAllocSize += Size;
223
224    if (AcpiGbl_MaxConcurrentAllocSize < AcpiGbl_CurrentAllocSize)
225    {
226        AcpiGbl_MaxConcurrentAllocSize = AcpiGbl_CurrentAllocSize;
227    }
228
229    /* If the head pointer is null, create the first element and fill it in. */
230
231    if (NULL == AcpiGbl_HeadAllocPtr)
232    {
233        AcpiGbl_HeadAllocPtr = AcpiOsCallocate (sizeof (ACPI_ALLOCATION_INFO));
234        if (!AcpiGbl_HeadAllocPtr)
235        {
236            DEBUG_PRINTP (ACPI_ERROR, ("Could not allocate mem info block\n"));
237            Status = AE_NO_MEMORY;
238            goto UnlockAndExit;
239        }
240
241        AcpiGbl_TailAllocPtr = AcpiGbl_HeadAllocPtr;
242    }
243
244    else
245    {
246        AcpiGbl_TailAllocPtr->Next = AcpiOsCallocate (sizeof (ACPI_ALLOCATION_INFO));
247        if (!AcpiGbl_TailAllocPtr->Next)
248        {
249            DEBUG_PRINTP (ACPI_ERROR, ("Could not allocate mem info block\n"));
250            Status = AE_NO_MEMORY;
251            goto UnlockAndExit;
252        }
253
254        /* error check */
255
256        AcpiGbl_TailAllocPtr->Next->Previous = AcpiGbl_TailAllocPtr;
257        AcpiGbl_TailAllocPtr = AcpiGbl_TailAllocPtr->Next;
258    }
259
260    /*
261     * Search list for this address to make sure it is not already on the list.
262     * This will catch several kinds of problems.
263     */
264
265    Element = AcpiUtSearchAllocList (Address);
266    if (Element)
267    {
268        REPORT_ERROR (("UtAddElementToAllocList: Address already present in list! (%p)\n",
269            Address));
270
271        DEBUG_PRINTP (ACPI_ERROR, ("Element %p Address %p\n", Element, Address));
272
273        BREAKPOINT3;
274    }
275
276    /* Fill in the instance data. */
277
278    AcpiGbl_TailAllocPtr->Address   = Address;
279    AcpiGbl_TailAllocPtr->Size      = Size;
280    AcpiGbl_TailAllocPtr->AllocType = AllocType;
281    AcpiGbl_TailAllocPtr->Component = Component;
282    AcpiGbl_TailAllocPtr->Line      = Line;
283
284    STRNCPY (AcpiGbl_TailAllocPtr->Module, Module, MAX_MODULE_NAME);
285
286
287UnlockAndExit:
288    AcpiUtReleaseMutex (ACPI_MTX_MEMORY);
289    return_ACPI_STATUS (Status);
290}
291
292
293/*******************************************************************************
294 *
295 * FUNCTION:    AcpiUtDeleteElementFromAllocList
296 *
297 * PARAMETERS:  Address             - Address of allocated memory
298 *              Component           - Component type of caller
299 *              Module              - Source file name of caller
300 *              Line                - Line number of caller
301 *
302 * RETURN:
303 *
304 * DESCRIPTION: Deletes an element from the global allocation tracking list.
305 *
306 ******************************************************************************/
307
308void
309AcpiUtDeleteElementFromAllocList (
310    void                    *Address,
311    UINT32                  Component,
312    NATIVE_CHAR             *Module,
313    UINT32                  Line)
314{
315    ACPI_ALLOCATION_INFO    *Element;
316    UINT32                  *DwordPtr;
317    UINT32                  DwordLen;
318    UINT32                  Size;
319    UINT32                  i;
320
321
322    FUNCTION_TRACE ("UtDeleteElementFromAllocList");
323
324    if (NULL == AcpiGbl_HeadAllocPtr)
325    {
326        /* Boy we got problems. */
327
328        _REPORT_ERROR (Module, Line, Component,
329                ("UtDeleteElementFromAllocList: Empty allocation list, nothing to free!\n"));
330
331        return_VOID;
332    }
333
334
335    AcpiUtAcquireMutex (ACPI_MTX_MEMORY);
336
337    /* Keep track of the amount of memory allocated. */
338
339    Size = 0;
340    AcpiGbl_CurrentAllocCount--;
341
342    if (AcpiGbl_HeadAllocPtr == AcpiGbl_TailAllocPtr)
343    {
344        if (Address != AcpiGbl_HeadAllocPtr->Address)
345        {
346            _REPORT_ERROR (Module, Line, Component,
347                ("UtDeleteElementFromAllocList: Deleting non-allocated memory\n"));
348
349            goto Cleanup;
350        }
351
352        Size = AcpiGbl_HeadAllocPtr->Size;
353
354        AcpiOsFree (AcpiGbl_HeadAllocPtr);
355        AcpiGbl_HeadAllocPtr = NULL;
356        AcpiGbl_TailAllocPtr = NULL;
357
358        DEBUG_PRINTP (TRACE_ALLOCATIONS,
359            ("Allocation list deleted.  There are no outstanding allocations\n"));
360
361        goto Cleanup;
362    }
363
364
365    /* Search list for this address */
366
367    Element = AcpiUtSearchAllocList (Address);
368    if (Element)
369    {
370        /* cases: head, tail, other */
371
372        if (Element == AcpiGbl_HeadAllocPtr)
373        {
374            Element->Next->Previous = NULL;
375            AcpiGbl_HeadAllocPtr = Element->Next;
376        }
377
378        else
379        {
380            if (Element == AcpiGbl_TailAllocPtr)
381            {
382                Element->Previous->Next = NULL;
383                AcpiGbl_TailAllocPtr = Element->Previous;
384            }
385
386            else
387            {
388                Element->Previous->Next = Element->Next;
389                Element->Next->Previous = Element->Previous;
390            }
391        }
392
393
394        /* Mark the segment as deleted */
395
396        if (Element->Size >= 4)
397        {
398            DwordLen = DIV_4 (Element->Size);
399            DwordPtr = (UINT32 *) Element->Address;
400
401            for (i = 0; i < DwordLen; i++)
402            {
403                DwordPtr[i] = 0x00DEAD00;
404            }
405
406            /* Set obj type, desc, and ref count fields to all ones */
407
408            DwordPtr[0] = ACPI_UINT32_MAX;
409            if (Element->Size >= 8)
410            {
411                DwordPtr[1] = ACPI_UINT32_MAX;
412            }
413        }
414
415        Size = Element->Size;
416
417        MEMSET (Element, 0xEA, sizeof (ACPI_ALLOCATION_INFO));
418
419
420        if (Size == sizeof (ACPI_OPERAND_OBJECT))
421        {
422            DEBUG_PRINTP (TRACE_ALLOCATIONS,
423                ("Freeing size %X (ACPI_OPERAND_OBJECT)\n", Size));
424        }
425        else
426        {
427            DEBUG_PRINTP (TRACE_ALLOCATIONS, ("Freeing size %X\n", Size));
428        }
429
430        AcpiOsFree (Element);
431    }
432
433    else
434    {
435        _REPORT_ERROR (Module, Line, Component,
436                ("_UtFree: Entry not found in list\n"));
437        DEBUG_PRINTP (ACPI_ERROR, ("Entry %p was not found in allocation list\n",
438                Address));
439        AcpiUtReleaseMutex (ACPI_MTX_MEMORY);
440        return_VOID;
441    }
442
443
444Cleanup:
445
446    AcpiGbl_CurrentAllocSize -= Size;
447    AcpiUtReleaseMutex (ACPI_MTX_MEMORY);
448
449    return_VOID;
450}
451
452
453/*******************************************************************************
454 *
455 * FUNCTION:    AcpiUtDumpAllocationInfo
456 *
457 * PARAMETERS:
458 *
459 * RETURN:      None
460 *
461 * DESCRIPTION: Print some info about the outstanding allocations.
462 *
463 ******************************************************************************/
464
465void
466AcpiUtDumpAllocationInfo (
467    void)
468{
469    FUNCTION_TRACE ("UtDumpAllocationInfo");
470
471
472    DEBUG_PRINT (TRACE_ALLOCATIONS | TRACE_TABLES,
473                    ("%30s: %4d (%3d Kb)\n", "Current allocations",
474                    AcpiGbl_CurrentAllocCount,
475                    ROUND_UP_TO_1K (AcpiGbl_CurrentAllocSize)));
476
477    DEBUG_PRINT (TRACE_ALLOCATIONS | TRACE_TABLES,
478                    ("%30s: %4d (%3d Kb)\n", "Max concurrent allocations",
479                    AcpiGbl_MaxConcurrentAllocCount,
480                    ROUND_UP_TO_1K (AcpiGbl_MaxConcurrentAllocSize)));
481
482    DEBUG_PRINT (TRACE_ALLOCATIONS | TRACE_TABLES,
483                    ("%30s: %4d (%3d Kb)\n", "Current Internal objects",
484                    AcpiGbl_CurrentObjectCount,
485                    ROUND_UP_TO_1K (AcpiGbl_CurrentObjectSize)));
486
487    DEBUG_PRINT (TRACE_ALLOCATIONS | TRACE_TABLES,
488                    ("%30s: %4d (%3d Kb)\n", "Max internal objects",
489                    AcpiGbl_MaxConcurrentObjectCount,
490                    ROUND_UP_TO_1K (AcpiGbl_MaxConcurrentObjectSize)));
491
492    DEBUG_PRINT (TRACE_ALLOCATIONS | TRACE_TABLES,
493                    ("%30s: %4d (%3d Kb)\n", "Current Nodes",
494                    AcpiGbl_CurrentNodeCount,
495                    ROUND_UP_TO_1K (AcpiGbl_CurrentNodeSize)));
496
497    DEBUG_PRINT (TRACE_ALLOCATIONS | TRACE_TABLES,
498                    ("%30s: %4d (%3d Kb)\n", "Max Nodes",
499                    AcpiGbl_MaxConcurrentNodeCount,
500                    ROUND_UP_TO_1K ((AcpiGbl_MaxConcurrentNodeCount * sizeof (ACPI_NAMESPACE_NODE)))));
501
502    DEBUG_PRINT (TRACE_ALLOCATIONS | TRACE_TABLES,
503                    ("%30s: %4d (%3d Kb)\n", "Total (all) internal objects",
504                    AcpiGbl_RunningObjectCount,
505                    ROUND_UP_TO_1K (AcpiGbl_RunningObjectSize)));
506
507    DEBUG_PRINT (TRACE_ALLOCATIONS | TRACE_TABLES,
508                    ("%30s: %4d (%3d Kb)\n", "Total (all) allocations",
509                    AcpiGbl_RunningAllocCount,
510                    ROUND_UP_TO_1K (AcpiGbl_RunningAllocSize)));
511
512    return_VOID;
513}
514
515
516/*******************************************************************************
517 *
518 * FUNCTION:    AcpiUtDumpCurrentAllocations
519 *
520 * PARAMETERS:  Component           - Component(s) to dump info for.
521 *              Module              - Module to dump info for.  NULL means all.
522 *
523 * RETURN:      None
524 *
525 * DESCRIPTION: Print a list of all outstanding allocations.
526 *
527 ******************************************************************************/
528
529void
530AcpiUtDumpCurrentAllocations (
531    UINT32                  Component,
532    NATIVE_CHAR             *Module)
533{
534    ACPI_ALLOCATION_INFO    *Element = AcpiGbl_HeadAllocPtr;
535    UINT32                  i;
536
537
538    FUNCTION_TRACE ("UtDumpCurrentAllocations");
539
540
541    if (Element == NULL)
542    {
543        DEBUG_PRINT (TRACE_ALLOCATIONS | TRACE_TABLES,
544                ("No outstanding allocations.\n"));
545        return_VOID;
546    }
547
548
549    /*
550     * Walk the allocation list.
551     */
552
553    AcpiUtAcquireMutex (ACPI_MTX_MEMORY);
554
555    DEBUG_PRINT (TRACE_ALLOCATIONS | TRACE_TABLES,
556        ("Outstanding allocations:\n"));
557
558    for (i = 1; ; i++)  /* Just a counter */
559    {
560        if ((Element->Component & Component) &&
561            ((Module == NULL) || (0 == STRCMP (Module, Element->Module))))
562        {
563            DEBUG_PRINT (TRACE_ALLOCATIONS | TRACE_TABLES,
564                        ("%p Len %04lX %9.9s-%ld",
565                        Element->Address, Element->Size, Element->Module,
566                        Element->Line));
567
568            /* Most of the elements will be internal objects. */
569
570            switch (((ACPI_OPERAND_OBJECT  *)
571                (Element->Address))->Common.DataType)
572            {
573            case ACPI_DESC_TYPE_INTERNAL:
574                DEBUG_PRINT_RAW (TRACE_ALLOCATIONS | TRACE_TABLES,
575                        (" ObjType %s",
576                        AcpiUtGetTypeName (((ACPI_OPERAND_OBJECT  *)(Element->Address))->Common.Type)));
577                break;
578
579            case ACPI_DESC_TYPE_PARSER:
580                DEBUG_PRINT_RAW (TRACE_ALLOCATIONS | TRACE_TABLES,
581                        (" ParseObj Opcode %04X",
582                        ((ACPI_PARSE_OBJECT *)(Element->Address))->Opcode));
583                break;
584
585            case ACPI_DESC_TYPE_NAMED:
586                DEBUG_PRINT_RAW (TRACE_ALLOCATIONS | TRACE_TABLES,
587                        (" Node %4.4s",
588                        &((ACPI_NAMESPACE_NODE *)(Element->Address))->Name));
589                break;
590
591            case ACPI_DESC_TYPE_STATE:
592                DEBUG_PRINT_RAW (TRACE_ALLOCATIONS | TRACE_TABLES,
593                        (" StateObj"));
594                break;
595            }
596
597            DEBUG_PRINT_RAW (TRACE_ALLOCATIONS | TRACE_TABLES, ("\n"));
598        }
599
600        if (Element->Next == NULL)
601        {
602            break;
603        }
604
605        Element = Element->Next;
606    }
607
608    AcpiUtReleaseMutex (ACPI_MTX_MEMORY);
609
610    DEBUG_PRINT (TRACE_ALLOCATIONS | TRACE_TABLES,
611        ("Total number of unfreed allocations = %d(%X)\n", i,i));
612
613
614    return_VOID;
615
616}
617#endif  /* #ifdef ACPI_DEBUG_TRACK_ALLOCATIONS */
618
619/*******************************************************************************
620 *
621 * FUNCTION:    _UtAllocate
622 *
623 * PARAMETERS:  Size                - Size of the allocation
624 *              Component           - Component type of caller
625 *              Module              - Source file name of caller
626 *              Line                - Line number of caller
627 *
628 * RETURN:      Address of the allocated memory on success, NULL on failure.
629 *
630 * DESCRIPTION: The subsystem's equivalent of malloc.
631 *
632 ******************************************************************************/
633
634void *
635_UtAllocate (
636    UINT32                  Size,
637    UINT32                  Component,
638    NATIVE_CHAR             *Module,
639    UINT32                  Line)
640{
641    void                    *Address = NULL;
642
643
644    FUNCTION_TRACE_U32 ("_UtAllocate", Size);
645
646
647    /* Check for an inadvertent size of zero bytes */
648
649    if (!Size)
650    {
651        _REPORT_ERROR (Module, Line, Component,
652                ("UtAllocate: Attempt to allocate zero bytes\n"));
653        Size = 1;
654    }
655
656    Address = AcpiOsAllocate (Size);
657    if (!Address)
658    {
659        /* Report allocation error */
660
661        _REPORT_ERROR (Module, Line, Component,
662                ("UtAllocate: Could not allocate size %X\n", Size));
663
664        return_PTR (NULL);
665    }
666
667#ifdef ACPI_DEBUG_TRACK_ALLOCATIONS
668
669    if (ACPI_FAILURE (AcpiUtAddElementToAllocList (Address, Size, MEM_MALLOC,
670                                Component, Module, Line)))
671    {
672        AcpiOsFree (Address);
673        return_PTR (NULL);
674    }
675
676    DEBUG_PRINTP (TRACE_ALLOCATIONS, ("%p Size %X\n", Address, Size));
677#endif
678
679    return_PTR (Address);
680}
681
682
683/*******************************************************************************
684 *
685 * FUNCTION:    _UtCallocate
686 *
687 * PARAMETERS:  Size                - Size of the allocation
688 *              Component           - Component type of caller
689 *              Module              - Source file name of caller
690 *              Line                - Line number of caller
691 *
692 * RETURN:      Address of the allocated memory on success, NULL on failure.
693 *
694 * DESCRIPTION: Subsystem equivalent of calloc.
695 *
696 ******************************************************************************/
697
698void *
699_UtCallocate (
700    UINT32                  Size,
701    UINT32                  Component,
702    NATIVE_CHAR             *Module,
703    UINT32                  Line)
704{
705    void                    *Address = NULL;
706
707
708    FUNCTION_TRACE_U32 ("_UtCallocate", Size);
709
710
711    /* Check for an inadvertent size of zero bytes */
712
713    if (!Size)
714    {
715        _REPORT_ERROR (Module, Line, Component,
716                ("UtCallocate: Attempt to allocate zero bytes\n"));
717        return_PTR (NULL);
718    }
719
720
721    Address = AcpiOsCallocate (Size);
722    if (!Address)
723    {
724        /* Report allocation error */
725
726        _REPORT_ERROR (Module, Line, Component,
727                ("UtCallocate: Could not allocate size %X\n", Size));
728        return_PTR (NULL);
729    }
730
731#ifdef ACPI_DEBUG_TRACK_ALLOCATIONS
732
733    if (ACPI_FAILURE (AcpiUtAddElementToAllocList (Address, Size, MEM_CALLOC,
734                            Component,Module, Line)))
735    {
736        AcpiOsFree (Address);
737        return_PTR (NULL);
738    }
739#endif
740
741    DEBUG_PRINTP (TRACE_ALLOCATIONS, ("%p Size %X\n", Address, Size));
742
743    return_PTR (Address);
744}
745
746
747/*******************************************************************************
748 *
749 * FUNCTION:    _UtFree
750 *
751 * PARAMETERS:  Address             - Address of the memory to deallocate
752 *              Component           - Component type of caller
753 *              Module              - Source file name of caller
754 *              Line                - Line number of caller
755 *
756 * RETURN:      None
757 *
758 * DESCRIPTION: Frees the memory at Address
759 *
760 ******************************************************************************/
761
762void
763_UtFree (
764    void                    *Address,
765    UINT32                  Component,
766    NATIVE_CHAR             *Module,
767    UINT32                  Line)
768{
769    FUNCTION_TRACE_PTR ("_UtFree", Address);
770
771
772    if (NULL == Address)
773    {
774        _REPORT_ERROR (Module, Line, Component,
775            ("_UtFree: Trying to delete a NULL address\n"));
776
777        return_VOID;
778    }
779
780#ifdef ACPI_DEBUG_TRACK_ALLOCATIONS
781    AcpiUtDeleteElementFromAllocList (Address, Component, Module, Line);
782#endif
783
784    AcpiOsFree (Address);
785
786    DEBUG_PRINTP (TRACE_ALLOCATIONS, ("%p freed\n", Address));
787
788    return_VOID;
789}
790
791
792