do not expose uint_least16_t or uint_least32_t if __UINT_LEAST16_TYPE__ && __UINT_LEA...
[AROS.git] / rom / exec / supervisoralert.c
blobd0648df36ca9e6978a42e082435fb2539bb21730
1 /*
2 Copyright © 2012-2017, 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>
16 #include "etask.h"
17 #include "exec_intern.h"
18 #include "exec_util.h"
20 LONG Alert_AskSuspend(struct Task *task, ULONG alertNum, char * buffer, struct ExecBase *SysBase);
21 void Alert_DisplayKrnAlert(struct Task * task, ULONG alertNum, APTR location, APTR stack, UBYTE type, APTR data,
22 struct ExecBase *SysBase);
25 * This task tries to display alerts that occured in supervisor mode. The task that caused the
26 * problem is available in SAT.sat_Params[1]. The code that raised Alert is responsible for
27 * stopping/sanitizing the task itself. Since the task is already stopped, AT_DeadEnd is added to
28 * when invoking alert functions so that user does not have an option to continue the task.
30 void SupervisorAlertTask(struct ExecBase *SysBase)
32 struct IntExecBase * IntSysBase = PrivExecBase(SysBase);
33 char * buffer = AllocMem(ALERT_BUFFER_SIZE, MEMF_ANY);
34 LONG res, i;
35 struct Task * t = NULL;
36 ULONG alertNum = 0;
38 IntSysBase->SAT.sat_Task = GET_THIS_TASK;
39 IntSysBase->SAT.sat_IsAvailable = TRUE;
41 while(TRUE)
43 Wait(SIGF_SINGLE);
45 Disable();
46 /* Mark task as in use so that nested crash will use critical error path, see Exec_SystemAlert */
47 IntSysBase->SAT.sat_IsAvailable = FALSE;
48 t = (struct Task*)IntSysBase->SAT.sat_Params[1];
49 alertNum = IntSysBase->SAT.sat_Params[0];
50 Enable();
52 res = Alert_AskSuspend(t, alertNum | AT_DeadEnd, buffer, SysBase);
54 if (res == -1)
56 /* It was not possible to report error to user, fallback to critical error path */
57 struct IntETask * iet = GetIntETask(t);
58 Disable();
60 Alert_DisplayKrnAlert(t, alertNum | AT_DeadEnd, iet->iet_AlertLocation, iet->iet_AlertStack,
61 iet->iet_AlertType, (APTR)&iet->iet_AlertData, SysBase);
63 if (alertNum & AT_DeadEnd)
65 /* Um, we have to do something here in order to prevent the
66 computer from continuing... */
67 ColdReboot();
68 ShutdownA(SD_ACTION_COLDREBOOT);
71 Enable();
74 switch (res)
76 case 0:
77 ShutdownA(SD_ACTION_POWEROFF);
78 break;
80 case 2:
81 /* Suspend actually should have already happened by code raising Alert */
82 break;
84 case 3:
85 ColdReboot();
86 /* In case if ColdReboot() doesn't work */
87 ShutdownA(SD_ACTION_COLDREBOOT);
88 break;
92 Disable();
93 /* Mark task as available */
94 IntSysBase->SAT.sat_IsAvailable = TRUE;
95 for (i = 0; i < 2; i++)
96 IntSysBase->SAT.sat_Params[i] = (IPTR)NULL;
97 t = NULL;
98 alertNum = 0;
99 Enable();