mirror of
https://github.com/acpica/acpica/
synced 2025-02-23 00:44:17 +03:00
iASL: Automatically increase internal line buffer sizes.
Via realloc(), automatically increase the internal line buffer sizes as necessary to support very long source code lines. The current version of the preprocessor requires a buffer long enough to contain full source code lines. This change increases the line buffer(s) if the input lines go beyond the current buffer size. This eliminates errors that occurred when a source code line was longer than the buffer.
This commit is contained in:
parent
c24949b628
commit
54e0432053
@ -851,6 +851,10 @@ char *
|
||||
UtGetStringBuffer (
|
||||
UINT32 Length);
|
||||
|
||||
void
|
||||
UtExpandLineBuffers (
|
||||
void);
|
||||
|
||||
ACPI_STATUS
|
||||
UtInternalizeName (
|
||||
char *ExternalName,
|
||||
|
@ -146,21 +146,22 @@ extern int PrParserdebug;
|
||||
extern const ASL_MAPPING_ENTRY AslKeywordMapping[];
|
||||
extern char *AslCompilertext;
|
||||
|
||||
#define ASL_LINE_BUFFER_SIZE (4096 * 4) /* 16K */
|
||||
#define ASL_MSG_BUFFER_SIZE 4096
|
||||
#define HEX_TABLE_LINE_SIZE 8
|
||||
#define HEX_LISTING_LINE_SIZE 8
|
||||
#define ASL_DEFAULT_LINE_BUFFER_SIZE (1024 * 32) /* 32K */
|
||||
#define ASL_MSG_BUFFER_SIZE 4096
|
||||
#define HEX_TABLE_LINE_SIZE 8
|
||||
#define HEX_LISTING_LINE_SIZE 8
|
||||
|
||||
|
||||
/* Source code buffers and pointers for error reporting */
|
||||
|
||||
ASL_EXTERN char Gbl_CurrentLineBuffer[ASL_LINE_BUFFER_SIZE];
|
||||
ASL_EXTERN char ASL_INIT_GLOBAL (*Gbl_CurrentLineBuffer, NULL);
|
||||
ASL_EXTERN char ASL_INIT_GLOBAL (*Gbl_LineBufPtr, NULL);
|
||||
ASL_EXTERN UINT32 ASL_INIT_GLOBAL (Gbl_LineBufferSize, ASL_DEFAULT_LINE_BUFFER_SIZE);
|
||||
ASL_EXTERN UINT32 ASL_INIT_GLOBAL (Gbl_CurrentColumn, 0);
|
||||
ASL_EXTERN UINT32 ASL_INIT_GLOBAL (Gbl_PreviousLineNumber, 0);
|
||||
ASL_EXTERN UINT32 ASL_INIT_GLOBAL (Gbl_CurrentLineNumber, 1);
|
||||
ASL_EXTERN UINT32 ASL_INIT_GLOBAL (Gbl_LogicalLineNumber, 1);
|
||||
ASL_EXTERN UINT32 ASL_INIT_GLOBAL (Gbl_CurrentLineOffset, 0);
|
||||
ASL_EXTERN char ASL_INIT_GLOBAL (*Gbl_LineBufPtr, Gbl_CurrentLineBuffer);
|
||||
|
||||
/* Exception reporting */
|
||||
|
||||
|
@ -168,7 +168,7 @@ AslDoResponseFile (
|
||||
|
||||
|
||||
#define ASL_TOKEN_SEPARATORS " \t\n"
|
||||
#define ASL_SUPPORTED_OPTIONS "@:2b|c|d^D:e:fgh^i|I:l^mno|p:P^r:s|t|T:G^v^w|x:z"
|
||||
#define ASL_SUPPORTED_OPTIONS "@:2b|c|d^D:e:fgh^i|I:l^m:no|p:P^r:s|t|T:G^v^w|x:z"
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
@ -235,10 +235,10 @@ Options (
|
||||
printf ("\nAML Disassembler:\n");
|
||||
ACPI_OPTION ("-d [file]", "Disassemble or decode binary ACPI table to file (*.dsl)");
|
||||
ACPI_OPTION ("-da [f1,f2]", "Disassemble multiple tables from single namespace");
|
||||
ACPI_OPTION ("-db", "Do not translate Buffers to Resource Templates");
|
||||
ACPI_OPTION ("-dc [file]", "Disassemble AML and immediately compile it");
|
||||
ACPI_OPTION ("", "(Obtain DSDT from current system if no input file)");
|
||||
ACPI_OPTION ("-e [f1,f2]", "Include ACPI table(s) for external symbol resolution");
|
||||
ACPI_OPTION ("-m", "Do not translate Buffers to Resource Templates");
|
||||
ACPI_OPTION ("-2", "Emit ACPI 2.0 compatible ASL code");
|
||||
ACPI_OPTION ("-g", "Get ACPI tables and write to files (*.dat)");
|
||||
|
||||
@ -346,6 +346,11 @@ AslInitialize (
|
||||
|
||||
Gbl_Files[ASL_FILE_STDERR].Handle = stderr;
|
||||
Gbl_Files[ASL_FILE_STDERR].Filename = "STDERR";
|
||||
|
||||
/* Allocate the line buffer(s) */
|
||||
|
||||
Gbl_LineBufferSize /= 2;
|
||||
UtExpandLineBuffers ();
|
||||
}
|
||||
|
||||
|
||||
@ -547,6 +552,10 @@ AslDoOptions (
|
||||
Gbl_DisassembleAll = TRUE;
|
||||
break;
|
||||
|
||||
case 'b': /* Do not convert buffers to resource descriptors */
|
||||
AcpiGbl_NoResourceDisassembly = TRUE;
|
||||
break;
|
||||
|
||||
case 'c':
|
||||
break;
|
||||
|
||||
@ -685,8 +694,13 @@ AslDoOptions (
|
||||
break;
|
||||
|
||||
|
||||
case 'm': /* Do not convert buffers to resource descriptors */
|
||||
AcpiGbl_NoResourceDisassembly = TRUE;
|
||||
case 'm': /* Set line buffer size */
|
||||
Gbl_LineBufferSize = (UINT32) strtoul (AcpiGbl_Optarg, NULL, 0) * 1024;
|
||||
if (Gbl_LineBufferSize < ASL_DEFAULT_LINE_BUFFER_SIZE)
|
||||
{
|
||||
Gbl_LineBufferSize = ASL_DEFAULT_LINE_BUFFER_SIZE;
|
||||
}
|
||||
printf ("Line Buffer Size: %u\n", Gbl_LineBufferSize);
|
||||
break;
|
||||
|
||||
|
||||
@ -1027,9 +1041,10 @@ main (
|
||||
|
||||
/* Init and command line */
|
||||
|
||||
Index1 = Index2 = AslCommandLine (argc, argv);
|
||||
|
||||
AslInitialize ();
|
||||
PrInitializePreprocessor ();
|
||||
Index1 = Index2 = AslCommandLine (argc, argv);
|
||||
|
||||
/* Options that have no additional parameters or pathnames */
|
||||
|
||||
|
@ -270,6 +270,7 @@ typedef enum
|
||||
ASL_MSG_VENDOR_LIST,
|
||||
ASL_MSG_WRITE,
|
||||
ASL_MSG_RANGE,
|
||||
ASL_MSG_BUFFER_ALLOCATION,
|
||||
|
||||
/* These messages are used by the Preprocessor only */
|
||||
|
||||
@ -445,6 +446,7 @@ char *AslMessages [] = {
|
||||
/* ASL_MSG_VENDOR_LIST */ "Too many vendor data bytes (7 max)",
|
||||
/* ASL_MSG_WRITE */ "Could not write file",
|
||||
/* ASL_MSG_RANGE */ "Constant out of range",
|
||||
/* ASL_MSG_BUFFER_ALLOCATION */ "Could not allocate line buffer",
|
||||
|
||||
/* Preprocessor */
|
||||
|
||||
|
@ -311,7 +311,7 @@ AslDetectSourceFileType (
|
||||
* File is ASCII. Determine if this is an ASL file or an ACPI data
|
||||
* table file.
|
||||
*/
|
||||
while (fgets (Gbl_CurrentLineBuffer, ASL_LINE_BUFFER_SIZE, Info->Handle))
|
||||
while (fgets (Gbl_CurrentLineBuffer, Gbl_LineBufferSize, Info->Handle))
|
||||
{
|
||||
/* Uppercase the buffer for caseless compare */
|
||||
|
||||
|
@ -415,14 +415,14 @@ AslInsertLineBuffer (
|
||||
*Gbl_LineBufPtr = (UINT8) SourceChar;
|
||||
Gbl_LineBufPtr++;
|
||||
|
||||
if (Gbl_LineBufPtr > (Gbl_CurrentLineBuffer + (ASL_LINE_BUFFER_SIZE - 1)))
|
||||
if (Gbl_LineBufPtr > (Gbl_CurrentLineBuffer + (Gbl_LineBufferSize - 1)))
|
||||
{
|
||||
#if 0
|
||||
/*
|
||||
* Warning if we have split a long source line.
|
||||
* <Probably overkill>
|
||||
*/
|
||||
sprintf (MsgBuffer, "Max %u", ASL_LINE_BUFFER_SIZE);
|
||||
sprintf (MsgBuffer, "Max %u", Gbl_LineBufferSize);
|
||||
AslCommonError (ASL_WARNING, ASL_MSG_LONG_LINE,
|
||||
Gbl_CurrentLineNumber, Gbl_LogicalLineNumber,
|
||||
Gbl_CurrentLineOffset, Gbl_CurrentColumn,
|
||||
|
@ -718,6 +718,79 @@ UtGetStringBuffer (
|
||||
}
|
||||
|
||||
|
||||
/******************************************************************************
|
||||
*
|
||||
* FUNCTION: UtExpandLineBuffers
|
||||
*
|
||||
* PARAMETERS: None. Updates global line buffer pointers.
|
||||
*
|
||||
* RETURN: None. Reallocates the global line buffers
|
||||
*
|
||||
* DESCRIPTION: Called if the current line buffer becomes filled. Reallocates
|
||||
* all global line buffers and updates Gbl_LineBufferSize. NOTE:
|
||||
* Also used for the initial allocation of the buffers, when
|
||||
* all of the buffer pointers are NULL. Initial allocations are
|
||||
* of size ASL_DEFAULT_LINE_BUFFER_SIZE
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
void
|
||||
UtExpandLineBuffers (
|
||||
void)
|
||||
{
|
||||
UINT32 NewSize;
|
||||
|
||||
|
||||
/* Attempt to double the size of all line buffers */
|
||||
|
||||
NewSize = Gbl_LineBufferSize * 2;
|
||||
if (Gbl_CurrentLineBuffer)
|
||||
{
|
||||
DbgPrint (ASL_DEBUG_OUTPUT,"Increasing line buffer size from %u to %u\n",
|
||||
Gbl_LineBufferSize, NewSize);
|
||||
}
|
||||
|
||||
Gbl_CurrentLineBuffer = realloc (Gbl_CurrentLineBuffer, NewSize);
|
||||
Gbl_LineBufPtr = Gbl_CurrentLineBuffer;
|
||||
if (!Gbl_CurrentLineBuffer)
|
||||
{
|
||||
goto ErrorExit;
|
||||
}
|
||||
|
||||
Gbl_MainTokenBuffer = realloc (Gbl_MainTokenBuffer, NewSize);
|
||||
if (!Gbl_MainTokenBuffer)
|
||||
{
|
||||
goto ErrorExit;
|
||||
}
|
||||
|
||||
Gbl_MacroTokenBuffer = realloc (Gbl_MacroTokenBuffer, NewSize);
|
||||
if (!Gbl_MacroTokenBuffer)
|
||||
{
|
||||
goto ErrorExit;
|
||||
}
|
||||
|
||||
Gbl_ExpressionTokenBuffer = realloc (Gbl_ExpressionTokenBuffer, NewSize);
|
||||
if (!Gbl_ExpressionTokenBuffer)
|
||||
{
|
||||
goto ErrorExit;
|
||||
}
|
||||
|
||||
Gbl_LineBufferSize = NewSize;
|
||||
return;
|
||||
|
||||
|
||||
/* On error above, simply issue error messages and abort, cannot continue */
|
||||
|
||||
ErrorExit:
|
||||
printf ("Could not increase line buffer size from %u to %u\n",
|
||||
Gbl_LineBufferSize, Gbl_LineBufferSize * 2);
|
||||
|
||||
AslError (ASL_ERROR, ASL_MSG_BUFFER_ALLOCATION,
|
||||
NULL, NULL);
|
||||
AslAbort ();
|
||||
}
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
*
|
||||
* FUNCTION: UtInternalizeName
|
||||
|
@ -485,13 +485,21 @@ DtGetNextLine (
|
||||
BOOLEAN LineNotAllBlanks = FALSE;
|
||||
UINT32 State = DT_NORMAL_TEXT;
|
||||
UINT32 CurrentLineOffset;
|
||||
UINT32 BeyondBufferCount;
|
||||
UINT32 i;
|
||||
char c;
|
||||
|
||||
|
||||
for (i = 0; i < ASL_LINE_BUFFER_SIZE;)
|
||||
for (i = 0; ;)
|
||||
{
|
||||
/*
|
||||
* If line is too long, expand the line buffers. Also increases
|
||||
* Gbl_LineBufferSize.
|
||||
*/
|
||||
if (i >= Gbl_LineBufferSize)
|
||||
{
|
||||
UtExpandLineBuffers ();
|
||||
}
|
||||
|
||||
c = (char) getc (Handle);
|
||||
if (c == EOF)
|
||||
{
|
||||
@ -563,6 +571,11 @@ DtGetNextLine (
|
||||
*/
|
||||
if ((i != 0) && LineNotAllBlanks)
|
||||
{
|
||||
if ((i + 1) >= Gbl_LineBufferSize)
|
||||
{
|
||||
UtExpandLineBuffers ();
|
||||
}
|
||||
|
||||
Gbl_CurrentLineBuffer[i+1] = 0; /* Terminate string */
|
||||
return (CurrentLineOffset);
|
||||
}
|
||||
@ -637,6 +650,11 @@ DtGetNextLine (
|
||||
|
||||
default: /* Not a comment */
|
||||
i++; /* Save the preceeding slash */
|
||||
if (i >= Gbl_LineBufferSize)
|
||||
{
|
||||
UtExpandLineBuffers ();
|
||||
}
|
||||
|
||||
Gbl_CurrentLineBuffer[i] = c;
|
||||
i++;
|
||||
State = DT_NORMAL_TEXT;
|
||||
@ -740,21 +758,6 @@ DtGetNextLine (
|
||||
return (ASL_EOF);
|
||||
}
|
||||
}
|
||||
|
||||
/* Line is too long for internal buffer. Determine actual length */
|
||||
|
||||
BeyondBufferCount = 1;
|
||||
c = (char) getc (Handle);
|
||||
while (c != '\n')
|
||||
{
|
||||
c = (char) getc (Handle);
|
||||
BeyondBufferCount++;
|
||||
}
|
||||
|
||||
printf ("ERROR - At %u: Input line (%u bytes) is too long (max %u)\n",
|
||||
Gbl_CurrentLineNumber++, ASL_LINE_BUFFER_SIZE + BeyondBufferCount,
|
||||
ASL_LINE_BUFFER_SIZE);
|
||||
return (ASL_EOF);
|
||||
}
|
||||
|
||||
|
||||
|
@ -200,10 +200,13 @@ typedef struct pr_file_node
|
||||
/*
|
||||
* Globals
|
||||
*/
|
||||
PR_EXTERN char XXXEvalBuffer[ASL_LINE_BUFFER_SIZE];
|
||||
PR_EXTERN char Gbl_MainTokenBuffer[ASL_LINE_BUFFER_SIZE];
|
||||
PR_EXTERN char Gbl_MacroTokenBuffer[ASL_LINE_BUFFER_SIZE];
|
||||
PR_EXTERN char Gbl_ExpressionTokenBuffer[ASL_LINE_BUFFER_SIZE];
|
||||
#if 0 /* TBD for macros */
|
||||
PR_EXTERN char PR_INIT_GLOBAL (*XXXEvalBuffer, NULL); /* [ASL_LINE_BUFFER_SIZE]; */
|
||||
#endif
|
||||
|
||||
PR_EXTERN char PR_INIT_GLOBAL (*Gbl_MainTokenBuffer, NULL); /* [ASL_LINE_BUFFER_SIZE]; */
|
||||
PR_EXTERN char PR_INIT_GLOBAL (*Gbl_MacroTokenBuffer, NULL); /* [ASL_LINE_BUFFER_SIZE]; */
|
||||
PR_EXTERN char PR_INIT_GLOBAL (*Gbl_ExpressionTokenBuffer, NULL); /* [ASL_LINE_BUFFER_SIZE]; */
|
||||
|
||||
PR_EXTERN PR_FILE_NODE *Gbl_InputFileList;
|
||||
PR_EXTERN PR_DEFINE_INFO PR_INIT_GLOBAL (*Gbl_DefineList, NULL);
|
||||
|
Loading…
x
Reference in New Issue
Block a user