fatal: Skeleton tasks, write ThrowFatalImpl.

This commit is contained in:
Michael Scire 2018-11-10 00:54:12 -08:00
parent b9091e9466
commit 21b0f228b6
9 changed files with 164 additions and 7 deletions

View file

@ -16,9 +16,61 @@
#include <switch.h>
#include "fatal_user.hpp"
#include "fatal_event_manager.hpp"
#include "fatal_task.hpp"
Result UserService::ThrowFatalImpl(u32 error, u64 pid, FatalType policy, FatalCpuContext *context) {
/* TODO */
static bool g_thrown = false;
static Result SetThrown() {
/* This should be fine, since fatal only has a single IPC thread. */
if (g_thrown) {
return FatalResult_AlreadyThrown;
}
g_thrown = true;
return 0;
}
Result UserService::ThrowFatalImpl(u32 error, u64 pid, FatalType policy, FatalCpuContext *cpu_ctx) {
Result rc = 0;
FatalContext ctx;
ctx.error_code = error;
ctx.cpu_ctx = *cpu_ctx;
/* Get title id. On failure, it'll be zero. */
u64 title_id = 0;
pminfoGetTitleId(&title_id, pid);
switch (policy) {
case FatalType_ErrorReport:
/* TODO: Don't write an error report. */
case FatalType_ErrorReportAndErrorScreen:
case FatalType_ErrorScreen:
{
/* Ensure we only throw once. */
if (R_FAILED((rc = SetThrown()))) {
return rc;
}
/* Signal that fatal is about to happen. */
GetEventManager()->SignalEvents();
/* Create events. */
Event erpt_event;
Event battery_event;
if (R_FAILED(eventCreate(&erpt_event, true)) || R_FAILED(eventCreate(&battery_event, true))) {
std::abort();
}
/* Run tasks. */
RunFatalTasks(&ctx, title_id, policy == FatalType_ErrorReportAndErrorScreen, &erpt_event, &battery_event);
}
break;
default:
/* N aborts here. Should we just return an error code? */
std::abort();
}
return 0;
}