utalloc.c revision 1.1.1.2.4.2 1 1.1.1.2.4.2 rmind /******************************************************************************
2 1.1.1.2.4.2 rmind *
3 1.1.1.2.4.2 rmind * Module Name: utalloc - local memory allocation routines
4 1.1.1.2.4.2 rmind *
5 1.1.1.2.4.2 rmind *****************************************************************************/
6 1.1.1.2.4.2 rmind
7 1.1.1.2.4.2 rmind /*
8 1.1.1.2.4.2 rmind * Copyright (C) 2000 - 2011, Intel Corp.
9 1.1.1.2.4.2 rmind * All rights reserved.
10 1.1.1.2.4.2 rmind *
11 1.1.1.2.4.2 rmind * Redistribution and use in source and binary forms, with or without
12 1.1.1.2.4.2 rmind * modification, are permitted provided that the following conditions
13 1.1.1.2.4.2 rmind * are met:
14 1.1.1.2.4.2 rmind * 1. Redistributions of source code must retain the above copyright
15 1.1.1.2.4.2 rmind * notice, this list of conditions, and the following disclaimer,
16 1.1.1.2.4.2 rmind * without modification.
17 1.1.1.2.4.2 rmind * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 1.1.1.2.4.2 rmind * substantially similar to the "NO WARRANTY" disclaimer below
19 1.1.1.2.4.2 rmind * ("Disclaimer") and any redistribution must be conditioned upon
20 1.1.1.2.4.2 rmind * including a substantially similar Disclaimer requirement for further
21 1.1.1.2.4.2 rmind * binary redistribution.
22 1.1.1.2.4.2 rmind * 3. Neither the names of the above-listed copyright holders nor the names
23 1.1.1.2.4.2 rmind * of any contributors may be used to endorse or promote products derived
24 1.1.1.2.4.2 rmind * from this software without specific prior written permission.
25 1.1.1.2.4.2 rmind *
26 1.1.1.2.4.2 rmind * Alternatively, this software may be distributed under the terms of the
27 1.1.1.2.4.2 rmind * GNU General Public License ("GPL") version 2 as published by the Free
28 1.1.1.2.4.2 rmind * Software Foundation.
29 1.1.1.2.4.2 rmind *
30 1.1.1.2.4.2 rmind * NO WARRANTY
31 1.1.1.2.4.2 rmind * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 1.1.1.2.4.2 rmind * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 1.1.1.2.4.2 rmind * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 1.1.1.2.4.2 rmind * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 1.1.1.2.4.2 rmind * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 1.1.1.2.4.2 rmind * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 1.1.1.2.4.2 rmind * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 1.1.1.2.4.2 rmind * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 1.1.1.2.4.2 rmind * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 1.1.1.2.4.2 rmind * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 1.1.1.2.4.2 rmind * POSSIBILITY OF SUCH DAMAGES.
42 1.1.1.2.4.2 rmind */
43 1.1.1.2.4.2 rmind
44 1.1.1.2.4.2 rmind #define __UTALLOC_C__
45 1.1.1.2.4.2 rmind
46 1.1.1.2.4.2 rmind #include "acpi.h"
47 1.1.1.2.4.2 rmind #include "accommon.h"
48 1.1.1.2.4.2 rmind #include "acdebug.h"
49 1.1.1.2.4.2 rmind
50 1.1.1.2.4.2 rmind #define _COMPONENT ACPI_UTILITIES
51 1.1.1.2.4.2 rmind ACPI_MODULE_NAME ("utalloc")
52 1.1.1.2.4.2 rmind
53 1.1.1.2.4.2 rmind
54 1.1.1.2.4.2 rmind /*******************************************************************************
55 1.1.1.2.4.2 rmind *
56 1.1.1.2.4.2 rmind * FUNCTION: AcpiUtCreateCaches
57 1.1.1.2.4.2 rmind *
58 1.1.1.2.4.2 rmind * PARAMETERS: None
59 1.1.1.2.4.2 rmind *
60 1.1.1.2.4.2 rmind * RETURN: Status
61 1.1.1.2.4.2 rmind *
62 1.1.1.2.4.2 rmind * DESCRIPTION: Create all local caches
63 1.1.1.2.4.2 rmind *
64 1.1.1.2.4.2 rmind ******************************************************************************/
65 1.1.1.2.4.2 rmind
66 1.1.1.2.4.2 rmind ACPI_STATUS
67 1.1.1.2.4.2 rmind AcpiUtCreateCaches (
68 1.1.1.2.4.2 rmind void)
69 1.1.1.2.4.2 rmind {
70 1.1.1.2.4.2 rmind ACPI_STATUS Status;
71 1.1.1.2.4.2 rmind
72 1.1.1.2.4.2 rmind
73 1.1.1.2.4.2 rmind /* Object Caches, for frequently used objects */
74 1.1.1.2.4.2 rmind
75 1.1.1.2.4.2 rmind Status = AcpiOsCreateCache ("Acpi-Namespace", sizeof (ACPI_NAMESPACE_NODE),
76 1.1.1.2.4.2 rmind ACPI_MAX_NAMESPACE_CACHE_DEPTH, &AcpiGbl_NamespaceCache);
77 1.1.1.2.4.2 rmind if (ACPI_FAILURE (Status))
78 1.1.1.2.4.2 rmind {
79 1.1.1.2.4.2 rmind return (Status);
80 1.1.1.2.4.2 rmind }
81 1.1.1.2.4.2 rmind
82 1.1.1.2.4.2 rmind Status = AcpiOsCreateCache ("Acpi-State", sizeof (ACPI_GENERIC_STATE),
83 1.1.1.2.4.2 rmind ACPI_MAX_STATE_CACHE_DEPTH, &AcpiGbl_StateCache);
84 1.1.1.2.4.2 rmind if (ACPI_FAILURE (Status))
85 1.1.1.2.4.2 rmind {
86 1.1.1.2.4.2 rmind return (Status);
87 1.1.1.2.4.2 rmind }
88 1.1.1.2.4.2 rmind
89 1.1.1.2.4.2 rmind Status = AcpiOsCreateCache ("Acpi-Parse", sizeof (ACPI_PARSE_OBJ_COMMON),
90 1.1.1.2.4.2 rmind ACPI_MAX_PARSE_CACHE_DEPTH, &AcpiGbl_PsNodeCache);
91 1.1.1.2.4.2 rmind if (ACPI_FAILURE (Status))
92 1.1.1.2.4.2 rmind {
93 1.1.1.2.4.2 rmind return (Status);
94 1.1.1.2.4.2 rmind }
95 1.1.1.2.4.2 rmind
96 1.1.1.2.4.2 rmind Status = AcpiOsCreateCache ("Acpi-ParseExt", sizeof (ACPI_PARSE_OBJ_NAMED),
97 1.1.1.2.4.2 rmind ACPI_MAX_EXTPARSE_CACHE_DEPTH, &AcpiGbl_PsNodeExtCache);
98 1.1.1.2.4.2 rmind if (ACPI_FAILURE (Status))
99 1.1.1.2.4.2 rmind {
100 1.1.1.2.4.2 rmind return (Status);
101 1.1.1.2.4.2 rmind }
102 1.1.1.2.4.2 rmind
103 1.1.1.2.4.2 rmind Status = AcpiOsCreateCache ("Acpi-Operand", sizeof (ACPI_OPERAND_OBJECT),
104 1.1.1.2.4.2 rmind ACPI_MAX_OBJECT_CACHE_DEPTH, &AcpiGbl_OperandCache);
105 1.1.1.2.4.2 rmind if (ACPI_FAILURE (Status))
106 1.1.1.2.4.2 rmind {
107 1.1.1.2.4.2 rmind return (Status);
108 1.1.1.2.4.2 rmind }
109 1.1.1.2.4.2 rmind
110 1.1.1.2.4.2 rmind
111 1.1.1.2.4.2 rmind #ifdef ACPI_DBG_TRACK_ALLOCATIONS
112 1.1.1.2.4.2 rmind
113 1.1.1.2.4.2 rmind /* Memory allocation lists */
114 1.1.1.2.4.2 rmind
115 1.1.1.2.4.2 rmind Status = AcpiUtCreateList ("Acpi-Global", 0,
116 1.1.1.2.4.2 rmind &AcpiGbl_GlobalList);
117 1.1.1.2.4.2 rmind if (ACPI_FAILURE (Status))
118 1.1.1.2.4.2 rmind {
119 1.1.1.2.4.2 rmind return (Status);
120 1.1.1.2.4.2 rmind }
121 1.1.1.2.4.2 rmind
122 1.1.1.2.4.2 rmind Status = AcpiUtCreateList ("Acpi-Namespace", sizeof (ACPI_NAMESPACE_NODE),
123 1.1.1.2.4.2 rmind &AcpiGbl_NsNodeList);
124 1.1.1.2.4.2 rmind if (ACPI_FAILURE (Status))
125 1.1.1.2.4.2 rmind {
126 1.1.1.2.4.2 rmind return (Status);
127 1.1.1.2.4.2 rmind }
128 1.1.1.2.4.2 rmind #endif
129 1.1.1.2.4.2 rmind
130 1.1.1.2.4.2 rmind return (AE_OK);
131 1.1.1.2.4.2 rmind }
132 1.1.1.2.4.2 rmind
133 1.1.1.2.4.2 rmind
134 1.1.1.2.4.2 rmind /*******************************************************************************
135 1.1.1.2.4.2 rmind *
136 1.1.1.2.4.2 rmind * FUNCTION: AcpiUtDeleteCaches
137 1.1.1.2.4.2 rmind *
138 1.1.1.2.4.2 rmind * PARAMETERS: None
139 1.1.1.2.4.2 rmind *
140 1.1.1.2.4.2 rmind * RETURN: Status
141 1.1.1.2.4.2 rmind *
142 1.1.1.2.4.2 rmind * DESCRIPTION: Purge and delete all local caches
143 1.1.1.2.4.2 rmind *
144 1.1.1.2.4.2 rmind ******************************************************************************/
145 1.1.1.2.4.2 rmind
146 1.1.1.2.4.2 rmind ACPI_STATUS
147 1.1.1.2.4.2 rmind AcpiUtDeleteCaches (
148 1.1.1.2.4.2 rmind void)
149 1.1.1.2.4.2 rmind {
150 1.1.1.2.4.2 rmind #ifdef ACPI_DBG_TRACK_ALLOCATIONS
151 1.1.1.2.4.2 rmind char Buffer[7];
152 1.1.1.2.4.2 rmind
153 1.1.1.2.4.2 rmind if (AcpiGbl_DisplayFinalMemStats)
154 1.1.1.2.4.2 rmind {
155 1.1.1.2.4.2 rmind ACPI_STRCPY (Buffer, "MEMORY");
156 1.1.1.2.4.2 rmind (void) AcpiDbDisplayStatistics (Buffer);
157 1.1.1.2.4.2 rmind }
158 1.1.1.2.4.2 rmind #endif
159 1.1.1.2.4.2 rmind
160 1.1.1.2.4.2 rmind (void) AcpiOsDeleteCache (AcpiGbl_NamespaceCache);
161 1.1.1.2.4.2 rmind AcpiGbl_NamespaceCache = NULL;
162 1.1.1.2.4.2 rmind
163 1.1.1.2.4.2 rmind (void) AcpiOsDeleteCache (AcpiGbl_StateCache);
164 1.1.1.2.4.2 rmind AcpiGbl_StateCache = NULL;
165 1.1.1.2.4.2 rmind
166 1.1.1.2.4.2 rmind (void) AcpiOsDeleteCache (AcpiGbl_OperandCache);
167 1.1.1.2.4.2 rmind AcpiGbl_OperandCache = NULL;
168 1.1.1.2.4.2 rmind
169 1.1.1.2.4.2 rmind (void) AcpiOsDeleteCache (AcpiGbl_PsNodeCache);
170 1.1.1.2.4.2 rmind AcpiGbl_PsNodeCache = NULL;
171 1.1.1.2.4.2 rmind
172 1.1.1.2.4.2 rmind (void) AcpiOsDeleteCache (AcpiGbl_PsNodeExtCache);
173 1.1.1.2.4.2 rmind AcpiGbl_PsNodeExtCache = NULL;
174 1.1.1.2.4.2 rmind
175 1.1.1.2.4.2 rmind
176 1.1.1.2.4.2 rmind #ifdef ACPI_DBG_TRACK_ALLOCATIONS
177 1.1.1.2.4.2 rmind
178 1.1.1.2.4.2 rmind /* Debug only - display leftover memory allocation, if any */
179 1.1.1.2.4.2 rmind
180 1.1.1.2.4.2 rmind AcpiUtDumpAllocations (ACPI_UINT32_MAX, NULL);
181 1.1.1.2.4.2 rmind
182 1.1.1.2.4.2 rmind /* Free memory lists */
183 1.1.1.2.4.2 rmind
184 1.1.1.2.4.2 rmind AcpiOsFree (AcpiGbl_GlobalList);
185 1.1.1.2.4.2 rmind AcpiGbl_GlobalList = NULL;
186 1.1.1.2.4.2 rmind
187 1.1.1.2.4.2 rmind AcpiOsFree (AcpiGbl_NsNodeList);
188 1.1.1.2.4.2 rmind AcpiGbl_NsNodeList = NULL;
189 1.1.1.2.4.2 rmind #endif
190 1.1.1.2.4.2 rmind
191 1.1.1.2.4.2 rmind return (AE_OK);
192 1.1.1.2.4.2 rmind }
193 1.1.1.2.4.2 rmind
194 1.1.1.2.4.2 rmind
195 1.1.1.2.4.2 rmind /*******************************************************************************
196 1.1.1.2.4.2 rmind *
197 1.1.1.2.4.2 rmind * FUNCTION: AcpiUtValidateBuffer
198 1.1.1.2.4.2 rmind *
199 1.1.1.2.4.2 rmind * PARAMETERS: Buffer - Buffer descriptor to be validated
200 1.1.1.2.4.2 rmind *
201 1.1.1.2.4.2 rmind * RETURN: Status
202 1.1.1.2.4.2 rmind *
203 1.1.1.2.4.2 rmind * DESCRIPTION: Perform parameter validation checks on an ACPI_BUFFER
204 1.1.1.2.4.2 rmind *
205 1.1.1.2.4.2 rmind ******************************************************************************/
206 1.1.1.2.4.2 rmind
207 1.1.1.2.4.2 rmind ACPI_STATUS
208 1.1.1.2.4.2 rmind AcpiUtValidateBuffer (
209 1.1.1.2.4.2 rmind ACPI_BUFFER *Buffer)
210 1.1.1.2.4.2 rmind {
211 1.1.1.2.4.2 rmind
212 1.1.1.2.4.2 rmind /* Obviously, the structure pointer must be valid */
213 1.1.1.2.4.2 rmind
214 1.1.1.2.4.2 rmind if (!Buffer)
215 1.1.1.2.4.2 rmind {
216 1.1.1.2.4.2 rmind return (AE_BAD_PARAMETER);
217 1.1.1.2.4.2 rmind }
218 1.1.1.2.4.2 rmind
219 1.1.1.2.4.2 rmind /* Special semantics for the length */
220 1.1.1.2.4.2 rmind
221 1.1.1.2.4.2 rmind if ((Buffer->Length == ACPI_NO_BUFFER) ||
222 1.1.1.2.4.2 rmind (Buffer->Length == ACPI_ALLOCATE_BUFFER) ||
223 1.1.1.2.4.2 rmind (Buffer->Length == ACPI_ALLOCATE_LOCAL_BUFFER))
224 1.1.1.2.4.2 rmind {
225 1.1.1.2.4.2 rmind return (AE_OK);
226 1.1.1.2.4.2 rmind }
227 1.1.1.2.4.2 rmind
228 1.1.1.2.4.2 rmind /* Length is valid, the buffer pointer must be also */
229 1.1.1.2.4.2 rmind
230 1.1.1.2.4.2 rmind if (!Buffer->Pointer)
231 1.1.1.2.4.2 rmind {
232 1.1.1.2.4.2 rmind return (AE_BAD_PARAMETER);
233 1.1.1.2.4.2 rmind }
234 1.1.1.2.4.2 rmind
235 1.1.1.2.4.2 rmind return (AE_OK);
236 1.1.1.2.4.2 rmind }
237 1.1.1.2.4.2 rmind
238 1.1.1.2.4.2 rmind
239 1.1.1.2.4.2 rmind /*******************************************************************************
240 1.1.1.2.4.2 rmind *
241 1.1.1.2.4.2 rmind * FUNCTION: AcpiUtInitializeBuffer
242 1.1.1.2.4.2 rmind *
243 1.1.1.2.4.2 rmind * PARAMETERS: Buffer - Buffer to be validated
244 1.1.1.2.4.2 rmind * RequiredLength - Length needed
245 1.1.1.2.4.2 rmind *
246 1.1.1.2.4.2 rmind * RETURN: Status
247 1.1.1.2.4.2 rmind *
248 1.1.1.2.4.2 rmind * DESCRIPTION: Validate that the buffer is of the required length or
249 1.1.1.2.4.2 rmind * allocate a new buffer. Returned buffer is always zeroed.
250 1.1.1.2.4.2 rmind *
251 1.1.1.2.4.2 rmind ******************************************************************************/
252 1.1.1.2.4.2 rmind
253 1.1.1.2.4.2 rmind ACPI_STATUS
254 1.1.1.2.4.2 rmind AcpiUtInitializeBuffer (
255 1.1.1.2.4.2 rmind ACPI_BUFFER *Buffer,
256 1.1.1.2.4.2 rmind ACPI_SIZE RequiredLength)
257 1.1.1.2.4.2 rmind {
258 1.1.1.2.4.2 rmind ACPI_SIZE InputBufferLength;
259 1.1.1.2.4.2 rmind
260 1.1.1.2.4.2 rmind
261 1.1.1.2.4.2 rmind /* Parameter validation */
262 1.1.1.2.4.2 rmind
263 1.1.1.2.4.2 rmind if (!Buffer || !RequiredLength)
264 1.1.1.2.4.2 rmind {
265 1.1.1.2.4.2 rmind return (AE_BAD_PARAMETER);
266 1.1.1.2.4.2 rmind }
267 1.1.1.2.4.2 rmind
268 1.1.1.2.4.2 rmind /*
269 1.1.1.2.4.2 rmind * Buffer->Length is used as both an input and output parameter. Get the
270 1.1.1.2.4.2 rmind * input actual length and set the output required buffer length.
271 1.1.1.2.4.2 rmind */
272 1.1.1.2.4.2 rmind InputBufferLength = Buffer->Length;
273 1.1.1.2.4.2 rmind Buffer->Length = RequiredLength;
274 1.1.1.2.4.2 rmind
275 1.1.1.2.4.2 rmind /*
276 1.1.1.2.4.2 rmind * The input buffer length contains the actual buffer length, or the type
277 1.1.1.2.4.2 rmind * of buffer to be allocated by this routine.
278 1.1.1.2.4.2 rmind */
279 1.1.1.2.4.2 rmind switch (InputBufferLength)
280 1.1.1.2.4.2 rmind {
281 1.1.1.2.4.2 rmind case ACPI_NO_BUFFER:
282 1.1.1.2.4.2 rmind
283 1.1.1.2.4.2 rmind /* Return the exception (and the required buffer length) */
284 1.1.1.2.4.2 rmind
285 1.1.1.2.4.2 rmind return (AE_BUFFER_OVERFLOW);
286 1.1.1.2.4.2 rmind
287 1.1.1.2.4.2 rmind case ACPI_ALLOCATE_BUFFER:
288 1.1.1.2.4.2 rmind
289 1.1.1.2.4.2 rmind /* Allocate a new buffer */
290 1.1.1.2.4.2 rmind
291 1.1.1.2.4.2 rmind Buffer->Pointer = AcpiOsAllocate (RequiredLength);
292 1.1.1.2.4.2 rmind break;
293 1.1.1.2.4.2 rmind
294 1.1.1.2.4.2 rmind case ACPI_ALLOCATE_LOCAL_BUFFER:
295 1.1.1.2.4.2 rmind
296 1.1.1.2.4.2 rmind /* Allocate a new buffer with local interface to allow tracking */
297 1.1.1.2.4.2 rmind
298 1.1.1.2.4.2 rmind Buffer->Pointer = ACPI_ALLOCATE (RequiredLength);
299 1.1.1.2.4.2 rmind break;
300 1.1.1.2.4.2 rmind
301 1.1.1.2.4.2 rmind default:
302 1.1.1.2.4.2 rmind
303 1.1.1.2.4.2 rmind /* Existing buffer: Validate the size of the buffer */
304 1.1.1.2.4.2 rmind
305 1.1.1.2.4.2 rmind if (InputBufferLength < RequiredLength)
306 1.1.1.2.4.2 rmind {
307 1.1.1.2.4.2 rmind return (AE_BUFFER_OVERFLOW);
308 1.1.1.2.4.2 rmind }
309 1.1.1.2.4.2 rmind break;
310 1.1.1.2.4.2 rmind }
311 1.1.1.2.4.2 rmind
312 1.1.1.2.4.2 rmind /* Validate allocation from above or input buffer pointer */
313 1.1.1.2.4.2 rmind
314 1.1.1.2.4.2 rmind if (!Buffer->Pointer)
315 1.1.1.2.4.2 rmind {
316 1.1.1.2.4.2 rmind return (AE_NO_MEMORY);
317 1.1.1.2.4.2 rmind }
318 1.1.1.2.4.2 rmind
319 1.1.1.2.4.2 rmind /* Have a valid buffer, clear it */
320 1.1.1.2.4.2 rmind
321 1.1.1.2.4.2 rmind ACPI_MEMSET (Buffer->Pointer, 0, RequiredLength);
322 1.1.1.2.4.2 rmind return (AE_OK);
323 1.1.1.2.4.2 rmind }
324 1.1.1.2.4.2 rmind
325 1.1.1.2.4.2 rmind
326 1.1.1.2.4.2 rmind /*******************************************************************************
327 1.1.1.2.4.2 rmind *
328 1.1.1.2.4.2 rmind * FUNCTION: AcpiUtAllocate
329 1.1.1.2.4.2 rmind *
330 1.1.1.2.4.2 rmind * PARAMETERS: Size - Size of the allocation
331 1.1.1.2.4.2 rmind * Component - Component type of caller
332 1.1.1.2.4.2 rmind * Module - Source file name of caller
333 1.1.1.2.4.2 rmind * Line - Line number of caller
334 1.1.1.2.4.2 rmind *
335 1.1.1.2.4.2 rmind * RETURN: Address of the allocated memory on success, NULL on failure.
336 1.1.1.2.4.2 rmind *
337 1.1.1.2.4.2 rmind * DESCRIPTION: Subsystem equivalent of malloc.
338 1.1.1.2.4.2 rmind *
339 1.1.1.2.4.2 rmind ******************************************************************************/
340 1.1.1.2.4.2 rmind
341 1.1.1.2.4.2 rmind void *
342 1.1.1.2.4.2 rmind AcpiUtAllocate (
343 1.1.1.2.4.2 rmind ACPI_SIZE Size,
344 1.1.1.2.4.2 rmind UINT32 Component,
345 1.1.1.2.4.2 rmind const char *Module,
346 1.1.1.2.4.2 rmind UINT32 Line)
347 1.1.1.2.4.2 rmind {
348 1.1.1.2.4.2 rmind void *Allocation;
349 1.1.1.2.4.2 rmind
350 1.1.1.2.4.2 rmind
351 1.1.1.2.4.2 rmind ACPI_FUNCTION_TRACE_U32 (UtAllocate, Size);
352 1.1.1.2.4.2 rmind
353 1.1.1.2.4.2 rmind
354 1.1.1.2.4.2 rmind /* Check for an inadvertent size of zero bytes */
355 1.1.1.2.4.2 rmind
356 1.1.1.2.4.2 rmind if (!Size)
357 1.1.1.2.4.2 rmind {
358 1.1.1.2.4.2 rmind ACPI_WARNING ((Module, Line,
359 1.1.1.2.4.2 rmind "Attempt to allocate zero bytes, allocating 1 byte"));
360 1.1.1.2.4.2 rmind Size = 1;
361 1.1.1.2.4.2 rmind }
362 1.1.1.2.4.2 rmind
363 1.1.1.2.4.2 rmind Allocation = AcpiOsAllocate (Size);
364 1.1.1.2.4.2 rmind if (!Allocation)
365 1.1.1.2.4.2 rmind {
366 1.1.1.2.4.2 rmind /* Report allocation error */
367 1.1.1.2.4.2 rmind
368 1.1.1.2.4.2 rmind ACPI_WARNING ((Module, Line,
369 1.1.1.2.4.2 rmind "Could not allocate size %u", (UINT32) Size));
370 1.1.1.2.4.2 rmind
371 1.1.1.2.4.2 rmind return_PTR (NULL);
372 1.1.1.2.4.2 rmind }
373 1.1.1.2.4.2 rmind
374 1.1.1.2.4.2 rmind return_PTR (Allocation);
375 1.1.1.2.4.2 rmind }
376 1.1.1.2.4.2 rmind
377 1.1.1.2.4.2 rmind
378 1.1.1.2.4.2 rmind /*******************************************************************************
379 1.1.1.2.4.2 rmind *
380 1.1.1.2.4.2 rmind * FUNCTION: AcpiUtAllocateZeroed
381 1.1.1.2.4.2 rmind *
382 1.1.1.2.4.2 rmind * PARAMETERS: Size - Size of the allocation
383 1.1.1.2.4.2 rmind * Component - Component type of caller
384 1.1.1.2.4.2 rmind * Module - Source file name of caller
385 1.1.1.2.4.2 rmind * Line - Line number of caller
386 1.1.1.2.4.2 rmind *
387 1.1.1.2.4.2 rmind * RETURN: Address of the allocated memory on success, NULL on failure.
388 1.1.1.2.4.2 rmind *
389 1.1.1.2.4.2 rmind * DESCRIPTION: Subsystem equivalent of calloc. Allocate and zero memory.
390 1.1.1.2.4.2 rmind *
391 1.1.1.2.4.2 rmind ******************************************************************************/
392 1.1.1.2.4.2 rmind
393 1.1.1.2.4.2 rmind void *
394 1.1.1.2.4.2 rmind AcpiUtAllocateZeroed (
395 1.1.1.2.4.2 rmind ACPI_SIZE Size,
396 1.1.1.2.4.2 rmind UINT32 Component,
397 1.1.1.2.4.2 rmind const char *Module,
398 1.1.1.2.4.2 rmind UINT32 Line)
399 1.1.1.2.4.2 rmind {
400 1.1.1.2.4.2 rmind void *Allocation;
401 1.1.1.2.4.2 rmind
402 1.1.1.2.4.2 rmind
403 1.1.1.2.4.2 rmind ACPI_FUNCTION_ENTRY ();
404 1.1.1.2.4.2 rmind
405 1.1.1.2.4.2 rmind
406 1.1.1.2.4.2 rmind Allocation = AcpiUtAllocate (Size, Component, Module, Line);
407 1.1.1.2.4.2 rmind if (Allocation)
408 1.1.1.2.4.2 rmind {
409 1.1.1.2.4.2 rmind /* Clear the memory block */
410 1.1.1.2.4.2 rmind
411 1.1.1.2.4.2 rmind ACPI_MEMSET (Allocation, 0, Size);
412 1.1.1.2.4.2 rmind }
413 1.1.1.2.4.2 rmind
414 1.1.1.2.4.2 rmind return (Allocation);
415 1.1.1.2.4.2 rmind }
416 1.1.1.2.4.2 rmind
417