167d9aa44SJung-uk Kim /****************************************************************************** 267d9aa44SJung-uk Kim * 367d9aa44SJung-uk Kim * Module Name: aslallocate -- Local memory allocation 467d9aa44SJung-uk Kim * 567d9aa44SJung-uk Kim *****************************************************************************/ 667d9aa44SJung-uk Kim 767d9aa44SJung-uk Kim /****************************************************************************** 867d9aa44SJung-uk Kim * 967d9aa44SJung-uk Kim * 1. Copyright Notice 1067d9aa44SJung-uk Kim * 11*804fe266SJung-uk Kim * Some or all of this work - Copyright (c) 1999 - 2024, Intel Corp. 1267d9aa44SJung-uk Kim * All rights reserved. 1367d9aa44SJung-uk Kim * 1467d9aa44SJung-uk Kim * 2. License 1567d9aa44SJung-uk Kim * 1667d9aa44SJung-uk Kim * 2.1. This is your license from Intel Corp. under its intellectual property 1767d9aa44SJung-uk Kim * rights. You may have additional license terms from the party that provided 1867d9aa44SJung-uk Kim * you this software, covering your right to use that party's intellectual 1967d9aa44SJung-uk Kim * property rights. 2067d9aa44SJung-uk Kim * 2167d9aa44SJung-uk Kim * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a 2267d9aa44SJung-uk Kim * copy of the source code appearing in this file ("Covered Code") an 2367d9aa44SJung-uk Kim * irrevocable, perpetual, worldwide license under Intel's copyrights in the 2467d9aa44SJung-uk Kim * base code distributed originally by Intel ("Original Intel Code") to copy, 2567d9aa44SJung-uk Kim * make derivatives, distribute, use and display any portion of the Covered 2667d9aa44SJung-uk Kim * Code in any form, with the right to sublicense such rights; and 2767d9aa44SJung-uk Kim * 2867d9aa44SJung-uk Kim * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent 2967d9aa44SJung-uk Kim * license (with the right to sublicense), under only those claims of Intel 3067d9aa44SJung-uk Kim * patents that are infringed by the Original Intel Code, to make, use, sell, 3167d9aa44SJung-uk Kim * offer to sell, and import the Covered Code and derivative works thereof 3267d9aa44SJung-uk Kim * solely to the minimum extent necessary to exercise the above copyright 3367d9aa44SJung-uk Kim * license, and in no event shall the patent license extend to any additions 3467d9aa44SJung-uk Kim * to or modifications of the Original Intel Code. No other license or right 3567d9aa44SJung-uk Kim * is granted directly or by implication, estoppel or otherwise; 3667d9aa44SJung-uk Kim * 3767d9aa44SJung-uk Kim * The above copyright and patent license is granted only if the following 3867d9aa44SJung-uk Kim * conditions are met: 3967d9aa44SJung-uk Kim * 4067d9aa44SJung-uk Kim * 3. Conditions 4167d9aa44SJung-uk Kim * 4267d9aa44SJung-uk Kim * 3.1. Redistribution of Source with Rights to Further Distribute Source. 4367d9aa44SJung-uk Kim * Redistribution of source code of any substantial portion of the Covered 4467d9aa44SJung-uk Kim * Code or modification with rights to further distribute source must include 4567d9aa44SJung-uk Kim * the above Copyright Notice, the above License, this list of Conditions, 4667d9aa44SJung-uk Kim * and the following Disclaimer and Export Compliance provision. In addition, 4767d9aa44SJung-uk Kim * Licensee must cause all Covered Code to which Licensee contributes to 4867d9aa44SJung-uk Kim * contain a file documenting the changes Licensee made to create that Covered 4967d9aa44SJung-uk Kim * Code and the date of any change. Licensee must include in that file the 5067d9aa44SJung-uk Kim * documentation of any changes made by any predecessor Licensee. Licensee 5167d9aa44SJung-uk Kim * must include a prominent statement that the modification is derived, 5267d9aa44SJung-uk Kim * directly or indirectly, from Original Intel Code. 5367d9aa44SJung-uk Kim * 5467d9aa44SJung-uk Kim * 3.2. Redistribution of Source with no Rights to Further Distribute Source. 5567d9aa44SJung-uk Kim * Redistribution of source code of any substantial portion of the Covered 5667d9aa44SJung-uk Kim * Code or modification without rights to further distribute source must 5767d9aa44SJung-uk Kim * include the following Disclaimer and Export Compliance provision in the 5867d9aa44SJung-uk Kim * documentation and/or other materials provided with distribution. In 5967d9aa44SJung-uk Kim * addition, Licensee may not authorize further sublicense of source of any 6067d9aa44SJung-uk Kim * portion of the Covered Code, and must include terms to the effect that the 6167d9aa44SJung-uk Kim * license from Licensee to its licensee is limited to the intellectual 6267d9aa44SJung-uk Kim * property embodied in the software Licensee provides to its licensee, and 6367d9aa44SJung-uk Kim * not to intellectual property embodied in modifications its licensee may 6467d9aa44SJung-uk Kim * make. 6567d9aa44SJung-uk Kim * 6667d9aa44SJung-uk Kim * 3.3. Redistribution of Executable. Redistribution in executable form of any 6767d9aa44SJung-uk Kim * substantial portion of the Covered Code or modification must reproduce the 6867d9aa44SJung-uk Kim * above Copyright Notice, and the following Disclaimer and Export Compliance 6967d9aa44SJung-uk Kim * provision in the documentation and/or other materials provided with the 7067d9aa44SJung-uk Kim * distribution. 7167d9aa44SJung-uk Kim * 7267d9aa44SJung-uk Kim * 3.4. Intel retains all right, title, and interest in and to the Original 7367d9aa44SJung-uk Kim * Intel Code. 7467d9aa44SJung-uk Kim * 7567d9aa44SJung-uk Kim * 3.5. Neither the name Intel nor any other trademark owned or controlled by 7667d9aa44SJung-uk Kim * Intel shall be used in advertising or otherwise to promote the sale, use or 7767d9aa44SJung-uk Kim * other dealings in products derived from or relating to the Covered Code 7867d9aa44SJung-uk Kim * without prior written authorization from Intel. 7967d9aa44SJung-uk Kim * 8067d9aa44SJung-uk Kim * 4. Disclaimer and Export Compliance 8167d9aa44SJung-uk Kim * 8267d9aa44SJung-uk Kim * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED 8367d9aa44SJung-uk Kim * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE 8467d9aa44SJung-uk Kim * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE, 8567d9aa44SJung-uk Kim * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY 8667d9aa44SJung-uk Kim * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY 8767d9aa44SJung-uk Kim * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A 8867d9aa44SJung-uk Kim * PARTICULAR PURPOSE. 8967d9aa44SJung-uk Kim * 9067d9aa44SJung-uk Kim * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES 9167d9aa44SJung-uk Kim * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR 9267d9aa44SJung-uk Kim * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT, 9367d9aa44SJung-uk Kim * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY 9467d9aa44SJung-uk Kim * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL 9567d9aa44SJung-uk Kim * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS 9667d9aa44SJung-uk Kim * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY 9767d9aa44SJung-uk Kim * LIMITED REMEDY. 9867d9aa44SJung-uk Kim * 9967d9aa44SJung-uk Kim * 4.3. Licensee shall not export, either directly or indirectly, any of this 10067d9aa44SJung-uk Kim * software or system incorporating such software without first obtaining any 10167d9aa44SJung-uk Kim * required license or other approval from the U. S. Department of Commerce or 10267d9aa44SJung-uk Kim * any other agency or department of the United States Government. In the 10367d9aa44SJung-uk Kim * event Licensee exports any such software from the United States or 10467d9aa44SJung-uk Kim * re-exports any such software from a foreign destination, Licensee shall 10567d9aa44SJung-uk Kim * ensure that the distribution and export/re-export of the software is in 10667d9aa44SJung-uk Kim * compliance with all laws, regulations, orders, or other restrictions of the 10767d9aa44SJung-uk Kim * U.S. Export Administration Regulations. Licensee agrees that neither it nor 10867d9aa44SJung-uk Kim * any of its subsidiaries will export/re-export any technical data, process, 10967d9aa44SJung-uk Kim * software, or service, directly or indirectly, to any country for which the 11067d9aa44SJung-uk Kim * United States government or any agency thereof requires an export license, 11167d9aa44SJung-uk Kim * other governmental approval, or letter of assurance, without first obtaining 11267d9aa44SJung-uk Kim * such license, approval or letter. 11367d9aa44SJung-uk Kim * 11467d9aa44SJung-uk Kim ***************************************************************************** 11567d9aa44SJung-uk Kim * 11667d9aa44SJung-uk Kim * Alternatively, you may choose to be licensed under the terms of the 11767d9aa44SJung-uk Kim * following license: 11867d9aa44SJung-uk Kim * 11967d9aa44SJung-uk Kim * Redistribution and use in source and binary forms, with or without 12067d9aa44SJung-uk Kim * modification, are permitted provided that the following conditions 12167d9aa44SJung-uk Kim * are met: 12267d9aa44SJung-uk Kim * 1. Redistributions of source code must retain the above copyright 12367d9aa44SJung-uk Kim * notice, this list of conditions, and the following disclaimer, 12467d9aa44SJung-uk Kim * without modification. 12567d9aa44SJung-uk Kim * 2. Redistributions in binary form must reproduce at minimum a disclaimer 12667d9aa44SJung-uk Kim * substantially similar to the "NO WARRANTY" disclaimer below 12767d9aa44SJung-uk Kim * ("Disclaimer") and any redistribution must be conditioned upon 12867d9aa44SJung-uk Kim * including a substantially similar Disclaimer requirement for further 12967d9aa44SJung-uk Kim * binary redistribution. 13067d9aa44SJung-uk Kim * 3. Neither the names of the above-listed copyright holders nor the names 13167d9aa44SJung-uk Kim * of any contributors may be used to endorse or promote products derived 13267d9aa44SJung-uk Kim * from this software without specific prior written permission. 13367d9aa44SJung-uk Kim * 13467d9aa44SJung-uk Kim * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 13567d9aa44SJung-uk Kim * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 13667d9aa44SJung-uk Kim * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 13767d9aa44SJung-uk Kim * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 13867d9aa44SJung-uk Kim * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 13967d9aa44SJung-uk Kim * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 14067d9aa44SJung-uk Kim * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 14167d9aa44SJung-uk Kim * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 14267d9aa44SJung-uk Kim * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 14367d9aa44SJung-uk Kim * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 14467d9aa44SJung-uk Kim * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 14567d9aa44SJung-uk Kim * 14667d9aa44SJung-uk Kim * Alternatively, you may choose to be licensed under the terms of the 14767d9aa44SJung-uk Kim * GNU General Public License ("GPL") version 2 as published by the Free 14867d9aa44SJung-uk Kim * Software Foundation. 14967d9aa44SJung-uk Kim * 15067d9aa44SJung-uk Kim *****************************************************************************/ 15167d9aa44SJung-uk Kim 15267d9aa44SJung-uk Kim #include <contrib/dev/acpica/compiler/aslcompiler.h> 15367d9aa44SJung-uk Kim 15467d9aa44SJung-uk Kim /* 15567d9aa44SJung-uk Kim * Local heap allocation wrappers. See aslcache.c for allocation from local 156cfd1ed46SJung-uk Kim * cache allocations 15767d9aa44SJung-uk Kim */ 15867d9aa44SJung-uk Kim 15967d9aa44SJung-uk Kim 16067d9aa44SJung-uk Kim /******************************************************************************* 16167d9aa44SJung-uk Kim * 16267d9aa44SJung-uk Kim * FUNCTION: UtLocalCalloc 16367d9aa44SJung-uk Kim * 16467d9aa44SJung-uk Kim * PARAMETERS: Size - Bytes to be allocated 16567d9aa44SJung-uk Kim * 16667d9aa44SJung-uk Kim * RETURN: Pointer to the allocated memory. If this function returns 16767d9aa44SJung-uk Kim * (the compiler is not aborted), the pointer is guaranteed to 16867d9aa44SJung-uk Kim * be valid. 16967d9aa44SJung-uk Kim * 17067d9aa44SJung-uk Kim * DESCRIPTION: Allocate zero-initialized memory. The point of this function 17167d9aa44SJung-uk Kim * is to abort the compile on an allocation failure, on the 17267d9aa44SJung-uk Kim * assumption that nothing more can be accomplished. 17367d9aa44SJung-uk Kim * 17467d9aa44SJung-uk Kim * NOTE: For allocation from the local caches, see aslcache.c 17567d9aa44SJung-uk Kim * 17667d9aa44SJung-uk Kim ******************************************************************************/ 17767d9aa44SJung-uk Kim 17867d9aa44SJung-uk Kim void * 17967d9aa44SJung-uk Kim UtLocalCalloc ( 18067d9aa44SJung-uk Kim UINT32 Size) 18167d9aa44SJung-uk Kim { 18267d9aa44SJung-uk Kim void *Allocated; 18367d9aa44SJung-uk Kim 18467d9aa44SJung-uk Kim 18567d9aa44SJung-uk Kim Allocated = ACPI_ALLOCATE_ZEROED (Size); 18667d9aa44SJung-uk Kim if (!Allocated) 18767d9aa44SJung-uk Kim { 18867d9aa44SJung-uk Kim AslCommonError (ASL_ERROR, ASL_MSG_MEMORY_ALLOCATION, 1896f1f1a63SJung-uk Kim AslGbl_CurrentLineNumber, AslGbl_LogicalLineNumber, 1906f1f1a63SJung-uk Kim AslGbl_InputByteCount, AslGbl_CurrentColumn, 1916f1f1a63SJung-uk Kim AslGbl_Files[ASL_FILE_INPUT].Filename, NULL); 19267d9aa44SJung-uk Kim 19367d9aa44SJung-uk Kim CmCleanupAndExit (); 19467d9aa44SJung-uk Kim exit (1); 19567d9aa44SJung-uk Kim } 19667d9aa44SJung-uk Kim 1976f1f1a63SJung-uk Kim AslGbl_TotalAllocations++; 1986f1f1a63SJung-uk Kim AslGbl_TotalAllocated += Size; 19967d9aa44SJung-uk Kim return (Allocated); 20067d9aa44SJung-uk Kim } 20167d9aa44SJung-uk Kim 20267d9aa44SJung-uk Kim 20367d9aa44SJung-uk Kim /****************************************************************************** 20467d9aa44SJung-uk Kim * 20567d9aa44SJung-uk Kim * FUNCTION: UtExpandLineBuffers 20667d9aa44SJung-uk Kim * 20767d9aa44SJung-uk Kim * PARAMETERS: None. Updates global line buffer pointers. 20867d9aa44SJung-uk Kim * 20967d9aa44SJung-uk Kim * RETURN: None. Reallocates the global line buffers 21067d9aa44SJung-uk Kim * 21167d9aa44SJung-uk Kim * DESCRIPTION: Called if the current line buffer becomes filled. Reallocates 2126f1f1a63SJung-uk Kim * all global line buffers and updates AslGbl_LineBufferSize. NOTE: 21367d9aa44SJung-uk Kim * Also used for the initial allocation of the buffers, when 21467d9aa44SJung-uk Kim * all of the buffer pointers are NULL. Initial allocations are 21567d9aa44SJung-uk Kim * of size ASL_DEFAULT_LINE_BUFFER_SIZE 21667d9aa44SJung-uk Kim * 21767d9aa44SJung-uk Kim *****************************************************************************/ 21867d9aa44SJung-uk Kim 21967d9aa44SJung-uk Kim void 22067d9aa44SJung-uk Kim UtExpandLineBuffers ( 22167d9aa44SJung-uk Kim void) 22267d9aa44SJung-uk Kim { 22367d9aa44SJung-uk Kim UINT32 NewSize; 22467d9aa44SJung-uk Kim 22567d9aa44SJung-uk Kim 22667d9aa44SJung-uk Kim /* Attempt to double the size of all line buffers */ 22767d9aa44SJung-uk Kim 2286f1f1a63SJung-uk Kim NewSize = AslGbl_LineBufferSize * 2; 2296f1f1a63SJung-uk Kim if (AslGbl_CurrentLineBuffer) 23067d9aa44SJung-uk Kim { 23167d9aa44SJung-uk Kim DbgPrint (ASL_DEBUG_OUTPUT, 23267d9aa44SJung-uk Kim "Increasing line buffer size from %u to %u\n", 2336f1f1a63SJung-uk Kim AslGbl_LineBufferSize, NewSize); 23467d9aa44SJung-uk Kim } 23567d9aa44SJung-uk Kim 2366f1f1a63SJung-uk Kim UtReallocLineBuffers (&AslGbl_CurrentLineBuffer, AslGbl_LineBufferSize, NewSize); 2376f1f1a63SJung-uk Kim UtReallocLineBuffers (&AslGbl_MainTokenBuffer, AslGbl_LineBufferSize, NewSize); 2386f1f1a63SJung-uk Kim UtReallocLineBuffers (&AslGbl_MacroTokenBuffer, AslGbl_LineBufferSize, NewSize); 2396f1f1a63SJung-uk Kim UtReallocLineBuffers (&AslGbl_ExpressionTokenBuffer, AslGbl_LineBufferSize, NewSize); 24067d9aa44SJung-uk Kim 2416f1f1a63SJung-uk Kim AslGbl_LineBufPtr = AslGbl_CurrentLineBuffer; 2426f1f1a63SJung-uk Kim AslGbl_LineBufferSize = NewSize; 24367d9aa44SJung-uk Kim } 24467d9aa44SJung-uk Kim 24567d9aa44SJung-uk Kim 24667d9aa44SJung-uk Kim /****************************************************************************** 24767d9aa44SJung-uk Kim * 24867d9aa44SJung-uk Kim * FUNCTION: UtReallocLineBuffers 24967d9aa44SJung-uk Kim * 25067d9aa44SJung-uk Kim * PARAMETERS: Buffer - Buffer to realloc 25167d9aa44SJung-uk Kim * OldSize - Old size of Buffer 25267d9aa44SJung-uk Kim * NewSize - New size of Buffer 25367d9aa44SJung-uk Kim * 25467d9aa44SJung-uk Kim * RETURN: none 25567d9aa44SJung-uk Kim * 25667d9aa44SJung-uk Kim * DESCRIPTION: Reallocate and initialize Buffer 25767d9aa44SJung-uk Kim * 25867d9aa44SJung-uk Kim *****************************************************************************/ 25967d9aa44SJung-uk Kim 26067d9aa44SJung-uk Kim void 26167d9aa44SJung-uk Kim UtReallocLineBuffers ( 26267d9aa44SJung-uk Kim char **Buffer, 26367d9aa44SJung-uk Kim UINT32 OldSize, 26467d9aa44SJung-uk Kim UINT32 NewSize) 26567d9aa44SJung-uk Kim { 26667d9aa44SJung-uk Kim 26767d9aa44SJung-uk Kim *Buffer = realloc (*Buffer, NewSize); 26867d9aa44SJung-uk Kim if (*Buffer) 26967d9aa44SJung-uk Kim { 27067d9aa44SJung-uk Kim memset (*Buffer + OldSize, 0, NewSize - OldSize); 27167d9aa44SJung-uk Kim return; 27267d9aa44SJung-uk Kim } 27367d9aa44SJung-uk Kim 27467d9aa44SJung-uk Kim printf ("Could not increase line buffer size from %u to %u\n", 27567d9aa44SJung-uk Kim OldSize, NewSize); 27667d9aa44SJung-uk Kim 27767d9aa44SJung-uk Kim AslError (ASL_ERROR, ASL_MSG_BUFFER_ALLOCATION, NULL, NULL); 27867d9aa44SJung-uk Kim AslAbort (); 27967d9aa44SJung-uk Kim } 28067d9aa44SJung-uk Kim 28167d9aa44SJung-uk Kim 28267d9aa44SJung-uk Kim /****************************************************************************** 28367d9aa44SJung-uk Kim * 28467d9aa44SJung-uk Kim * FUNCTION: UtFreeLineBuffers 28567d9aa44SJung-uk Kim * 28667d9aa44SJung-uk Kim * PARAMETERS: None 28767d9aa44SJung-uk Kim * 28867d9aa44SJung-uk Kim * RETURN: None 28967d9aa44SJung-uk Kim * 29067d9aa44SJung-uk Kim * DESCRIPTION: Free all line buffers 29167d9aa44SJung-uk Kim * 29267d9aa44SJung-uk Kim *****************************************************************************/ 29367d9aa44SJung-uk Kim 29467d9aa44SJung-uk Kim void 29567d9aa44SJung-uk Kim UtFreeLineBuffers ( 29667d9aa44SJung-uk Kim void) 29767d9aa44SJung-uk Kim { 2986f1f1a63SJung-uk Kim free (AslGbl_CurrentLineBuffer); 299722b1667SJung-uk Kim 3006f1f1a63SJung-uk Kim free (AslGbl_MainTokenBuffer); 301722b1667SJung-uk Kim 3026f1f1a63SJung-uk Kim free (AslGbl_MacroTokenBuffer); 303722b1667SJung-uk Kim 304722b1667SJung-uk Kim free (AslGbl_MacroTokenReplaceBuffer); 305722b1667SJung-uk Kim 3066f1f1a63SJung-uk Kim free (AslGbl_ExpressionTokenBuffer); 30767d9aa44SJung-uk Kim } 308