File: aeexception.c

package info (click to toggle)
acpica-unix 20181213-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 40,744 kB
  • sloc: ansic: 128,238; sh: 4,389; yacc: 4,184; makefile: 1,385; lex: 1,124
file content (360 lines) | stat: -rw-r--r-- 10,446 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
/******************************************************************************
 *
 * Module Name: aeexception - Exception and signal handlers
 *
 *****************************************************************************/

/*
 * Copyright (C) 2000 - 2018, Intel Corp.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions, and the following disclaimer,
 *    without modification.
 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
 *    substantially similar to the "NO WARRANTY" disclaimer below
 *    ("Disclaimer") and any redistribution must be conditioned upon
 *    including a substantially similar Disclaimer requirement for further
 *    binary redistribution.
 * 3. Neither the names of the above-listed copyright holders nor the names
 *    of any contributors may be used to endorse or promote products derived
 *    from this software without specific prior written permission.
 *
 * Alternatively, this software may be distributed under the terms of the
 * GNU General Public License ("GPL") version 2 as published by the Free
 * Software Foundation.
 *
 * NO WARRANTY
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGES.
 */

#include "aecommon.h"

#define _COMPONENT          ACPI_TOOLS
        ACPI_MODULE_NAME    ("aeexception")


/* Local prototypes */

static void
AeDisplayMethodCallStack (
    void);


UINT32                      SigintCount = 0;
#define ACPI_MAX_CONTROL_C  5


/******************************************************************************
 *
 * FUNCTION:    AeExceptionHandler
 *
 * PARAMETERS:  Standard exception handler parameters
 *
 * RETURN:      Status
 *
 * DESCRIPTION: System exception handler for AcpiExec utility. Called from
 *              the core ACPICA code after any exception during method
 *              execution.
 *
 *****************************************************************************/

ACPI_STATUS
AeExceptionHandler (
    ACPI_STATUS             AmlStatus,
    ACPI_NAME               Name,
    UINT16                  Opcode,
    UINT32                  AmlOffset,
    void                    *Context)
{
    ACPI_STATUS             NewAmlStatus = AmlStatus;
    ACPI_STATUS             Status;
    ACPI_BUFFER             ReturnObj;
    ACPI_OBJECT_LIST        ArgList;
    ACPI_OBJECT             Arg[3];
    const char              *Exception;
    ACPI_HANDLE             ErrHandle;


    Exception = AcpiFormatException (AmlStatus);

    if (AcpiGbl_VerboseHandlers)
    {
        AcpiOsPrintf (AE_PREFIX
            "Exception %s during execution\n", Exception);

        if (Name)
        {
            if (ACPI_COMPARE_NAME (&Name, ACPI_ROOT_PATHNAME))
            {
                AcpiOsPrintf (AE_PREFIX
                    "Evaluating executable code at [%s]\n", ACPI_NAMESPACE_ROOT);
            }
            else
            {
                AcpiOsPrintf (AE_PREFIX
                    "Evaluating Method or Node: [%4.4s]\n", (char *) &Name);
            }
        }

        /* Be terse about loop timeouts */

        if ((AmlStatus == AE_AML_LOOP_TIMEOUT) && AcpiGbl_AbortLoopOnTimeout)
        {
            AcpiOsPrintf (AE_PREFIX "Aborting loop after timeout\n");
            return (AE_OK);
        }

        AcpiOsPrintf ("\n" AE_PREFIX
            "AML Opcode [%s], Method Offset ~%5.5X\n",
            AcpiPsGetOpcodeName (Opcode), AmlOffset);
    }

    /* Invoke the _ERR method if present */

    Status = AcpiGetHandle (NULL, "\\_ERR", &ErrHandle);
    if (ACPI_FAILURE (Status))
    {
        goto Cleanup;
    }

    /* Setup parameter object */

    ArgList.Count = 3;
    ArgList.Pointer = Arg;

    Arg[0].Type = ACPI_TYPE_INTEGER;
    Arg[0].Integer.Value = AmlStatus;

    Arg[1].Type = ACPI_TYPE_STRING;
    Arg[1].String.Pointer = ACPI_CAST_PTR (char, Exception);
    Arg[1].String.Length = strlen (Exception);

    Arg[2].Type = ACPI_TYPE_INTEGER;
    Arg[2].Integer.Value = AcpiOsGetThreadId();

    /* Setup return buffer */

    ReturnObj.Pointer = NULL;
    ReturnObj.Length = ACPI_ALLOCATE_BUFFER;

    Status = AcpiEvaluateObject (ErrHandle, NULL, &ArgList, &ReturnObj);
    if (ACPI_SUCCESS (Status))
    {
        if (ReturnObj.Pointer)
        {
            /* Override original status */

            NewAmlStatus = (ACPI_STATUS)
                ((ACPI_OBJECT *) ReturnObj.Pointer)->Integer.Value;

            /* Free a buffer created via ACPI_ALLOCATE_BUFFER */

            AcpiOsFree (ReturnObj.Pointer);
        }
    }
    else if (Status != AE_NOT_FOUND)
    {
        AcpiOsPrintf (AE_PREFIX
            "Could not execute _ERR method, %s\n",
            AcpiFormatException (Status));
    }

Cleanup:

    if (AcpiGbl_IgnoreErrors)
    {
        /* Global option to ignore all method errors, just return OK */

        NewAmlStatus = AE_OK;
    }
    if (NewAmlStatus != AmlStatus)
    {
        /* Request to override actual status with a different status */

        AcpiOsPrintf (AE_PREFIX
            "Exception override, new status %s\n\n",
            AcpiFormatException (NewAmlStatus));
    }

    return (NewAmlStatus);
}


