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