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