fix comment
[AROS.git] / rom / exec / supervisoralert.c
blob2f55ce1164e35fc0947d2e5b24265151550ff0f1
1 /*
2 Copyright © 2012-2015, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Display an alert passed from supervisor mode.
6 Lang: english
7 */
9 #include <aros/debug.h>
10 #include <exec/alerts.h>
11 #include <exec/rawfmt.h>
12 #include <intuition/intuition.h>
13 #include <proto/exec.h>
14 #include <proto/intuition.h>
15 #include <proto/kernel.h>
17 #include "etask.h"
18 #include "exec_intern.h"
19 #include "exec_util.h"
21 LONG Alert_AskSuspend(struct Task *task, ULONG alertNum, char * buffer, struct ExecBase *SysBase);
22 void Alert_DisplayKrnAlert(struct Task * task, ULONG alertNum, APTR location, APTR stack, UBYTE type, APTR data,
23 struct ExecBase *SysBase);
26 * This task tries to display alerts that occured in supervisor mode. The task that caused the
27 * problem is available in SAT.sat_Params[1]. The code that raised Alert is responsible for
28 * stopping/sanitizing the task itself. Since the task is already stopped, AT_DeadEnd is added to
29 * when invoking alert functions so that user does not have an option to continue the task.
31 void SupervisorAlertTask(struct ExecBase *SysBase)
33 struct IntExecBase * IntSysBase = PrivExecBase(SysBase);
34 char * buffer = AllocMem(ALERT_BUFFER_SIZE, MEMF_ANY);
35 LONG res, i;
36 struct Task * t = NULL;
37 ULONG alertNum = 0;
39 IntSysBase->SAT.sat_Task = GET_THIS_TASK;
40 IntSysBase->SAT.sat_IsAvailable = TRUE;
42 while(TRUE)
44 Wait(SIGF_SINGLE);
46 Disable();
47 /* Mark task as in use so that nested crash will use critical error path, see Exec_SystemAlert */
48 IntSysBase->SAT.sat_IsAvailable = FALSE;
49 t = (struct Task*)IntSysBase->SAT.sat_Params[1];
50 alertNum = IntSysBase->SAT.sat_Params[0];
51 Enable();
53 res = Alert_AskSuspend(t, alertNum | AT_DeadEnd, buffer, SysBase);
55 if (res == -1)
57 /* It was not possible to report error to user, fallback to critical error path */
58 struct IntETask * iet = GetIntETask(t);
59 Disable();
61 Alert_DisplayKrnAlert(t, alertNum | AT_DeadEnd, iet->iet_AlertLocation, iet->iet_AlertStack,
62 iet->iet_AlertType, (APTR)&iet->iet_AlertData, SysBase);
64 if (alertNum & AT_DeadEnd)
66 /* Um, we have to do something here in order to prevent the
67 computer from continuing... */
68 ColdReboot();
69 ShutdownA(SD_ACTION_COLDREBOOT);
72 Enable();
75 switch (res)
77 case 0:
78 ShutdownA(SD_ACTION_POWEROFF);
79 break;
81 case 2:
82 /* Suspend actually should have already happened by code raising Alert */
83 break;
85 case 3:
86 ColdReboot();
87 /* In case if ColdReboot() doesn't work */
88 ShutdownA(SD_ACTION_COLDREBOOT);
89 break;
93 Disable();
94 /* Mark task as available */
95 IntSysBase->SAT.sat_IsAvailable = TRUE;
96 for (i = 0; i < 2; i++)
97 IntSysBase->SAT.sat_Params[i] = (IPTR)NULL;
98 t = NULL;
99 alertNum = 0;
100 Enable();