1 /****************************************************************************** 2 * 3 * Module Name: aslerror - Error handling and statistics 4 * 5 *****************************************************************************/ 6 7 /****************************************************************************** 8 * 9 * 1. Copyright Notice 10 * 11 * Some or all of this work - Copyright (c) 1999 - 2017, Intel Corp. 12 * All rights reserved. 13 * 14 * 2. License 15 * 16 * 2.1. This is your license from Intel Corp. under its intellectual property 17 * rights. You may have additional license terms from the party that provided 18 * you this software, covering your right to use that party's intellectual 19 * property rights. 20 * 21 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a 22 * copy of the source code appearing in this file ("Covered Code") an 23 * irrevocable, perpetual, worldwide license under Intel's copyrights in the 24 * base code distributed originally by Intel ("Original Intel Code") to copy, 25 * make derivatives, distribute, use and display any portion of the Covered 26 * Code in any form, with the right to sublicense such rights; and 27 * 28 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent 29 * license (with the right to sublicense), under only those claims of Intel 30 * patents that are infringed by the Original Intel Code, to make, use, sell, 31 * offer to sell, and import the Covered Code and derivative works thereof 32 * solely to the minimum extent necessary to exercise the above copyright 33 * license, and in no event shall the patent license extend to any additions 34 * to or modifications of the Original Intel Code. No other license or right 35 * is granted directly or by implication, estoppel or otherwise; 36 * 37 * The above copyright and patent license is granted only if the following 38 * conditions are met: 39 * 40 * 3. Conditions 41 * 42 * 3.1. Redistribution of Source with Rights to Further Distribute Source. 43 * Redistribution of source code of any substantial portion of the Covered 44 * Code or modification with rights to further distribute source must include 45 * the above Copyright Notice, the above License, this list of Conditions, 46 * and the following Disclaimer and Export Compliance provision. In addition, 47 * Licensee must cause all Covered Code to which Licensee contributes to 48 * contain a file documenting the changes Licensee made to create that Covered 49 * Code and the date of any change. Licensee must include in that file the 50 * documentation of any changes made by any predecessor Licensee. Licensee 51 * must include a prominent statement that the modification is derived, 52 * directly or indirectly, from Original Intel Code. 53 * 54 * 3.2. Redistribution of Source with no Rights to Further Distribute Source. 55 * Redistribution of source code of any substantial portion of the Covered 56 * Code or modification without rights to further distribute source must 57 * include the following Disclaimer and Export Compliance provision in the 58 * documentation and/or other materials provided with distribution. In 59 * addition, Licensee may not authorize further sublicense of source of any 60 * portion of the Covered Code, and must include terms to the effect that the 61 * license from Licensee to its licensee is limited to the intellectual 62 * property embodied in the software Licensee provides to its licensee, and 63 * not to intellectual property embodied in modifications its licensee may 64 * make. 65 * 66 * 3.3. Redistribution of Executable. Redistribution in executable form of any 67 * substantial portion of the Covered Code or modification must reproduce the 68 * above Copyright Notice, and the following Disclaimer and Export Compliance 69 * provision in the documentation and/or other materials provided with the 70 * distribution. 71 * 72 * 3.4. Intel retains all right, title, and interest in and to the Original 73 * Intel Code. 74 * 75 * 3.5. Neither the name Intel nor any other trademark owned or controlled by 76 * Intel shall be used in advertising or otherwise to promote the sale, use or 77 * other dealings in products derived from or relating to the Covered Code 78 * without prior written authorization from Intel. 79 * 80 * 4. Disclaimer and Export Compliance 81 * 82 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED 83 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE 84 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE, 85 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY 86 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY 87 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A 88 * PARTICULAR PURPOSE. 89 * 90 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES 91 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR 92 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT, 93 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY 94 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL 95 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS 96 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY 97 * LIMITED REMEDY. 98 * 99 * 4.3. Licensee shall not export, either directly or indirectly, any of this 100 * software or system incorporating such software without first obtaining any 101 * required license or other approval from the U. S. Department of Commerce or 102 * any other agency or department of the United States Government. In the 103 * event Licensee exports any such software from the United States or 104 * re-exports any such software from a foreign destination, Licensee shall 105 * ensure that the distribution and export/re-export of the software is in 106 * compliance with all laws, regulations, orders, or other restrictions of the 107 * U.S. Export Administration Regulations. Licensee agrees that neither it nor 108 * any of its subsidiaries will export/re-export any technical data, process, 109 * software, or service, directly or indirectly, to any country for which the 110 * United States government or any agency thereof requires an export license, 111 * other governmental approval, or letter of assurance, without first obtaining 112 * such license, approval or letter. 113 * 114 ***************************************************************************** 115 * 116 * Alternatively, you may choose to be licensed under the terms of the 117 * following license: 118 * 119 * Redistribution and use in source and binary forms, with or without 120 * modification, are permitted provided that the following conditions 121 * are met: 122 * 1. Redistributions of source code must retain the above copyright 123 * notice, this list of conditions, and the following disclaimer, 124 * without modification. 125 * 2. Redistributions in binary form must reproduce at minimum a disclaimer 126 * substantially similar to the "NO WARRANTY" disclaimer below 127 * ("Disclaimer") and any redistribution must be conditioned upon 128 * including a substantially similar Disclaimer requirement for further 129 * binary redistribution. 130 * 3. Neither the names of the above-listed copyright holders nor the names 131 * of any contributors may be used to endorse or promote products derived 132 * from this software without specific prior written permission. 133 * 134 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 135 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 136 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 137 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 138 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 139 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 140 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 141 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 142 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 143 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 144 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 145 * 146 * Alternatively, you may choose to be licensed under the terms of the 147 * GNU General Public License ("GPL") version 2 as published by the Free 148 * Software Foundation. 149 * 150 *****************************************************************************/ 151 152 #include <contrib/dev/acpica/compiler/aslcompiler.h> 153 154 #define _COMPONENT ACPI_COMPILER 155 ACPI_MODULE_NAME ("aslerror") 156 157 /* Local prototypes */ 158 159 static void 160 AeAddToErrorLog ( 161 ASL_ERROR_MSG *Enode); 162 163 static BOOLEAN 164 AslIsExceptionExpected ( 165 UINT8 Level, 166 UINT16 MessageId); 167 168 static BOOLEAN 169 AslIsExceptionDisabled ( 170 UINT8 Level, 171 UINT16 MessageId); 172 173 174 /******************************************************************************* 175 * 176 * FUNCTION: AslAbort 177 * 178 * PARAMETERS: None 179 * 180 * RETURN: None 181 * 182 * DESCRIPTION: Dump the error log and abort the compiler. Used for serious 183 * I/O errors. 184 * 185 ******************************************************************************/ 186 187 void 188 AslAbort ( 189 void) 190 { 191 192 AePrintErrorLog (ASL_FILE_STDERR); 193 if (Gbl_DebugFlag) 194 { 195 /* Print error summary to stdout also */ 196 197 AePrintErrorLog (ASL_FILE_STDOUT); 198 } 199 200 exit (1); 201 } 202 203 204 /******************************************************************************* 205 * 206 * FUNCTION: AeClearErrorLog 207 * 208 * PARAMETERS: None 209 * 210 * RETURN: None 211 * 212 * DESCRIPTION: Empty the error list 213 * 214 ******************************************************************************/ 215 216 void 217 AeClearErrorLog ( 218 void) 219 { 220 ASL_ERROR_MSG *Enode = Gbl_ErrorLog; 221 ASL_ERROR_MSG *Next; 222 223 /* Walk the error node list */ 224 225 while (Enode) 226 { 227 Next = Enode->Next; 228 ACPI_FREE (Enode); 229 Enode = Next; 230 } 231 232 Gbl_ErrorLog = NULL; 233 } 234 235 236 /******************************************************************************* 237 * 238 * FUNCTION: AeAddToErrorLog 239 * 240 * PARAMETERS: Enode - An error node to add to the log 241 * 242 * RETURN: None 243 * 244 * DESCRIPTION: Add a new error node to the error log. The error log is 245 * ordered by the "logical" line number (cumulative line number 246 * including all include files.) 247 * 248 ******************************************************************************/ 249 250 static void 251 AeAddToErrorLog ( 252 ASL_ERROR_MSG *Enode) 253 { 254 ASL_ERROR_MSG *Next; 255 ASL_ERROR_MSG *Prev; 256 257 258 /* If Gbl_ErrorLog is null, this is the first error node */ 259 260 if (!Gbl_ErrorLog) 261 { 262 Gbl_ErrorLog = Enode; 263 return; 264 } 265 266 /* 267 * Walk error list until we find a line number greater than ours. 268 * List is sorted according to line number. 269 */ 270 Prev = NULL; 271 Next = Gbl_ErrorLog; 272 273 while ((Next) && 274 (Next->LogicalLineNumber <= Enode->LogicalLineNumber)) 275 { 276 Prev = Next; 277 Next = Next->Next; 278 } 279 280 /* Found our place in the list */ 281 282 Enode->Next = Next; 283 284 if (Prev) 285 { 286 Prev->Next = Enode; 287 } 288 else 289 { 290 Gbl_ErrorLog = Enode; 291 } 292 } 293 294 295 /******************************************************************************* 296 * 297 * FUNCTION: AePrintException 298 * 299 * PARAMETERS: FileId - ID of output file 300 * Enode - Error node to print 301 * Header - Additional text before each message 302 * 303 * RETURN: None 304 * 305 * DESCRIPTION: Print the contents of an error node. 306 * 307 * NOTE: We don't use the FlxxxFile I/O functions here because on error 308 * they abort the compiler and call this function! Since we 309 * are reporting errors here, we ignore most output errors and 310 * just try to get out as much as we can. 311 * 312 ******************************************************************************/ 313 314 void 315 AePrintException ( 316 UINT32 FileId, 317 ASL_ERROR_MSG *Enode, 318 char *Header) 319 { 320 UINT8 SourceByte; 321 int Actual; 322 size_t RActual; 323 UINT32 MsgLength; 324 const char *MainMessage; 325 char *ExtraMessage; 326 UINT32 SourceColumn; 327 UINT32 ErrorColumn; 328 FILE *OutputFile; 329 FILE *SourceFile = NULL; 330 long FileSize; 331 BOOLEAN PrematureEOF = FALSE; 332 UINT32 Total = 0; 333 334 335 if (Gbl_NoErrors) 336 { 337 return; 338 } 339 340 /* 341 * Only listing files have a header, and remarks/optimizations 342 * are always output 343 */ 344 if (!Header) 345 { 346 /* Ignore remarks if requested */ 347 348 switch (Enode->Level) 349 { 350 case ASL_WARNING: 351 case ASL_WARNING2: 352 case ASL_WARNING3: 353 354 if (!Gbl_DisplayWarnings) 355 { 356 return; 357 } 358 break; 359 360 case ASL_REMARK: 361 362 if (!Gbl_DisplayRemarks) 363 { 364 return; 365 } 366 break; 367 368 case ASL_OPTIMIZATION: 369 370 if (!Gbl_DisplayOptimizations) 371 { 372 return; 373 } 374 break; 375 376 default: 377 378 break; 379 } 380 } 381 382 /* Get the various required file handles */ 383 384 OutputFile = Gbl_Files[FileId].Handle; 385 386 if (!Enode->SourceLine) 387 { 388 /* 389 * Use the merged header/source file if present, otherwise 390 * use input file 391 */ 392 SourceFile = Gbl_Files[ASL_FILE_SOURCE_OUTPUT].Handle; 393 if (!SourceFile) 394 { 395 SourceFile = Gbl_Files[ASL_FILE_INPUT].Handle; 396 } 397 398 if (SourceFile) 399 { 400 /* Determine if the error occurred at source file EOF */ 401 402 fseek (SourceFile, 0, SEEK_END); 403 FileSize = ftell (SourceFile); 404 405 if ((long) Enode->LogicalByteOffset >= FileSize) 406 { 407 PrematureEOF = TRUE; 408 } 409 } 410 } 411 412 if (Header) 413 { 414 fprintf (OutputFile, "%s", Header); 415 } 416 417 /* Print filename and line number if present and valid */ 418 419 if (Enode->Filename) 420 { 421 if (Gbl_VerboseErrors) 422 { 423 fprintf (OutputFile, "%-8s", Enode->Filename); 424 425 if (Enode->LineNumber) 426 { 427 if (Enode->SourceLine) 428 { 429 fprintf (OutputFile, " %6u: %s", 430 Enode->LineNumber, Enode->SourceLine); 431 } 432 else 433 { 434 fprintf (OutputFile, " %6u: ", Enode->LineNumber); 435 436 /* 437 * If not at EOF, get the corresponding source code line 438 * and display it. Don't attempt this if we have a 439 * premature EOF condition. 440 */ 441 if (!PrematureEOF) 442 { 443 /* 444 * Seek to the offset in the combined source file, 445 * read the source line, and write it to the output. 446 */ 447 Actual = fseek (SourceFile, 448 (long) Enode->LogicalByteOffset, (int) SEEK_SET); 449 if (Actual) 450 { 451 fprintf (OutputFile, 452 "[*** iASL: Seek error on source code temp file %s ***]", 453 Gbl_Files[ASL_FILE_SOURCE_OUTPUT].Filename); 454 } 455 else 456 { 457 RActual = fread (&SourceByte, 1, 1, SourceFile); 458 if (RActual != 1) 459 { 460 fprintf (OutputFile, 461 "[*** iASL: Read error on source code temp file %s ***]", 462 Gbl_Files[ASL_FILE_SOURCE_OUTPUT].Filename); 463 } 464 else 465 { 466 /* Read/write the source line, up to the maximum line length */ 467 468 while (RActual && SourceByte && (SourceByte != '\n')) 469 { 470 if (Total < 256) 471 { 472 /* After the max line length, we will just read the line, no write */ 473 474 if (fwrite (&SourceByte, 1, 1, OutputFile) != 1) 475 { 476 printf ("[*** iASL: Write error on output file ***]\n"); 477 return; 478 } 479 } 480 else if (Total == 256) 481 { 482 fprintf (OutputFile, 483 "\n[*** iASL: Very long input line, message below refers to column %u ***]", 484 Enode->Column); 485 } 486 487 RActual = fread (&SourceByte, 1, 1, SourceFile); 488 if (RActual != 1) 489 { 490 fprintf (OutputFile, 491 "[*** iASL: Read error on source code temp file %s ***]", 492 Gbl_Files[ASL_FILE_SOURCE_OUTPUT].Filename); 493 return; 494 } 495 Total++; 496 } 497 } 498 } 499 } 500 501 fprintf (OutputFile, "\n"); 502 } 503 } 504 } 505 else 506 { 507 /* 508 * Less verbose version of the error message, enabled via the 509 * -vi switch. The format is compatible with MS Visual Studio. 510 */ 511 fprintf (OutputFile, "%s", Enode->Filename); 512 513 if (Enode->LineNumber) 514 { 515 fprintf (OutputFile, "(%u) : ", 516 Enode->LineNumber); 517 } 518 } 519 } 520 521 /* If a NULL message ID, just print the raw message */ 522 523 if (Enode->MessageId == 0) 524 { 525 fprintf (OutputFile, "%s\n", Enode->Message); 526 return; 527 } 528 529 /* Decode the message ID */ 530 531 fprintf (OutputFile, "%s %4.4d -", 532 AeDecodeExceptionLevel (Enode->Level), 533 AeBuildFullExceptionCode (Enode->Level, Enode->MessageId)); 534 535 MainMessage = AeDecodeMessageId (Enode->MessageId); 536 ExtraMessage = Enode->Message; 537 538 /* If a NULL line number, just print the decoded message */ 539 540 if (!Enode->LineNumber) 541 { 542 fprintf (OutputFile, " %s %s\n\n", MainMessage, ExtraMessage); 543 return; 544 } 545 546 MsgLength = strlen (MainMessage); 547 if (MsgLength == 0) 548 { 549 /* Use the secondary/extra message as main message */ 550 551 MainMessage = Enode->Message; 552 if (!MainMessage) 553 { 554 MainMessage = ""; 555 } 556 557 MsgLength = strlen (MainMessage); 558 ExtraMessage = NULL; 559 } 560 561 if (Gbl_VerboseErrors && !PrematureEOF) 562 { 563 if (Total >= 256) 564 { 565 fprintf (OutputFile, " %s", 566 MainMessage); 567 } 568 else 569 { 570 SourceColumn = Enode->Column + Enode->FilenameLength + 6 + 2; 571 ErrorColumn = ASL_ERROR_LEVEL_LENGTH + 5 + 2 + 1; 572 573 if ((MsgLength + ErrorColumn) < (SourceColumn - 1)) 574 { 575 fprintf (OutputFile, "%*s%s", 576 (int) ((SourceColumn - 1) - ErrorColumn), 577 MainMessage, " ^ "); 578 } 579 else 580 { 581 fprintf (OutputFile, "%*s %s", 582 (int) ((SourceColumn - ErrorColumn) + 1), "^", 583 MainMessage); 584 } 585 } 586 } 587 else 588 { 589 fprintf (OutputFile, " %s", MainMessage); 590 } 591 592 /* Print the extra info message if present */ 593 594 if (ExtraMessage) 595 { 596 fprintf (OutputFile, " (%s)", ExtraMessage); 597 } 598 599 if (PrematureEOF) 600 { 601 fprintf (OutputFile, " and premature End-Of-File"); 602 } 603 604 fprintf (OutputFile, "\n"); 605 if (Gbl_VerboseErrors) 606 { 607 fprintf (OutputFile, "\n"); 608 } 609 } 610 611 612 /******************************************************************************* 613 * 614 * FUNCTION: AePrintErrorLog 615 * 616 * PARAMETERS: FileId - Where to output the error log 617 * 618 * RETURN: None 619 * 620 * DESCRIPTION: Print the entire contents of the error log 621 * 622 ******************************************************************************/ 623 624 void 625 AePrintErrorLog ( 626 UINT32 FileId) 627 { 628 ASL_ERROR_MSG *Enode = Gbl_ErrorLog; 629 630 631 /* Walk the error node list */ 632 633 while (Enode) 634 { 635 AePrintException (FileId, Enode, NULL); 636 Enode = Enode->Next; 637 } 638 } 639 640 641 /******************************************************************************* 642 * 643 * FUNCTION: AslCommonError2 644 * 645 * PARAMETERS: Level - Seriousness (Warning/error, etc.) 646 * MessageId - Index into global message buffer 647 * LineNumber - Actual file line number 648 * Column - Column in current line 649 * SourceLine - Actual source code line 650 * Filename - source filename 651 * ExtraMessage - additional error message 652 * 653 * RETURN: None 654 * 655 * DESCRIPTION: Create a new error node and add it to the error log 656 * 657 ******************************************************************************/ 658 659 void 660 AslCommonError2 ( 661 UINT8 Level, 662 UINT16 MessageId, 663 UINT32 LineNumber, 664 UINT32 Column, 665 char *SourceLine, 666 char *Filename, 667 char *ExtraMessage) 668 { 669 char *MessageBuffer = NULL; 670 char *LineBuffer; 671 ASL_ERROR_MSG *Enode; 672 673 674 Enode = UtLocalCalloc (sizeof (ASL_ERROR_MSG)); 675 676 if (ExtraMessage) 677 { 678 /* Allocate a buffer for the message and a new error node */ 679 680 MessageBuffer = UtStringCacheCalloc (strlen (ExtraMessage) + 1); 681 682 /* Keep a copy of the extra message */ 683 684 strcpy (MessageBuffer, ExtraMessage); 685 } 686 687 LineBuffer = UtLocalCalloc (strlen (SourceLine) + 1); 688 strcpy (LineBuffer, SourceLine); 689 690 /* Initialize the error node */ 691 692 if (Filename) 693 { 694 Enode->Filename = Filename; 695 Enode->FilenameLength = strlen (Filename); 696 if (Enode->FilenameLength < 6) 697 { 698 Enode->FilenameLength = 6; 699 } 700 } 701 702 Enode->MessageId = MessageId; 703 Enode->Level = Level; 704 Enode->LineNumber = LineNumber; 705 Enode->LogicalLineNumber = LineNumber; 706 Enode->LogicalByteOffset = 0; 707 Enode->Column = Column; 708 Enode->Message = MessageBuffer; 709 Enode->SourceLine = LineBuffer; 710 711 /* Add the new node to the error node list */ 712 713 AeAddToErrorLog (Enode); 714 715 if (Gbl_DebugFlag) 716 { 717 /* stderr is a file, send error to it immediately */ 718 719 AePrintException (ASL_FILE_STDERR, Enode, NULL); 720 } 721 722 Gbl_ExceptionCount[Level]++; 723 } 724 725 726 /******************************************************************************* 727 * 728 * FUNCTION: AslCommonError 729 * 730 * PARAMETERS: Level - Seriousness (Warning/error, etc.) 731 * MessageId - Index into global message buffer 732 * CurrentLineNumber - Actual file line number 733 * LogicalLineNumber - Cumulative line number 734 * LogicalByteOffset - Byte offset in source file 735 * Column - Column in current line 736 * Filename - source filename 737 * ExtraMessage - additional error message 738 * 739 * RETURN: None 740 * 741 * DESCRIPTION: Create a new error node and add it to the error log 742 * 743 ******************************************************************************/ 744 745 void 746 AslCommonError ( 747 UINT8 Level, 748 UINT16 MessageId, 749 UINT32 CurrentLineNumber, 750 UINT32 LogicalLineNumber, 751 UINT32 LogicalByteOffset, 752 UINT32 Column, 753 char *Filename, 754 char *ExtraMessage) 755 { 756 char *MessageBuffer = NULL; 757 ASL_ERROR_MSG *Enode; 758 759 760 Enode = UtLocalCalloc (sizeof (ASL_ERROR_MSG)); 761 762 if (ExtraMessage) 763 { 764 /* Allocate a buffer for the message and a new error node */ 765 766 MessageBuffer = UtStringCacheCalloc (strlen (ExtraMessage) + 1); 767 768 /* Keep a copy of the extra message */ 769 770 strcpy (MessageBuffer, ExtraMessage); 771 } 772 773 /* Initialize the error node */ 774 775 if (Filename) 776 { 777 Enode->Filename = Filename; 778 Enode->FilenameLength = strlen (Filename); 779 if (Enode->FilenameLength < 6) 780 { 781 Enode->FilenameLength = 6; 782 } 783 } 784 785 Enode->MessageId = MessageId; 786 Enode->Level = Level; 787 Enode->LineNumber = CurrentLineNumber; 788 Enode->LogicalLineNumber = LogicalLineNumber; 789 Enode->LogicalByteOffset = LogicalByteOffset; 790 Enode->Column = Column; 791 Enode->Message = MessageBuffer; 792 Enode->SourceLine = NULL; 793 794 /* Add the new node to the error node list */ 795 796 AeAddToErrorLog (Enode); 797 798 if (Gbl_DebugFlag) 799 { 800 /* stderr is a file, send error to it immediately */ 801 802 AePrintException (ASL_FILE_STDERR, Enode, NULL); 803 } 804 805 Gbl_ExceptionCount[Level]++; 806 if (Gbl_ExceptionCount[ASL_ERROR] > ASL_MAX_ERROR_COUNT) 807 { 808 printf ("\nMaximum error count (%u) exceeded\n", ASL_MAX_ERROR_COUNT); 809 810 Gbl_SourceLine = 0; 811 Gbl_NextError = Gbl_ErrorLog; 812 CmCleanupAndExit (); 813 exit(1); 814 } 815 816 return; 817 } 818 819 /******************************************************************************* 820 * 821 * FUNCTION: AslIsExceptionIgnored 822 * 823 * PARAMETERS: Level - Seriousness (Warning/error, etc.) 824 * MessageId - Index into global message buffer 825 * 826 * RETURN: BOOLEAN 827 * 828 * DESCRIPTION: Check if a particular exception is ignored. In this case it 829 * means that the exception is (expected or disabled. 830 * 831 ******************************************************************************/ 832 833 BOOLEAN 834 AslIsExceptionIgnored ( 835 UINT8 Level, 836 UINT16 MessageId) 837 { 838 BOOLEAN ExceptionIgnored; 839 840 841 /* Note: this allows exception to be disabled and expected */ 842 843 ExceptionIgnored = AslIsExceptionDisabled (Level, MessageId); 844 ExceptionIgnored |= AslIsExceptionExpected (Level, MessageId); 845 846 return (Gbl_AllExceptionsDisabled || ExceptionIgnored); 847 } 848 849 850 /******************************************************************************* 851 * 852 * FUNCTION: AslCheckExpectException 853 * 854 * PARAMETERS: none 855 * 856 * RETURN: none 857 * 858 * DESCRIPTION: Check the global expected messages table and raise an error 859 * for each message that has not been received. 860 * 861 ******************************************************************************/ 862 863 void 864 AslCheckExpectedExceptions ( 865 void) 866 { 867 UINT8 i; 868 869 for (i = 0; i < Gbl_ExpectedMessagesIndex; ++i) 870 { 871 if (!Gbl_ExpectedMessages[i].MessageReceived) 872 { 873 AslError (ASL_ERROR, ASL_MSG_EXCEPTION_NOT_RECEIVED, NULL, 874 Gbl_ExpectedMessages[i].MessageIdStr); 875 } 876 } 877 } 878 879 880 /******************************************************************************* 881 * 882 * FUNCTION: AslExpectException 883 * 884 * PARAMETERS: MessageIdString - ID of excepted exception during compile 885 * 886 * RETURN: Status 887 * 888 * DESCRIPTION: Enter a message ID into the global expected messages table 889 * If these messages are not raised during the compilation, throw 890 * an error. 891 * 892 ******************************************************************************/ 893 894 ACPI_STATUS 895 AslExpectException ( 896 char *MessageIdString) 897 { 898 UINT32 MessageId; 899 900 901 /* Convert argument to an integer and validate it */ 902 903 MessageId = (UINT32) strtoul (MessageIdString, NULL, 0); 904 905 if (MessageId > 6999) 906 { 907 printf ("\"%s\" is not a valid warning/remark/erro ID\n", 908 MessageIdString); 909 return (AE_BAD_PARAMETER); 910 } 911 912 /* Insert value into the global expected message array */ 913 914 if (Gbl_ExpectedMessagesIndex >= ASL_MAX_EXPECTED_MESSAGES) 915 { 916 printf ("Too many messages have been registered as expected (max %u)\n", 917 ASL_MAX_DISABLED_MESSAGES); 918 return (AE_LIMIT); 919 } 920 921 Gbl_ExpectedMessages[Gbl_ExpectedMessagesIndex].MessageId = MessageId; 922 Gbl_ExpectedMessages[Gbl_ExpectedMessagesIndex].MessageIdStr = MessageIdString; 923 Gbl_ExpectedMessages[Gbl_ExpectedMessagesIndex].MessageReceived = FALSE; 924 Gbl_ExpectedMessagesIndex++; 925 return (AE_OK); 926 } 927 928 929 /******************************************************************************* 930 * 931 * FUNCTION: AslDisableException 932 * 933 * PARAMETERS: MessageIdString - ID to be disabled 934 * 935 * RETURN: Status 936 * 937 * DESCRIPTION: Enter a message ID into the global disabled messages table 938 * 939 ******************************************************************************/ 940 941 ACPI_STATUS 942 AslDisableException ( 943 char *MessageIdString) 944 { 945 UINT32 MessageId; 946 947 948 /* Convert argument to an integer and validate it */ 949 950 MessageId = (UINT32) strtoul (MessageIdString, NULL, 0); 951 952 if ((MessageId < 2000) || (MessageId > 5999)) 953 { 954 printf ("\"%s\" is not a valid warning/remark ID\n", 955 MessageIdString); 956 return (AE_BAD_PARAMETER); 957 } 958 959 /* Insert value into the global disabled message array */ 960 961 if (Gbl_DisabledMessagesIndex >= ASL_MAX_DISABLED_MESSAGES) 962 { 963 printf ("Too many messages have been disabled (max %u)\n", 964 ASL_MAX_DISABLED_MESSAGES); 965 return (AE_LIMIT); 966 } 967 968 Gbl_DisabledMessages[Gbl_DisabledMessagesIndex] = MessageId; 969 Gbl_DisabledMessagesIndex++; 970 return (AE_OK); 971 } 972 973 974 /******************************************************************************* 975 * 976 * FUNCTION: AslIsExceptionDisabled 977 * 978 * PARAMETERS: Level - Seriousness (Warning/error, etc.) 979 * MessageId - Index into global message buffer 980 * 981 * RETURN: TRUE if exception/message should be ignored 982 * 983 * DESCRIPTION: Check if the user has specified options such that this 984 * exception should be ignored 985 * 986 ******************************************************************************/ 987 988 static BOOLEAN 989 AslIsExceptionExpected ( 990 UINT8 Level, 991 UINT16 MessageId) 992 { 993 UINT32 EncodedMessageId; 994 UINT32 i; 995 996 997 /* 998 * Mark this exception as received 999 */ 1000 EncodedMessageId = AeBuildFullExceptionCode (Level, MessageId); 1001 for (i = 0; i < Gbl_ExpectedMessagesIndex; i++) 1002 { 1003 /* Simple implementation via fixed array */ 1004 1005 if (EncodedMessageId == Gbl_ExpectedMessages[i].MessageId) 1006 { 1007 return (Gbl_ExpectedMessages[i].MessageReceived = TRUE); 1008 } 1009 } 1010 1011 return (FALSE); 1012 } 1013 1014 1015 /******************************************************************************* 1016 * 1017 * FUNCTION: AslIsExceptionDisabled 1018 * 1019 * PARAMETERS: Level - Seriousness (Warning/error, etc.) 1020 * MessageId - Index into global message buffer 1021 * 1022 * RETURN: TRUE if exception/message should be ignored 1023 * 1024 * DESCRIPTION: Check if the user has specified options such that this 1025 * exception should be ignored 1026 * 1027 ******************************************************************************/ 1028 1029 static BOOLEAN 1030 AslIsExceptionDisabled ( 1031 UINT8 Level, 1032 UINT16 MessageId) 1033 { 1034 UINT32 EncodedMessageId; 1035 UINT32 i; 1036 1037 1038 switch (Level) 1039 { 1040 case ASL_WARNING2: 1041 case ASL_WARNING3: 1042 1043 /* Check for global disable via -w1/-w2/-w3 options */ 1044 1045 if (Level > Gbl_WarningLevel) 1046 { 1047 return (TRUE); 1048 } 1049 /* Fall through */ 1050 1051 case ASL_WARNING: 1052 case ASL_REMARK: 1053 /* 1054 * Ignore this warning/remark if it has been disabled by 1055 * the user (-vw option) 1056 */ 1057 EncodedMessageId = AeBuildFullExceptionCode (Level, MessageId); 1058 for (i = 0; i < Gbl_DisabledMessagesIndex; i++) 1059 { 1060 /* Simple implementation via fixed array */ 1061 1062 if (EncodedMessageId == Gbl_DisabledMessages[i]) 1063 { 1064 return (TRUE); 1065 } 1066 } 1067 break; 1068 1069 default: 1070 break; 1071 } 1072 1073 return (FALSE); 1074 } 1075 1076 1077 /******************************************************************************* 1078 * 1079 * FUNCTION: AslError 1080 * 1081 * PARAMETERS: Level - Seriousness (Warning/error, etc.) 1082 * MessageId - Index into global message buffer 1083 * Op - Parse node where error happened 1084 * ExtraMessage - additional error message 1085 * 1086 * RETURN: None 1087 * 1088 * DESCRIPTION: Main error reporting routine for the ASL compiler (all code 1089 * except the parser.) 1090 * 1091 ******************************************************************************/ 1092 1093 void 1094 AslError ( 1095 UINT8 Level, 1096 UINT16 MessageId, 1097 ACPI_PARSE_OBJECT *Op, 1098 char *ExtraMessage) 1099 { 1100 1101 /* Check if user wants to ignore this exception */ 1102 1103 if (AslIsExceptionIgnored (Level, MessageId)) 1104 { 1105 return; 1106 } 1107 1108 if (Op) 1109 { 1110 AslCommonError (Level, MessageId, Op->Asl.LineNumber, 1111 Op->Asl.LogicalLineNumber, 1112 Op->Asl.LogicalByteOffset, 1113 Op->Asl.Column, 1114 Op->Asl.Filename, ExtraMessage); 1115 } 1116 else 1117 { 1118 AslCommonError (Level, MessageId, 0, 1119 0, 0, 0, NULL, ExtraMessage); 1120 } 1121 } 1122 1123 1124 /******************************************************************************* 1125 * 1126 * FUNCTION: AslCoreSubsystemError 1127 * 1128 * PARAMETERS: Op - Parse node where error happened 1129 * Status - The ACPICA Exception 1130 * ExtraMessage - additional error message 1131 * Abort - TRUE -> Abort compilation 1132 * 1133 * RETURN: None 1134 * 1135 * DESCRIPTION: Error reporting routine for exceptions returned by the ACPICA 1136 * core subsystem. 1137 * 1138 ******************************************************************************/ 1139 1140 void 1141 AslCoreSubsystemError ( 1142 ACPI_PARSE_OBJECT *Op, 1143 ACPI_STATUS Status, 1144 char *ExtraMessage, 1145 BOOLEAN Abort) 1146 { 1147 1148 sprintf (MsgBuffer, "%s %s", AcpiFormatException (Status), ExtraMessage); 1149 1150 if (Op) 1151 { 1152 AslCommonError (ASL_ERROR, ASL_MSG_CORE_EXCEPTION, 1153 Op->Asl.LineNumber, 1154 Op->Asl.LogicalLineNumber, 1155 Op->Asl.LogicalByteOffset, 1156 Op->Asl.Column, 1157 Op->Asl.Filename, MsgBuffer); 1158 } 1159 else 1160 { 1161 AslCommonError (ASL_ERROR, ASL_MSG_CORE_EXCEPTION, 1162 0, 0, 0, 0, NULL, MsgBuffer); 1163 } 1164 1165 if (Abort) 1166 { 1167 AslAbort (); 1168 } 1169 } 1170 1171 1172 /******************************************************************************* 1173 * 1174 * FUNCTION: AslCompilererror 1175 * 1176 * PARAMETERS: CompilerMessage - Error message from the parser 1177 * 1178 * RETURN: Status (0 for now) 1179 * 1180 * DESCRIPTION: Report an error situation discovered in a production 1181 * NOTE: don't change the name of this function, it is called 1182 * from the auto-generated parser. 1183 * 1184 ******************************************************************************/ 1185 1186 int 1187 AslCompilererror ( 1188 const char *CompilerMessage) 1189 { 1190 1191 Gbl_SyntaxError++; 1192 1193 AslCommonError (ASL_ERROR, ASL_MSG_SYNTAX, Gbl_CurrentLineNumber, 1194 Gbl_LogicalLineNumber, Gbl_CurrentLineOffset, 1195 Gbl_CurrentColumn, Gbl_Files[ASL_FILE_INPUT].Filename, 1196 ACPI_CAST_PTR (char, CompilerMessage)); 1197 1198 return (0); 1199 } 1200