/******************************************************************************
 *
 * FUNCTION:    AeSignalHandler
 *
 * PARAMETERS:  Sig
 *
 * RETURN:      none
 *
 * DESCRIPTION: Master signal handler. Currently handles SIGINT (ctrl-c),
 *              and SIGSEGV (Segment violation).
 *
 *****************************************************************************/

void ACPI_SYSTEM_XFACE
AeSignalHandler (
    int                     Sig)
{

    fflush(stdout);
    AcpiOsPrintf ("\n" AE_PREFIX);

    switch (Sig)
    {
    case SIGINT:
        signal(Sig, SIG_IGN);
        AcpiOsPrintf ("<Control-C>\n");

        /* Force exit on multiple control-c */

        SigintCount++;
        if (SigintCount >= ACPI_MAX_CONTROL_C)
        {
            exit (0);
        }

        /* Abort the application if there are no methods executing */

        if (!AcpiGbl_MethodExecuting)
        {
            break;
        }

        /*
         * Abort the method(s). This will also dump the method call
         * stack so there is no need to do it here. The application
         * will then drop back into the debugger interface.
         */
        AcpiGbl_AbortMethod = TRUE;
        AcpiOsPrintf (AE_PREFIX "Control Method Call Stack:\n");
        signal (SIGINT, AeSignalHandler);
        return;

    case SIGSEGV:
        AcpiOsPrintf ("Segmentation Fault\n");
        AeDisplayMethodCallStack ();
        break;

    default:
        AcpiOsPrintf ("Unknown Signal, %X\n", Sig);
        break;
    }

    /* Terminate application -- cleanup then exit */

    AcpiOsPrintf (AE_PREFIX "Terminating\n");
    (void) AcpiOsTerminate ();
    exit (0);
}


/******************************************************************************
 *
 * FUNCTION:    AeDisplayMethodCallStack
 *
 * PARAMETERS:  None
 *
 * RETURN:      None
 *
 * DESCRIPTION: Display current method call stack, if possible.
 *
 * NOTE:        Currently only called from a SIGSEGV, so AcpiExec is about
 *              to terminate.
 *
 *****************************************************************************/

static void
AeDisplayMethodCallStack (
    void)
{
    ACPI_WALK_STATE         *WalkState;
    ACPI_THREAD_STATE       *ThreadList = AcpiGbl_CurrentWalkList;
    char                    *FullPathname = NULL;


    if (!AcpiGbl_MethodExecuting)
    {
        AcpiOsPrintf (AE_PREFIX "No method is executing\n");
        return;
    }

    /*
     * Try to find the currently executing control method(s)
     *
     * Note: The following code may fault if the data structures are
     * in an indeterminate state when the interrupt occurs. However,
     * in practice, this works quite well and can provide very
     * valuable information.
     *
     * 1) Walk the global thread list
     */
    while (ThreadList &&
        (ThreadList->DescriptorType == ACPI_DESC_TYPE_STATE_THREAD))
    {
        /* 2) Walk the walk state list for this thread */

        WalkState = ThreadList->WalkStateList;
        while (WalkState &&
            (WalkState->DescriptorType == ACPI_DESC_TYPE_WALK))
        {
            /* An executing control method */

            if (WalkState->MethodNode)
            {
                FullPathname = AcpiNsGetExternalPathname (
                    WalkState->MethodNode);

                AcpiOsPrintf (AE_PREFIX
                    "Executing Method: %s\n", FullPathname);
            }

            /* Execution of a deferred opcode/node */

            if (WalkState->DeferredNode)
            {
                FullPathname = AcpiNsGetExternalPathname (
                    WalkState->DeferredNode);

                AcpiOsPrintf (AE_PREFIX
                    "Evaluating deferred node: %s\n", FullPathname);
            }

            /* Get the currently executing AML opcode */

            if ((WalkState->Opcode != AML_INT_METHODCALL_OP) &&
                FullPathname)
            {
                AcpiOsPrintf (AE_PREFIX
                    "Current AML Opcode in %s: [%s]-0x%4.4X at %p\n",
                    FullPathname, AcpiPsGetOpcodeName (WalkState->Opcode),
                    WalkState->Opcode, WalkState->Aml);
            }

            if (FullPathname)
            {
                ACPI_FREE (FullPathname);
                FullPathname = NULL;
            }

            WalkState = WalkState->Next;
        }

        ThreadList = ThreadList->Next;
    }
}