Home | History | Annotate | Line # | Download | only in acpiexec
aeexception.c revision 1.1.1.2.4.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.2.4.1  pgoyette  * Copyright (C) 2000 - 2018, 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  christos /******************************************************************************
     58          1.1  christos  *
     59          1.1  christos  * FUNCTION:    AeExceptionHandler
     60          1.1  christos  *
     61          1.1  christos  * PARAMETERS:  Standard exception handler parameters
     62          1.1  christos  *
     63          1.1  christos  * RETURN:      Status
     64          1.1  christos  *
     65          1.1  christos  * DESCRIPTION: System exception handler for AcpiExec utility. Called from
     66          1.1  christos  *              the core ACPICA code after any exception during method
     67          1.1  christos  *              execution.
     68          1.1  christos  *
     69          1.1  christos  *****************************************************************************/
     70          1.1  christos 
     71          1.1  christos ACPI_STATUS
     72          1.1  christos AeExceptionHandler (
     73          1.1  christos     ACPI_STATUS             AmlStatus,
     74          1.1  christos     ACPI_NAME               Name,
     75          1.1  christos     UINT16                  Opcode,
     76          1.1  christos     UINT32                  AmlOffset,
     77          1.1  christos     void                    *Context)
     78          1.1  christos {
     79          1.1  christos     ACPI_STATUS             NewAmlStatus = AmlStatus;
     80          1.1  christos     ACPI_STATUS             Status;
     81          1.1  christos     ACPI_BUFFER             ReturnObj;
     82          1.1  christos     ACPI_OBJECT_LIST        ArgList;
     83          1.1  christos     ACPI_OBJECT             Arg[3];
     84          1.1  christos     const char              *Exception;
     85          1.1  christos     ACPI_HANDLE             ErrHandle;
     86          1.1  christos 
     87          1.1  christos 
     88          1.1  christos     Exception = AcpiFormatException (AmlStatus);
     89          1.1  christos     AcpiOsPrintf (AE_PREFIX
     90          1.1  christos         "Exception %s during execution\n", Exception);
     91      1.1.1.2  christos 
     92          1.1  christos     if (Name)
     93          1.1  christos     {
     94          1.1  christos         AcpiOsPrintf (AE_PREFIX
     95      1.1.1.2  christos             "Evaluating Method or Node: [%4.4s]\n",
     96          1.1  christos             (char *) &Name);
     97          1.1  christos     }
     98          1.1  christos 
     99      1.1.1.2  christos     /* Be terse about loop timeouts */
    100      1.1.1.2  christos 
    101      1.1.1.2  christos     if ((AmlStatus == AE_AML_LOOP_TIMEOUT) && AcpiGbl_AbortLoopOnTimeout)
    102      1.1.1.2  christos     {
    103      1.1.1.2  christos         AcpiOsPrintf (AE_PREFIX "Aborting loop after timeout\n");
    104      1.1.1.2  christos         return (AE_OK);
    105      1.1.1.2  christos     }
    106      1.1.1.2  christos 
    107          1.1  christos     AcpiOsPrintf ("\n" AE_PREFIX
    108          1.1  christos         "AML Opcode [%s], Method Offset ~%5.5X\n",
    109          1.1  christos         AcpiPsGetOpcodeName (Opcode), AmlOffset);
    110          1.1  christos 
    111          1.1  christos     /* Invoke the _ERR method if present */
    112          1.1  christos 
    113          1.1  christos     Status = AcpiGetHandle (NULL, "\\_ERR", &ErrHandle);
    114          1.1  christos     if (ACPI_FAILURE (Status))
    115          1.1  christos     {
    116          1.1  christos         goto Cleanup;
    117          1.1  christos     }
    118          1.1  christos 
    119          1.1  christos     /* Setup parameter object */
    120          1.1  christos 
    121          1.1  christos     ArgList.Count = 3;
    122          1.1  christos     ArgList.Pointer = Arg;
    123          1.1  christos 
    124          1.1  christos     Arg[0].Type = ACPI_TYPE_INTEGER;
    125          1.1  christos     Arg[0].Integer.Value = AmlStatus;
    126          1.1  christos 
    127          1.1  christos     Arg[1].Type = ACPI_TYPE_STRING;
    128          1.1  christos     Arg[1].String.Pointer = ACPI_CAST_PTR (char, Exception);
    129          1.1  christos     Arg[1].String.Length = strlen (Exception);
    130          1.1  christos 
    131          1.1  christos     Arg[2].Type = ACPI_TYPE_INTEGER;
    132          1.1  christos     Arg[2].Integer.Value = AcpiOsGetThreadId();
    133          1.1  christos 
    134          1.1  christos     /* Setup return buffer */
    135          1.1  christos 
    136          1.1  christos     ReturnObj.Pointer = NULL;
    137          1.1  christos     ReturnObj.Length = ACPI_ALLOCATE_BUFFER;
    138          1.1  christos 
    139          1.1  christos     Status = AcpiEvaluateObject (ErrHandle, NULL, &ArgList, &ReturnObj);
    140          1.1  christos     if (ACPI_SUCCESS (Status))
    141          1.1  christos     {
    142          1.1  christos         if (ReturnObj.Pointer)
    143          1.1  christos         {
    144          1.1  christos             /* Override original status */
    145          1.1  christos 
    146          1.1  christos             NewAmlStatus = (ACPI_STATUS)
    147          1.1  christos                 ((ACPI_OBJECT *) ReturnObj.Pointer)->Integer.Value;
    148          1.1  christos 
    149          1.1  christos             /* Free a buffer created via ACPI_ALLOCATE_BUFFER */
    150          1.1  christos 
    151          1.1  christos             AcpiOsFree (ReturnObj.Pointer);
    152          1.1  christos         }
    153          1.1  christos     }
    154          1.1  christos     else if (Status != AE_NOT_FOUND)
    155          1.1  christos     {
    156          1.1  christos         AcpiOsPrintf (AE_PREFIX
    157          1.1  christos             "Could not execute _ERR method, %s\n",
    158          1.1  christos             AcpiFormatException (Status));
    159          1.1  christos     }
    160          1.1  christos 
    161          1.1  christos Cleanup:
    162          1.1  christos 
    163          1.1  christos     if (AcpiGbl_IgnoreErrors)
    164          1.1  christos     {
    165          1.1  christos         /* Global option to ignore all method errors, just return OK */
    166          1.1  christos 
    167          1.1  christos         NewAmlStatus = AE_OK;
    168          1.1  christos     }
    169          1.1  christos     if (NewAmlStatus != AmlStatus)
    170          1.1  christos     {
    171          1.1  christos         /* Request to override actual status with a different status */
    172          1.1  christos 
    173          1.1  christos         AcpiOsPrintf (AE_PREFIX
    174          1.1  christos             "Exception override, new status %s\n\n",
    175          1.1  christos             AcpiFormatException (NewAmlStatus));
    176          1.1  christos     }
    177          1.1  christos 
    178          1.1  christos     return (NewAmlStatus);
    179          1.1  christos }
    180          1.1  christos 
    181          1.1  christos 
    182          1.1  christos /******************************************************************************
    183          1.1  christos  *
    184          1.1  christos  * FUNCTION:    AeSignalHandler
    185          1.1  christos  *
    186          1.1  christos  * PARAMETERS:  Sig
    187          1.1  christos  *
    188          1.1  christos  * RETURN:      none
    189          1.1  christos  *
    190          1.1  christos  * DESCRIPTION: Master signal handler. Currently handles SIGINT (ctrl-c),
    191          1.1  christos  *              and SIGSEGV (Segment violation).
    192          1.1  christos  *
    193          1.1  christos  *****************************************************************************/
    194          1.1  christos 
    195          1.1  christos void ACPI_SYSTEM_XFACE
    196          1.1  christos AeSignalHandler (
    197          1.1  christos     int                     Sig)
    198          1.1  christos {
    199          1.1  christos 
    200          1.1  christos     fflush(stdout);
    201          1.1  christos     AcpiOsPrintf ("\n" AE_PREFIX);
    202          1.1  christos 
    203          1.1  christos     switch (Sig)
    204          1.1  christos     {
    205          1.1  christos     case SIGINT:
    206          1.1  christos         signal(Sig, SIG_IGN);
    207          1.1  christos         AcpiOsPrintf ("<Control-C>\n");
    208          1.1  christos 
    209          1.1  christos         /* Abort the application if there are no methods executing */
    210          1.1  christos 
    211          1.1  christos         if (!AcpiGbl_MethodExecuting)
    212          1.1  christos         {
    213          1.1  christos             break;
    214          1.1  christos         }
    215          1.1  christos 
    216          1.1  christos         /*
    217          1.1  christos          * Abort the method(s). This will also dump the method call
    218          1.1  christos          * stack so there is no need to do it here. The application
    219          1.1  christos          * will then drop back into the debugger interface.
    220          1.1  christos          */
    221          1.1  christos         AcpiGbl_AbortMethod = TRUE;
    222          1.1  christos         AcpiOsPrintf (AE_PREFIX "Control Method Call Stack:\n");
    223          1.1  christos         signal (SIGINT, AeSignalHandler);
    224          1.1  christos         return;
    225          1.1  christos 
    226          1.1  christos     case SIGSEGV:
    227          1.1  christos         AcpiOsPrintf ("Segmentation Fault\n");
    228          1.1  christos         AeDisplayMethodCallStack ();
    229          1.1  christos         break;
    230          1.1  christos 
    231          1.1  christos     default:
    232          1.1  christos         AcpiOsPrintf ("Unknown Signal, %X\n", Sig);
    233          1.1  christos         break;
    234          1.1  christos     }
    235          1.1  christos 
    236          1.1  christos     /* Terminate application -- cleanup then exit */
    237          1.1  christos 
    238          1.1  christos     AcpiOsPrintf (AE_PREFIX "Terminating\n");
    239          1.1  christos     (void) AcpiOsTerminate ();
    240          1.1  christos     exit (0);
    241          1.1  christos }
    242          1.1  christos 
    243          1.1  christos 
    244          1.1  christos /******************************************************************************
    245          1.1  christos  *
    246          1.1  christos  * FUNCTION:    AeDisplayMethodCallStack
    247          1.1  christos  *
    248          1.1  christos  * PARAMETERS:  None
    249          1.1  christos  *
    250          1.1  christos  * RETURN:      None
    251          1.1  christos  *
    252          1.1  christos  * DESCRIPTION: Display current method call stack, if possible.
    253          1.1  christos  *
    254          1.1  christos  * NOTE:        Currently only called from a SIGSEGV, so AcpiExec is about
    255          1.1  christos  *              to terminate.
    256          1.1  christos  *
    257          1.1  christos  *****************************************************************************/
    258          1.1  christos 
    259          1.1  christos static void
    260          1.1  christos AeDisplayMethodCallStack (
    261          1.1  christos     void)
    262          1.1  christos {
    263          1.1  christos     ACPI_WALK_STATE         *WalkState;
    264          1.1  christos     ACPI_THREAD_STATE       *ThreadList = AcpiGbl_CurrentWalkList;
    265          1.1  christos     char                    *FullPathname = NULL;
    266          1.1  christos 
    267          1.1  christos 
    268          1.1  christos     if (!AcpiGbl_MethodExecuting)
    269          1.1  christos     {
    270          1.1  christos         AcpiOsPrintf (AE_PREFIX "No method is executing\n");
    271          1.1  christos         return;
    272          1.1  christos     }
    273          1.1  christos 
    274          1.1  christos     /*
    275          1.1  christos      * Try to find the currently executing control method(s)
    276          1.1  christos      *
    277          1.1  christos      * Note: The following code may fault if the data structures are
    278          1.1  christos      * in an indeterminate state when the interrupt occurs. However,
    279          1.1  christos      * in practice, this works quite well and can provide very
    280          1.1  christos      * valuable information.
    281          1.1  christos      *
    282          1.1  christos      * 1) Walk the global thread list
    283          1.1  christos      */
    284          1.1  christos     while (ThreadList &&
    285          1.1  christos         (ThreadList->DescriptorType == ACPI_DESC_TYPE_STATE_THREAD))
    286          1.1  christos     {
    287          1.1  christos         /* 2) Walk the walk state list for this thread */
    288          1.1  christos 
    289          1.1  christos         WalkState = ThreadList->WalkStateList;
    290          1.1  christos         while (WalkState &&
    291          1.1  christos             (WalkState->DescriptorType == ACPI_DESC_TYPE_WALK))
    292          1.1  christos         {
    293          1.1  christos             /* An executing control method */
    294          1.1  christos 
    295          1.1  christos             if (WalkState->MethodNode)
    296          1.1  christos             {
    297          1.1  christos                 FullPathname = AcpiNsGetExternalPathname (
    298          1.1  christos                     WalkState->MethodNode);
    299          1.1  christos 
    300          1.1  christos                 AcpiOsPrintf (AE_PREFIX
    301          1.1  christos                     "Executing Method: %s\n", FullPathname);
    302          1.1  christos             }
    303          1.1  christos 
    304          1.1  christos             /* Execution of a deferred opcode/node */
    305          1.1  christos 
    306          1.1  christos             if (WalkState->DeferredNode)
    307          1.1  christos             {
    308          1.1  christos                 FullPathname = AcpiNsGetExternalPathname (
    309          1.1  christos                     WalkState->DeferredNode);
    310          1.1  christos 
    311          1.1  christos                 AcpiOsPrintf (AE_PREFIX
    312          1.1  christos                     "Evaluating deferred node: %s\n", FullPathname);
    313          1.1  christos             }
    314          1.1  christos 
    315          1.1  christos             /* Get the currently executing AML opcode */
    316          1.1  christos 
    317          1.1  christos             if ((WalkState->Opcode != AML_INT_METHODCALL_OP) &&
    318          1.1  christos                 FullPathname)
    319          1.1  christos             {
    320          1.1  christos                 AcpiOsPrintf (AE_PREFIX
    321          1.1  christos                     "Current AML Opcode in %s: [%s]-0x%4.4X at %p\n",
    322          1.1  christos                     FullPathname, AcpiPsGetOpcodeName (WalkState->Opcode),
    323          1.1  christos                     WalkState->Opcode, WalkState->Aml);
    324          1.1  christos             }
    325          1.1  christos 
    326          1.1  christos             if (FullPathname)
    327          1.1  christos             {
    328          1.1  christos                 ACPI_FREE (FullPathname);
    329          1.1  christos                 FullPathname = NULL;
    330          1.1  christos             }
    331          1.1  christos 
    332          1.1  christos             WalkState = WalkState->Next;
    333          1.1  christos         }
    334          1.1  christos 
    335          1.1  christos         ThreadList = ThreadList->Next;
    336          1.1  christos     }
    337          1.1  christos }
    338