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