aslallocate.c revision 1.1.1.3 1 1.1 christos /******************************************************************************
2 1.1 christos *
3 1.1 christos * Module Name: aslallocate -- Local memory allocation
4 1.1 christos *
5 1.1 christos *****************************************************************************/
6 1.1 christos
7 1.1 christos /*
8 1.1.1.2 christos * Copyright (C) 2000 - 2018, Intel Corp.
9 1.1 christos * All rights reserved.
10 1.1 christos *
11 1.1 christos * Redistribution and use in source and binary forms, with or without
12 1.1 christos * modification, are permitted provided that the following conditions
13 1.1 christos * are met:
14 1.1 christos * 1. Redistributions of source code must retain the above copyright
15 1.1 christos * notice, this list of conditions, and the following disclaimer,
16 1.1 christos * without modification.
17 1.1 christos * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 1.1 christos * substantially similar to the "NO WARRANTY" disclaimer below
19 1.1 christos * ("Disclaimer") and any redistribution must be conditioned upon
20 1.1 christos * including a substantially similar Disclaimer requirement for further
21 1.1 christos * binary redistribution.
22 1.1 christos * 3. Neither the names of the above-listed copyright holders nor the names
23 1.1 christos * of any contributors may be used to endorse or promote products derived
24 1.1 christos * from this software without specific prior written permission.
25 1.1 christos *
26 1.1 christos * Alternatively, this software may be distributed under the terms of the
27 1.1 christos * GNU General Public License ("GPL") version 2 as published by the Free
28 1.1 christos * Software Foundation.
29 1.1 christos *
30 1.1 christos * NO WARRANTY
31 1.1 christos * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 1.1 christos * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 1.1 christos * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 1.1 christos * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 1.1 christos * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 1.1 christos * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 1.1 christos * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 1.1 christos * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 1.1 christos * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 1.1 christos * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 1.1 christos * POSSIBILITY OF SUCH DAMAGES.
42 1.1 christos */
43 1.1 christos
44 1.1 christos #include "aslcompiler.h"
45 1.1 christos
46 1.1 christos /*
47 1.1 christos * Local heap allocation wrappers. See aslcache.c for allocation from local
48 1.1 christos * cache alloctions
49 1.1 christos */
50 1.1 christos
51 1.1 christos
52 1.1 christos /*******************************************************************************
53 1.1 christos *
54 1.1 christos * FUNCTION: UtLocalCalloc
55 1.1 christos *
56 1.1 christos * PARAMETERS: Size - Bytes to be allocated
57 1.1 christos *
58 1.1 christos * RETURN: Pointer to the allocated memory. If this function returns
59 1.1 christos * (the compiler is not aborted), the pointer is guaranteed to
60 1.1 christos * be valid.
61 1.1 christos *
62 1.1 christos * DESCRIPTION: Allocate zero-initialized memory. The point of this function
63 1.1 christos * is to abort the compile on an allocation failure, on the
64 1.1 christos * assumption that nothing more can be accomplished.
65 1.1 christos *
66 1.1 christos * NOTE: For allocation from the local caches, see aslcache.c
67 1.1 christos *
68 1.1 christos ******************************************************************************/
69 1.1 christos
70 1.1 christos void *
71 1.1 christos UtLocalCalloc (
72 1.1 christos UINT32 Size)
73 1.1 christos {
74 1.1 christos void *Allocated;
75 1.1 christos
76 1.1 christos
77 1.1 christos Allocated = ACPI_ALLOCATE_ZEROED (Size);
78 1.1 christos if (!Allocated)
79 1.1 christos {
80 1.1 christos AslCommonError (ASL_ERROR, ASL_MSG_MEMORY_ALLOCATION,
81 1.1.1.3 christos AslGbl_CurrentLineNumber, AslGbl_LogicalLineNumber,
82 1.1.1.3 christos AslGbl_InputByteCount, AslGbl_CurrentColumn,
83 1.1.1.3 christos AslGbl_Files[ASL_FILE_INPUT].Filename, NULL);
84 1.1 christos
85 1.1 christos CmCleanupAndExit ();
86 1.1 christos exit (1);
87 1.1 christos }
88 1.1 christos
89 1.1.1.3 christos AslGbl_TotalAllocations++;
90 1.1.1.3 christos AslGbl_TotalAllocated += Size;
91 1.1 christos return (Allocated);
92 1.1 christos }
93 1.1 christos
94 1.1 christos
95 1.1 christos /******************************************************************************
96 1.1 christos *
97 1.1 christos * FUNCTION: UtExpandLineBuffers
98 1.1 christos *
99 1.1 christos * PARAMETERS: None. Updates global line buffer pointers.
100 1.1 christos *
101 1.1 christos * RETURN: None. Reallocates the global line buffers
102 1.1 christos *
103 1.1 christos * DESCRIPTION: Called if the current line buffer becomes filled. Reallocates
104 1.1.1.3 christos * all global line buffers and updates AslGbl_LineBufferSize. NOTE:
105 1.1 christos * Also used for the initial allocation of the buffers, when
106 1.1 christos * all of the buffer pointers are NULL. Initial allocations are
107 1.1 christos * of size ASL_DEFAULT_LINE_BUFFER_SIZE
108 1.1 christos *
109 1.1 christos *****************************************************************************/
110 1.1 christos
111 1.1 christos void
112 1.1 christos UtExpandLineBuffers (
113 1.1 christos void)
114 1.1 christos {
115 1.1 christos UINT32 NewSize;
116 1.1 christos
117 1.1 christos
118 1.1 christos /* Attempt to double the size of all line buffers */
119 1.1 christos
120 1.1.1.3 christos NewSize = AslGbl_LineBufferSize * 2;
121 1.1.1.3 christos if (AslGbl_CurrentLineBuffer)
122 1.1 christos {
123 1.1 christos DbgPrint (ASL_DEBUG_OUTPUT,
124 1.1 christos "Increasing line buffer size from %u to %u\n",
125 1.1.1.3 christos AslGbl_LineBufferSize, NewSize);
126 1.1 christos }
127 1.1 christos
128 1.1.1.3 christos UtReallocLineBuffers (&AslGbl_CurrentLineBuffer, AslGbl_LineBufferSize, NewSize);
129 1.1.1.3 christos UtReallocLineBuffers (&AslGbl_MainTokenBuffer, AslGbl_LineBufferSize, NewSize);
130 1.1.1.3 christos UtReallocLineBuffers (&AslGbl_MacroTokenBuffer, AslGbl_LineBufferSize, NewSize);
131 1.1.1.3 christos UtReallocLineBuffers (&AslGbl_ExpressionTokenBuffer, AslGbl_LineBufferSize, NewSize);
132 1.1 christos
133 1.1.1.3 christos AslGbl_LineBufPtr = AslGbl_CurrentLineBuffer;
134 1.1.1.3 christos AslGbl_LineBufferSize = NewSize;
135 1.1 christos }
136 1.1 christos
137 1.1 christos
138 1.1 christos /******************************************************************************
139 1.1 christos *
140 1.1 christos * FUNCTION: UtReallocLineBuffers
141 1.1 christos *
142 1.1 christos * PARAMETERS: Buffer - Buffer to realloc
143 1.1 christos * OldSize - Old size of Buffer
144 1.1 christos * NewSize - New size of Buffer
145 1.1 christos *
146 1.1 christos * RETURN: none
147 1.1 christos *
148 1.1 christos * DESCRIPTION: Reallocate and initialize Buffer
149 1.1 christos *
150 1.1 christos *****************************************************************************/
151 1.1 christos
152 1.1 christos void
153 1.1 christos UtReallocLineBuffers (
154 1.1 christos char **Buffer,
155 1.1 christos UINT32 OldSize,
156 1.1 christos UINT32 NewSize)
157 1.1 christos {
158 1.1 christos
159 1.1 christos *Buffer = realloc (*Buffer, NewSize);
160 1.1 christos if (*Buffer)
161 1.1 christos {
162 1.1 christos memset (*Buffer + OldSize, 0, NewSize - OldSize);
163 1.1 christos return;
164 1.1 christos }
165 1.1 christos
166 1.1 christos printf ("Could not increase line buffer size from %u to %u\n",
167 1.1 christos OldSize, NewSize);
168 1.1 christos
169 1.1 christos AslError (ASL_ERROR, ASL_MSG_BUFFER_ALLOCATION, NULL, NULL);
170 1.1 christos AslAbort ();
171 1.1 christos }
172 1.1 christos
173 1.1 christos
174 1.1 christos /******************************************************************************
175 1.1 christos *
176 1.1 christos * FUNCTION: UtFreeLineBuffers
177 1.1 christos *
178 1.1 christos * PARAMETERS: None
179 1.1 christos *
180 1.1 christos * RETURN: None
181 1.1 christos *
182 1.1 christos * DESCRIPTION: Free all line buffers
183 1.1 christos *
184 1.1 christos *****************************************************************************/
185 1.1 christos
186 1.1 christos void
187 1.1 christos UtFreeLineBuffers (
188 1.1 christos void)
189 1.1 christos {
190 1.1 christos
191 1.1.1.3 christos free (AslGbl_CurrentLineBuffer);
192 1.1.1.3 christos free (AslGbl_MainTokenBuffer);
193 1.1.1.3 christos free (AslGbl_MacroTokenBuffer);
194 1.1.1.3 christos free (AslGbl_ExpressionTokenBuffer);
195 1.1 christos }
196