17bcb6cafSSascha Wildner /******************************************************************************
27bcb6cafSSascha Wildner *
37bcb6cafSSascha Wildner * Module Name: aslallocate -- Local memory allocation
47bcb6cafSSascha Wildner *
57bcb6cafSSascha Wildner *****************************************************************************/
67bcb6cafSSascha Wildner
77bcb6cafSSascha Wildner /******************************************************************************
87bcb6cafSSascha Wildner *
97bcb6cafSSascha Wildner * 1. Copyright Notice
107bcb6cafSSascha Wildner *
11383048acSSascha Wildner * Some or all of this work - Copyright (c) 1999 - 2021, Intel Corp.
127bcb6cafSSascha Wildner * All rights reserved.
137bcb6cafSSascha Wildner *
147bcb6cafSSascha Wildner * 2. License
157bcb6cafSSascha Wildner *
167bcb6cafSSascha Wildner * 2.1. This is your license from Intel Corp. under its intellectual property
177bcb6cafSSascha Wildner * rights. You may have additional license terms from the party that provided
187bcb6cafSSascha Wildner * you this software, covering your right to use that party's intellectual
197bcb6cafSSascha Wildner * property rights.
207bcb6cafSSascha Wildner *
217bcb6cafSSascha Wildner * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
227bcb6cafSSascha Wildner * copy of the source code appearing in this file ("Covered Code") an
237bcb6cafSSascha Wildner * irrevocable, perpetual, worldwide license under Intel's copyrights in the
247bcb6cafSSascha Wildner * base code distributed originally by Intel ("Original Intel Code") to copy,
257bcb6cafSSascha Wildner * make derivatives, distribute, use and display any portion of the Covered
267bcb6cafSSascha Wildner * Code in any form, with the right to sublicense such rights; and
277bcb6cafSSascha Wildner *
287bcb6cafSSascha Wildner * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
297bcb6cafSSascha Wildner * license (with the right to sublicense), under only those claims of Intel
307bcb6cafSSascha Wildner * patents that are infringed by the Original Intel Code, to make, use, sell,
317bcb6cafSSascha Wildner * offer to sell, and import the Covered Code and derivative works thereof
327bcb6cafSSascha Wildner * solely to the minimum extent necessary to exercise the above copyright
337bcb6cafSSascha Wildner * license, and in no event shall the patent license extend to any additions
347bcb6cafSSascha Wildner * to or modifications of the Original Intel Code. No other license or right
357bcb6cafSSascha Wildner * is granted directly or by implication, estoppel or otherwise;
367bcb6cafSSascha Wildner *
377bcb6cafSSascha Wildner * The above copyright and patent license is granted only if the following
387bcb6cafSSascha Wildner * conditions are met:
397bcb6cafSSascha Wildner *
407bcb6cafSSascha Wildner * 3. Conditions
417bcb6cafSSascha Wildner *
427bcb6cafSSascha Wildner * 3.1. Redistribution of Source with Rights to Further Distribute Source.
437bcb6cafSSascha Wildner * Redistribution of source code of any substantial portion of the Covered
447bcb6cafSSascha Wildner * Code or modification with rights to further distribute source must include
457bcb6cafSSascha Wildner * the above Copyright Notice, the above License, this list of Conditions,
467bcb6cafSSascha Wildner * and the following Disclaimer and Export Compliance provision. In addition,
477bcb6cafSSascha Wildner * Licensee must cause all Covered Code to which Licensee contributes to
487bcb6cafSSascha Wildner * contain a file documenting the changes Licensee made to create that Covered
497bcb6cafSSascha Wildner * Code and the date of any change. Licensee must include in that file the
507bcb6cafSSascha Wildner * documentation of any changes made by any predecessor Licensee. Licensee
517bcb6cafSSascha Wildner * must include a prominent statement that the modification is derived,
527bcb6cafSSascha Wildner * directly or indirectly, from Original Intel Code.
537bcb6cafSSascha Wildner *
547bcb6cafSSascha Wildner * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
557bcb6cafSSascha Wildner * Redistribution of source code of any substantial portion of the Covered
567bcb6cafSSascha Wildner * Code or modification without rights to further distribute source must
577bcb6cafSSascha Wildner * include the following Disclaimer and Export Compliance provision in the
587bcb6cafSSascha Wildner * documentation and/or other materials provided with distribution. In
597bcb6cafSSascha Wildner * addition, Licensee may not authorize further sublicense of source of any
607bcb6cafSSascha Wildner * portion of the Covered Code, and must include terms to the effect that the
617bcb6cafSSascha Wildner * license from Licensee to its licensee is limited to the intellectual
627bcb6cafSSascha Wildner * property embodied in the software Licensee provides to its licensee, and
637bcb6cafSSascha Wildner * not to intellectual property embodied in modifications its licensee may
647bcb6cafSSascha Wildner * make.
657bcb6cafSSascha Wildner *
667bcb6cafSSascha Wildner * 3.3. Redistribution of Executable. Redistribution in executable form of any
677bcb6cafSSascha Wildner * substantial portion of the Covered Code or modification must reproduce the
687bcb6cafSSascha Wildner * above Copyright Notice, and the following Disclaimer and Export Compliance
697bcb6cafSSascha Wildner * provision in the documentation and/or other materials provided with the
707bcb6cafSSascha Wildner * distribution.
717bcb6cafSSascha Wildner *
727bcb6cafSSascha Wildner * 3.4. Intel retains all right, title, and interest in and to the Original
737bcb6cafSSascha Wildner * Intel Code.
747bcb6cafSSascha Wildner *
757bcb6cafSSascha Wildner * 3.5. Neither the name Intel nor any other trademark owned or controlled by
767bcb6cafSSascha Wildner * Intel shall be used in advertising or otherwise to promote the sale, use or
777bcb6cafSSascha Wildner * other dealings in products derived from or relating to the Covered Code
787bcb6cafSSascha Wildner * without prior written authorization from Intel.
797bcb6cafSSascha Wildner *
807bcb6cafSSascha Wildner * 4. Disclaimer and Export Compliance
817bcb6cafSSascha Wildner *
827bcb6cafSSascha Wildner * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
837bcb6cafSSascha Wildner * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
847bcb6cafSSascha Wildner * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
857bcb6cafSSascha Wildner * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
867bcb6cafSSascha Wildner * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
877bcb6cafSSascha Wildner * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
887bcb6cafSSascha Wildner * PARTICULAR PURPOSE.
897bcb6cafSSascha Wildner *
907bcb6cafSSascha Wildner * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
917bcb6cafSSascha Wildner * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
927bcb6cafSSascha Wildner * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
937bcb6cafSSascha Wildner * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
947bcb6cafSSascha Wildner * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
957bcb6cafSSascha Wildner * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
967bcb6cafSSascha Wildner * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
977bcb6cafSSascha Wildner * LIMITED REMEDY.
987bcb6cafSSascha Wildner *
997bcb6cafSSascha Wildner * 4.3. Licensee shall not export, either directly or indirectly, any of this
1007bcb6cafSSascha Wildner * software or system incorporating such software without first obtaining any
1017bcb6cafSSascha Wildner * required license or other approval from the U. S. Department of Commerce or
1027bcb6cafSSascha Wildner * any other agency or department of the United States Government. In the
1037bcb6cafSSascha Wildner * event Licensee exports any such software from the United States or
1047bcb6cafSSascha Wildner * re-exports any such software from a foreign destination, Licensee shall
1057bcb6cafSSascha Wildner * ensure that the distribution and export/re-export of the software is in
1067bcb6cafSSascha Wildner * compliance with all laws, regulations, orders, or other restrictions of the
1077bcb6cafSSascha Wildner * U.S. Export Administration Regulations. Licensee agrees that neither it nor
1087bcb6cafSSascha Wildner * any of its subsidiaries will export/re-export any technical data, process,
1097bcb6cafSSascha Wildner * software, or service, directly or indirectly, to any country for which the
1107bcb6cafSSascha Wildner * United States government or any agency thereof requires an export license,
1117bcb6cafSSascha Wildner * other governmental approval, or letter of assurance, without first obtaining
1127bcb6cafSSascha Wildner * such license, approval or letter.
1137bcb6cafSSascha Wildner *
1147bcb6cafSSascha Wildner *****************************************************************************
1157bcb6cafSSascha Wildner *
1167bcb6cafSSascha Wildner * Alternatively, you may choose to be licensed under the terms of the
1177bcb6cafSSascha Wildner * following license:
1187bcb6cafSSascha Wildner *
1197bcb6cafSSascha Wildner * Redistribution and use in source and binary forms, with or without
1207bcb6cafSSascha Wildner * modification, are permitted provided that the following conditions
1217bcb6cafSSascha Wildner * are met:
1227bcb6cafSSascha Wildner * 1. Redistributions of source code must retain the above copyright
1237bcb6cafSSascha Wildner * notice, this list of conditions, and the following disclaimer,
1247bcb6cafSSascha Wildner * without modification.
1257bcb6cafSSascha Wildner * 2. Redistributions in binary form must reproduce at minimum a disclaimer
1267bcb6cafSSascha Wildner * substantially similar to the "NO WARRANTY" disclaimer below
1277bcb6cafSSascha Wildner * ("Disclaimer") and any redistribution must be conditioned upon
1287bcb6cafSSascha Wildner * including a substantially similar Disclaimer requirement for further
1297bcb6cafSSascha Wildner * binary redistribution.
1307bcb6cafSSascha Wildner * 3. Neither the names of the above-listed copyright holders nor the names
1317bcb6cafSSascha Wildner * of any contributors may be used to endorse or promote products derived
1327bcb6cafSSascha Wildner * from this software without specific prior written permission.
1337bcb6cafSSascha Wildner *
1347bcb6cafSSascha Wildner * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
1357bcb6cafSSascha Wildner * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
1367bcb6cafSSascha Wildner * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
1377bcb6cafSSascha Wildner * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
1387bcb6cafSSascha Wildner * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
1397bcb6cafSSascha Wildner * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
1407bcb6cafSSascha Wildner * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
1417bcb6cafSSascha Wildner * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
1427bcb6cafSSascha Wildner * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
1437bcb6cafSSascha Wildner * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
1447bcb6cafSSascha Wildner * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1457bcb6cafSSascha Wildner *
1467bcb6cafSSascha Wildner * Alternatively, you may choose to be licensed under the terms of the
1477bcb6cafSSascha Wildner * GNU General Public License ("GPL") version 2 as published by the Free
1487bcb6cafSSascha Wildner * Software Foundation.
1497bcb6cafSSascha Wildner *
1507bcb6cafSSascha Wildner *****************************************************************************/
1517bcb6cafSSascha Wildner
1527bcb6cafSSascha Wildner #include "aslcompiler.h"
1537bcb6cafSSascha Wildner
1547bcb6cafSSascha Wildner /*
1557bcb6cafSSascha Wildner * Local heap allocation wrappers. See aslcache.c for allocation from local
156*01d5d5dfSSascha Wildner * cache allocations
1577bcb6cafSSascha Wildner */
1587bcb6cafSSascha Wildner
1597bcb6cafSSascha Wildner
1607bcb6cafSSascha Wildner /*******************************************************************************
1617bcb6cafSSascha Wildner *
1627bcb6cafSSascha Wildner * FUNCTION: UtLocalCalloc
1637bcb6cafSSascha Wildner *
1647bcb6cafSSascha Wildner * PARAMETERS: Size - Bytes to be allocated
1657bcb6cafSSascha Wildner *
1667bcb6cafSSascha Wildner * RETURN: Pointer to the allocated memory. If this function returns
1677bcb6cafSSascha Wildner * (the compiler is not aborted), the pointer is guaranteed to
1687bcb6cafSSascha Wildner * be valid.
1697bcb6cafSSascha Wildner *
1707bcb6cafSSascha Wildner * DESCRIPTION: Allocate zero-initialized memory. The point of this function
1717bcb6cafSSascha Wildner * is to abort the compile on an allocation failure, on the
1727bcb6cafSSascha Wildner * assumption that nothing more can be accomplished.
1737bcb6cafSSascha Wildner *
1747bcb6cafSSascha Wildner * NOTE: For allocation from the local caches, see aslcache.c
1757bcb6cafSSascha Wildner *
1767bcb6cafSSascha Wildner ******************************************************************************/
1777bcb6cafSSascha Wildner
1787bcb6cafSSascha Wildner void *
UtLocalCalloc(UINT32 Size)1797bcb6cafSSascha Wildner UtLocalCalloc (
1807bcb6cafSSascha Wildner UINT32 Size)
1817bcb6cafSSascha Wildner {
1827bcb6cafSSascha Wildner void *Allocated;
1837bcb6cafSSascha Wildner
1847bcb6cafSSascha Wildner
1857bcb6cafSSascha Wildner Allocated = ACPI_ALLOCATE_ZEROED (Size);
1867bcb6cafSSascha Wildner if (!Allocated)
1877bcb6cafSSascha Wildner {
1887bcb6cafSSascha Wildner AslCommonError (ASL_ERROR, ASL_MSG_MEMORY_ALLOCATION,
189806343b9SSascha Wildner AslGbl_CurrentLineNumber, AslGbl_LogicalLineNumber,
190806343b9SSascha Wildner AslGbl_InputByteCount, AslGbl_CurrentColumn,
191806343b9SSascha Wildner AslGbl_Files[ASL_FILE_INPUT].Filename, NULL);
1927bcb6cafSSascha Wildner
1937bcb6cafSSascha Wildner CmCleanupAndExit ();
1947bcb6cafSSascha Wildner exit (1);
1957bcb6cafSSascha Wildner }
1967bcb6cafSSascha Wildner
197806343b9SSascha Wildner AslGbl_TotalAllocations++;
198806343b9SSascha Wildner AslGbl_TotalAllocated += Size;
1997bcb6cafSSascha Wildner return (Allocated);
2007bcb6cafSSascha Wildner }
2017bcb6cafSSascha Wildner
2027bcb6cafSSascha Wildner
2037bcb6cafSSascha Wildner /******************************************************************************
2047bcb6cafSSascha Wildner *
2057bcb6cafSSascha Wildner * FUNCTION: UtExpandLineBuffers
2067bcb6cafSSascha Wildner *
2077bcb6cafSSascha Wildner * PARAMETERS: None. Updates global line buffer pointers.
2087bcb6cafSSascha Wildner *
2097bcb6cafSSascha Wildner * RETURN: None. Reallocates the global line buffers
2107bcb6cafSSascha Wildner *
2117bcb6cafSSascha Wildner * DESCRIPTION: Called if the current line buffer becomes filled. Reallocates
212806343b9SSascha Wildner * all global line buffers and updates AslGbl_LineBufferSize. NOTE:
2137bcb6cafSSascha Wildner * Also used for the initial allocation of the buffers, when
2147bcb6cafSSascha Wildner * all of the buffer pointers are NULL. Initial allocations are
2157bcb6cafSSascha Wildner * of size ASL_DEFAULT_LINE_BUFFER_SIZE
2167bcb6cafSSascha Wildner *
2177bcb6cafSSascha Wildner *****************************************************************************/
2187bcb6cafSSascha Wildner
2197bcb6cafSSascha Wildner void
UtExpandLineBuffers(void)2207bcb6cafSSascha Wildner UtExpandLineBuffers (
2217bcb6cafSSascha Wildner void)
2227bcb6cafSSascha Wildner {
2237bcb6cafSSascha Wildner UINT32 NewSize;
2247bcb6cafSSascha Wildner
2257bcb6cafSSascha Wildner
2267bcb6cafSSascha Wildner /* Attempt to double the size of all line buffers */
2277bcb6cafSSascha Wildner
228806343b9SSascha Wildner NewSize = AslGbl_LineBufferSize * 2;
229806343b9SSascha Wildner if (AslGbl_CurrentLineBuffer)
2307bcb6cafSSascha Wildner {
2317bcb6cafSSascha Wildner DbgPrint (ASL_DEBUG_OUTPUT,
2327bcb6cafSSascha Wildner "Increasing line buffer size from %u to %u\n",
233806343b9SSascha Wildner AslGbl_LineBufferSize, NewSize);
2347bcb6cafSSascha Wildner }
2357bcb6cafSSascha Wildner
236806343b9SSascha Wildner UtReallocLineBuffers (&AslGbl_CurrentLineBuffer, AslGbl_LineBufferSize, NewSize);
237806343b9SSascha Wildner UtReallocLineBuffers (&AslGbl_MainTokenBuffer, AslGbl_LineBufferSize, NewSize);
238806343b9SSascha Wildner UtReallocLineBuffers (&AslGbl_MacroTokenBuffer, AslGbl_LineBufferSize, NewSize);
239806343b9SSascha Wildner UtReallocLineBuffers (&AslGbl_ExpressionTokenBuffer, AslGbl_LineBufferSize, NewSize);
2407bcb6cafSSascha Wildner
241806343b9SSascha Wildner AslGbl_LineBufPtr = AslGbl_CurrentLineBuffer;
242806343b9SSascha Wildner AslGbl_LineBufferSize = NewSize;
2437bcb6cafSSascha Wildner }
2447bcb6cafSSascha Wildner
2457bcb6cafSSascha Wildner
2467bcb6cafSSascha Wildner /******************************************************************************
2477bcb6cafSSascha Wildner *
2487bcb6cafSSascha Wildner * FUNCTION: UtReallocLineBuffers
2497bcb6cafSSascha Wildner *
2507bcb6cafSSascha Wildner * PARAMETERS: Buffer - Buffer to realloc
2517bcb6cafSSascha Wildner * OldSize - Old size of Buffer
2527bcb6cafSSascha Wildner * NewSize - New size of Buffer
2537bcb6cafSSascha Wildner *
2547bcb6cafSSascha Wildner * RETURN: none
2557bcb6cafSSascha Wildner *
2567bcb6cafSSascha Wildner * DESCRIPTION: Reallocate and initialize Buffer
2577bcb6cafSSascha Wildner *
2587bcb6cafSSascha Wildner *****************************************************************************/
2597bcb6cafSSascha Wildner
2607bcb6cafSSascha Wildner void
UtReallocLineBuffers(char ** Buffer,UINT32 OldSize,UINT32 NewSize)2617bcb6cafSSascha Wildner UtReallocLineBuffers (
2627bcb6cafSSascha Wildner char **Buffer,
2637bcb6cafSSascha Wildner UINT32 OldSize,
2647bcb6cafSSascha Wildner UINT32 NewSize)
2657bcb6cafSSascha Wildner {
2667bcb6cafSSascha Wildner
2677bcb6cafSSascha Wildner *Buffer = realloc (*Buffer, NewSize);
2687bcb6cafSSascha Wildner if (*Buffer)
2697bcb6cafSSascha Wildner {
2707bcb6cafSSascha Wildner memset (*Buffer + OldSize, 0, NewSize - OldSize);
2717bcb6cafSSascha Wildner return;
2727bcb6cafSSascha Wildner }
2737bcb6cafSSascha Wildner
2747bcb6cafSSascha Wildner printf ("Could not increase line buffer size from %u to %u\n",
2757bcb6cafSSascha Wildner OldSize, NewSize);
2767bcb6cafSSascha Wildner
2777bcb6cafSSascha Wildner AslError (ASL_ERROR, ASL_MSG_BUFFER_ALLOCATION, NULL, NULL);
2787bcb6cafSSascha Wildner AslAbort ();
2797bcb6cafSSascha Wildner }
2807bcb6cafSSascha Wildner
2817bcb6cafSSascha Wildner
2827bcb6cafSSascha Wildner /******************************************************************************
2837bcb6cafSSascha Wildner *
2847bcb6cafSSascha Wildner * FUNCTION: UtFreeLineBuffers
2857bcb6cafSSascha Wildner *
2867bcb6cafSSascha Wildner * PARAMETERS: None
2877bcb6cafSSascha Wildner *
2887bcb6cafSSascha Wildner * RETURN: None
2897bcb6cafSSascha Wildner *
2907bcb6cafSSascha Wildner * DESCRIPTION: Free all line buffers
2917bcb6cafSSascha Wildner *
2927bcb6cafSSascha Wildner *****************************************************************************/
2937bcb6cafSSascha Wildner
2947bcb6cafSSascha Wildner void
UtFreeLineBuffers(void)2957bcb6cafSSascha Wildner UtFreeLineBuffers (
2967bcb6cafSSascha Wildner void)
2977bcb6cafSSascha Wildner {
2987bcb6cafSSascha Wildner
299806343b9SSascha Wildner free (AslGbl_CurrentLineBuffer);
300806343b9SSascha Wildner free (AslGbl_MainTokenBuffer);
301806343b9SSascha Wildner free (AslGbl_MacroTokenBuffer);
302806343b9SSascha Wildner free (AslGbl_ExpressionTokenBuffer);
3037bcb6cafSSascha Wildner }
304