Home | History | Annotate | Line # | Download | only in acpiexec
aeexception.c revision 1.1.1.4.2.1
      1          1.1  christos /******************************************************************************
      2          1.1  christos  *
      3          1.1  christos  * Module Name: aeexception - Exception and signal handlers
      4          1.1  christos  *
      5          1.1  christos  *****************************************************************************/
      6          1.1  christos 
      7          1.1  christos /*
      8  1.1.1.4.2.1  christos  * Copyright (C) 2000 - 2019, Intel Corp.
      9          1.1  christos  * All rights reserved.
     10          1.1  christos  *
     11          1.1  christos  * Redistribution and use in source and binary forms, with or without
     12          1.1  christos  * modification, are permitted provided that the following conditions
     13          1.1  christos  * are met:
     14          1.1  christos  * 1. Redistributions of source code must retain the above copyright
     15          1.1  christos  *    notice, this list of conditions, and the following disclaimer,
     16          1.1  christos  *    without modification.
     17          1.1  christos  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
     18          1.1  christos  *    substantially similar to the "NO WARRANTY" disclaimer below
     19          1.1  christos  *    ("Disclaimer") and any redistribution must be conditioned upon
     20          1.1  christos  *    including a substantially similar Disclaimer requirement for further
     21          1.1  christos  *    binary redistribution.
     22          1.1  christos  * 3. Neither the names of the above-listed copyright holders nor the names
     23          1.1  christos  *    of any contributors may be used to endorse or promote products derived
     24          1.1  christos  *    from this software without specific prior written permission.
     25          1.1  christos  *
     26          1.1  christos  * Alternatively, this software may be distributed under the terms of the
     27          1.1  christos  * GNU General Public License ("GPL") version 2 as published by the Free
     28          1.1  christos  * Software Foundation.
     29          1.1  christos  *
     30          1.1  christos  * NO WARRANTY
     31          1.1  christos  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     32          1.1  christos  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     33          1.1  christos  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
     34          1.1  christos  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     35          1.1  christos  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     36          1.1  christos  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     37          1.1  christos  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     38          1.1  christos  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
     39          1.1  christos  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
     40          1.1  christos  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     41          1.1  christos  * POSSIBILITY OF SUCH DAMAGES.
     42          1.1  christos  */
     43          1.1  christos 
     44          1.1  christos #include "aecommon.h"
     45          1.1  christos 
     46          1.1  christos #define _COMPONENT          ACPI_TOOLS
     47          1.1  christos         ACPI_MODULE_NAME    ("aeexception")
     48          1.1  christos 
     49          1.1  christos 
     50          1.1  christos /* Local prototypes */
     51          1.1  christos 
     52          1.1  christos static void
     53          1.1  christos AeDisplayMethodCallStack (
     54          1.1  christos     void);
     55          1.1  christos 
     56          1.1  christos 
     57  1.1.1.4.2.1  christos UINT32                      SigintCount = 0;
     58  1.1.1.4.2.1  christos #define ACPI_MAX_CONTROL_C  5
     59  1.1.1.4.2.1  christos 
     60  1.1.1.4.2.1  christos 
     61          1.1  christos /******************************************************************************
     62          1.1  christos  *
     63          1.1  christos  * FUNCTION:    AeExceptionHandler
     64          1.1  christos  *
     65          1.1  christos  * PARAMETERS:  Standard exception handler parameters
     66          1.1  christos  *
     67          1.1  christos  * RETURN:      Status
     68          1.1  christos  *
     69          1.1  christos  * DESCRIPTION: System exception handler for AcpiExec utility. Called from
     70          1.1  christos  *              the core ACPICA code after any exception during method
     71          1.1  christos  *              execution.
     72          1.1  christos  *
     73          1.1  christos  *****************************************************************************/
     74          1.1  christos 
     75          1.1  christos ACPI_STATUS
     76          1.1  christos AeExceptionHandler (
     77          1.1  christos     ACPI_STATUS             AmlStatus,
     78          1.1  christos     ACPI_NAME               Name,
     79          1.1  christos     UINT16                  Opcode,
     80          1.1  christos     UINT32                  AmlOffset,
     81          1.1  christos     void                    *Context)
     82          1.1  christos {
     83          1.1  christos     ACPI_STATUS             NewAmlStatus = AmlStatus;
     84          1.1  christos     ACPI_STATUS             Status;
     85          1.1  christos     ACPI_BUFFER             ReturnObj;
     86          1.1  christos     ACPI_OBJECT_LIST        ArgList;
     87          1.1  christos     ACPI_OBJECT             Arg[3];
     88          1.1  christos     const char              *Exception;
     89          1.1  christos     ACPI_HANDLE             ErrHandle;
     90          1.1  christos 
     91          1.1  christos 
     92          1.1  christos     Exception = AcpiFormatException (AmlStatus);
     93      1.1.1.2  christos 
     94  1.1.1.4.2.1  christos     if (AcpiGbl_VerboseHandlers)
     95          1.1  christos     {
     96  1.1.1.4.2.1  christos         AcpiOsPrintf (AE_PREFIX
     97  1.1.1.4.2.1  christos             "Exception %s during execution\n", Exception);
     98  1.1.1.4.2.1  christos 
     99  1.1.1.4.2.1  christos         if (Name)
    100      1.1.1.4  christos         {
    101  1.1.1.4.2.1  christos             if (ACPI_COMPARE_NAMESEG (&Name, ACPI_ROOT_PATHNAME))
    102  1.1.1.4.2.1  christos             {
    103  1.1.1.4.2.1  christos                 AcpiOsPrintf (AE_PREFIX
    104  1.1.1.4.2.1  christos                     "Evaluating executable code at [%s]\n", ACPI_NAMESPACE_ROOT);
    105  1.1.1.4.2.1  christos             }
    106  1.1.1.4.2.1  christos             else
    107  1.1.1.4.2.1  christos             {
    108  1.1.1.4.2.1  christos                 AcpiOsPrintf (AE_PREFIX
    109  1.1.1.4.2.1  christos                     "Evaluating Method or Node: [%4.4s]\n", (char *) &Name);
    110  1.1.1.4.2.1  christos             }
    111      1.1.1.4  christos         }
    112  1.1.1.4.2.1  christos 
    113  1.1.1.4.2.1  christos         /* Be terse about loop timeouts */
    114  1.1.1.4.2.1  christos 
    115  1.1.1.4.2.1  christos         if ((AmlStatus == AE_AML_LOOP_TIMEOUT) && AcpiGbl_AbortLoopOnTimeout)
    116      1.1.1.4  christos         {
    117  1.1.1.4.2.1  christos             AcpiOsPrintf (AE_PREFIX "Aborting loop after timeout\n");
    118  1.1.1.4.2.1  christos             return (AE_OK);
    119      1.1.1.4  christos         }
    120          1.1  christos 
    121  1.1.1.4.2.1  christos         AcpiOsPrintf ("\n" AE_PREFIX
    122  1.1.1.4.2.1  christos             "AML Opcode [%s], Method Offset ~%5.5X\n",
    123  1.1.1.4.2.1  christos             AcpiPsGetOpcodeName (Opcode), AmlOffset);
    124      1.1.1.2  christos     }
    125      1.1.1.2  christos 
    126          1.1  christos     /* Invoke the _ERR method if present */
    127          1.1  christos 
    128          1.1  christos     Status = AcpiGetHandle (NULL, "\\_ERR", &ErrHandle);
    129          1.1  christos     if (ACPI_FAILURE (Status))
    130          1.1  christos     {
    131          1.1  christos         goto Cleanup;
    132          1.1  christos     }
    133          1.1  christos 
    134          1.1  christos     /* Setup parameter object */
    135          1.1  christos 
    136          1.1  christos     ArgList.Count = 3;
    137          1.1  christos     ArgList.Pointer = Arg;
    138          1.1  christos 
    139          1.1  christos     Arg[0].Type = ACPI_TYPE_INTEGER;
    140          1.1  christos     Arg[0].Integer.Value = AmlStatus;
    141          1.1  christos 
    142          1.1  christos     Arg[1].Type = ACPI_TYPE_STRING;
    143          1.1  christos     Arg[1].String.Pointer = ACPI_CAST_PTR (char, Exception);
    144          1.1  christos     Arg[1].String.Length = strlen (Exception);
    145          1.1  christos 
    146          1.1  christos     Arg[2].Type = ACPI_TYPE_INTEGER;
    147          1.1  christos     Arg[2].Integer.Value = AcpiOsGetThreadId();
    148          1.1  christos 
    149          1.1  christos     /* Setup return buffer */
    150          1.1  christos 
    151          1.1  christos     ReturnObj.Pointer = NULL;
    152          1.1  christos     ReturnObj.Length = ACPI_ALLOCATE_BUFFER;
    153          1.1  christos 
    154          1.1  christos     Status = AcpiEvaluateObject (ErrHandle, NULL, &ArgList, &ReturnObj);
    155          1.1  christos     if (ACPI_SUCCESS (Status))
    156          1.1  christos     {
    157          1.1  christos         if (ReturnObj.Pointer)
    158          1.1  christos         {
    159          1.1  christos             /* Override original status */
    160          1.1  christos 
    161          1.1  christos             NewAmlStatus = (ACPI_STATUS)
    162          1.1  christos                 ((ACPI_OBJECT *) ReturnObj.Pointer)->Integer.Value;
    163          1.1  christos 
    164          1.1  christos             /* Free a buffer created via ACPI_ALLOCATE_BUFFER */
    165          1.1  christos 
    166          1.1  christos             AcpiOsFree (ReturnObj.Pointer);
    167          1.1  christos         }
    168          1.1  christos     }
    169          1.1  christos     else if (Status != AE_NOT_FOUND)
    170          1.1  christos     {
    171          1.1  christos         AcpiOsPrintf (AE_PREFIX
    172          1.1  christos             "Could not execute _ERR method, %s\n",
    173          1.1  christos             AcpiFormatException (Status));
    174          1.1  christos     }
    175          1.1  christos 
    176          1.1  christos Cleanup:
    177          1.1  christos 
    178          1.1  christos     if (AcpiGbl_IgnoreErrors)
    179          1.1  christos     {
    180          1.1  christos         /* Global option to ignore all method errors, just return OK */
    181          1.1  christos 
    182          1.1  christos         NewAmlStatus = AE_OK;
    183          1.1  christos     }
    184          1.1  christos     if (NewAmlStatus != AmlStatus)
    185          1.1  christos     {
    186          1.1  christos         /* Request to override actual status with a different status */
    187          1.1  christos 
    188          1.1  christos         AcpiOsPrintf (AE_PREFIX
    189          1.1  christos             "Exception override, new status %s\n\n",
    190          1.1  christos             AcpiFormatException (NewAmlStatus));
    191          1.1  christos     }
    192          1.1  christos 
    193          1.1  christos     return (NewAmlStatus);
    194          1.1  christos }
    195          1.1  christos 
    196          1.1  christos 
    197          1.1  christos /******************************************************************************
    198          1.1  christos  *
    199          1.1  christos  * FUNCTION:    AeSignalHandler
    200          1.1  christos  *
    201          1.1  christos  * PARAMETERS:  Sig
    202          1.1  christos  *
    203          1.1  christos  * RETURN:      none
    204          1.1  christos  *
    205          1.1  christos  * DESCRIPTION: Master signal handler. Currently handles SIGINT (ctrl-c),
    206          1.1  christos  *              and SIGSEGV (Segment violation).
    207          1.1  christos  *
    208          1.1  christos  *****************************************************************************/
    209          1.1  christos 
    210          1.1  christos void ACPI_SYSTEM_XFACE
    211          1.1  christos AeSignalHandler (
    212          1.1  christos     int                     Sig)
    213          1.1  christos {
    214          1.1  christos 
    215          1.1  christos     fflush(stdout);
    216          1.1  christos     AcpiOsPrintf ("\n" AE_PREFIX);
    217          1.1  christos 
    218          1.1  christos     switch (Sig)
    219          1.1  christos     {
    220          1.1  christos     case SIGINT:
    221          1.1  christos         signal(Sig, SIG_IGN);
    222          1.1  christos         AcpiOsPrintf ("<Control-C>\n");
    223          1.1  christos 
    224  1.1.1.4.2.1  christos         /* Force exit on multiple control-c */
    225  1.1.1.4.2.1  christos 
    226  1.1.1.4.2.1  christos         SigintCount++;
    227  1.1.1.4.2.1  christos         if (SigintCount >= ACPI_MAX_CONTROL_C)
    228  1.1.1.4.2.1  christos         {
    229  1.1.1.4.2.1  christos             exit (0);
    230  1.1.1.4.2.1  christos         }
    231  1.1.1.4.2.1  christos 
    232          1.1  christos         /* Abort the application if there are no methods executing */
    233          1.1  christos 
    234          1.1  christos         if (!AcpiGbl_MethodExecuting)
    235          1.1  christos         {
    236          1.1  christos             break;
    237          1.1  christos         }
    238          1.1  christos 
    239          1.1  christos         /*
    240          1.1  christos          * Abort the method(s). This will also dump the method call
    241          1.1  christos          * stack so there is no need to do it here. The application
    242          1.1  christos          * will then drop back into the debugger interface.
    243          1.1  christos          */
    244          1.1  christos         AcpiGbl_AbortMethod = TRUE;
    245          1.1  christos         AcpiOsPrintf (AE_PREFIX "Control Method Call Stack:\n");
    246          1.1  christos         signal (SIGINT, AeSignalHandler);
    247          1.1  christos         return;
    248          1.1  christos 
    249          1.1  christos     case SIGSEGV:
    250          1.1  christos         AcpiOsPrintf ("Segmentation Fault\n");
    251          1.1  christos         AeDisplayMethodCallStack ();
    252          1.1  christos         break;
    253          1.1  christos 
    254          1.1  christos     default:
    255          1.1  christos         AcpiOsPrintf ("Unknown Signal, %X\n", Sig);
    256          1.1  christos         break;
    257          1.1  christos     }
    258          1.1  christos 
    259          1.1  christos     /* Terminate application -- cleanup then exit */
    260          1.1  christos 
    261          1.1  christos     AcpiOsPrintf (AE_PREFIX "Terminating\n");
    262          1.1  christos     (void) AcpiOsTerminate ();
    263          1.1  christos     exit (0);
    264          1.1  christos }
    265          1.1  christos 
    266          1.1  christos 
    267          1.1  christos /******************************************************************************
    268          1.1  christos  *
    269          1.1  christos  * FUNCTION:    AeDisplayMethodCallStack
    270          1.1  christos  *
    271          1.1  christos  * PARAMETERS:  None
    272          1.1  christos  *
    273          1.1  christos  * RETURN:      None
    274          1.1  christos  *
    275          1.1  christos  * DESCRIPTION: Display current method call stack, if possible.
    276          1.1  christos  *
    277          1.1  christos  * NOTE:        Currently only called from a SIGSEGV, so AcpiExec is about
    278          1.1  christos  *              to terminate.
    279          1.1  christos  *
    280          1.1  christos  *****************************************************************************/
    281          1.1  christos 
    282          1.1  christos static void
    283          1.1  christos AeDisplayMethodCallStack (
    284          1.1  christos     void)
    285          1.1  christos {
    286          1.1  christos     ACPI_WALK_STATE         *WalkState;
    287          1.1  christos     ACPI_THREAD_STATE       *ThreadList = AcpiGbl_CurrentWalkList;
    288          1.1  christos     char                    *FullPathname = NULL;
    289          1.1  christos 
    290          1.1  christos 
    291          1.1  christos     if (!AcpiGbl_MethodExecuting)
    292          1.1  christos     {
    293          1.1  christos         AcpiOsPrintf (AE_PREFIX "No method is executing\n");
    294          1.1  christos         return;
    295          1.1  christos     }
    296          1.1  christos 
    297          1.1  christos     /*
    298          1.1  christos      * Try to find the currently executing control method(s)
    299          1.1  christos      *
    300          1.1  christos      * Note: The following code may fault if the data structures are
    301          1.1  christos      * in an indeterminate state when the interrupt occurs. However,
    302          1.1  christos      * in practice, this works quite well and can provide very
    303          1.1  christos      * valuable information.
    304          1.1  christos      *
    305          1.1  christos      * 1) Walk the global thread list
    306          1.1  christos      */
    307          1.1  christos     while (ThreadList &&
    308          1.1  christos         (ThreadList->DescriptorType == ACPI_DESC_TYPE_STATE_THREAD))
    309          1.1  christos     {
    310          1.1  christos         /* 2) Walk the walk state list for this thread */
    311          1.1  christos 
    312          1.1  christos         WalkState = ThreadList->WalkStateList;
    313          1.1  christos         while (WalkState &&
    314          1.1  christos             (WalkState->DescriptorType == ACPI_DESC_TYPE_WALK))
    315          1.1  christos         {
    316          1.1  christos             /* An executing control method */
    317          1.1  christos 
    318          1.1  christos             if (WalkState->MethodNode)
    319          1.1  christos             {
    320          1.1  christos                 FullPathname = AcpiNsGetExternalPathname (
    321          1.1  christos                     WalkState->MethodNode);
    322          1.1  christos 
    323          1.1  christos                 AcpiOsPrintf (AE_PREFIX
    324          1.1  christos                     "Executing Method: %s\n", FullPathname);
    325          1.1  christos             }
    326          1.1  christos 
    327          1.1  christos             /* Execution of a deferred opcode/node */
    328          1.1  christos 
    329          1.1  christos             if (WalkState->DeferredNode)
    330          1.1  christos             {
    331          1.1  christos                 FullPathname = AcpiNsGetExternalPathname (
    332          1.1  christos                     WalkState->DeferredNode);
    333          1.1  christos 
    334          1.1  christos                 AcpiOsPrintf (AE_PREFIX
    335          1.1  christos                     "Evaluating deferred node: %s\n", FullPathname);
    336          1.1  christos             }
    337          1.1  christos 
    338          1.1  christos             /* Get the currently executing AML opcode */
    339          1.1  christos 
    340          1.1  christos             if ((WalkState->Opcode != AML_INT_METHODCALL_OP) &&
    341          1.1  christos                 FullPathname)
    342          1.1  christos             {
    343          1.1  christos                 AcpiOsPrintf (AE_PREFIX
    344          1.1  christos                     "Current AML Opcode in %s: [%s]-0x%4.4X at %p\n",
    345          1.1  christos                     FullPathname, AcpiPsGetOpcodeName (WalkState->Opcode),
    346          1.1  christos                     WalkState->Opcode, WalkState->Aml);
    347          1.1  christos             }
    348          1.1  christos 
    349          1.1  christos             if (FullPathname)
    350          1.1  christos             {
    351          1.1  christos                 ACPI_FREE (FullPathname);
    352          1.1  christos                 FullPathname = NULL;
    353          1.1  christos             }
    354          1.1  christos 
    355          1.1  christos             WalkState = WalkState->Next;
    356          1.1  christos         }
    357          1.1  christos 
    358          1.1  christos         ThreadList = ThreadList->Next;
    359          1.1  christos     }
    360          1.1  christos }
    361