mirror of
https://github.com/Atmosphere-NX/Atmosphere.git
synced 2024-12-28 05:06:08 +00:00
fatal: Skeleton tasks, write ThrowFatalImpl.
This commit is contained in:
parent
b9091e9466
commit
21b0f228b6
9 changed files with 164 additions and 7 deletions
|
@ -4,7 +4,7 @@
|
|||
"title_id_range_min": "0x0100000000000034",
|
||||
"title_id_range_max": "0x0100000000000034",
|
||||
"main_thread_stack_size": "0x00010000",
|
||||
"main_thread_priority": 15,
|
||||
"main_thread_priority": 37,
|
||||
"default_cpu_id": 3,
|
||||
"process_category": 0,
|
||||
"is_retail": true,
|
||||
|
|
|
@ -15,8 +15,15 @@
|
|||
*/
|
||||
|
||||
#include <switch.h>
|
||||
#include "fatal_types.hpp"
|
||||
#include "fatal_event_manager.hpp"
|
||||
|
||||
static FatalEventManager g_event_manager;
|
||||
|
||||
FatalEventManager *GetEventManager() {
|
||||
return &g_event_manager;
|
||||
}
|
||||
|
||||
FatalEventManager::FatalEventManager() {
|
||||
/* Just create all the events. */
|
||||
for (size_t i = 0; i < FatalEventManager::NumFatalEvents; i++) {
|
||||
|
@ -31,7 +38,7 @@ Result FatalEventManager::GetEvent(Handle *out) {
|
|||
|
||||
/* Only allow GetEvent to succeed NumFatalEvents times. */
|
||||
if (this->events_gotten >= FatalEventManager::NumFatalEvents) {
|
||||
return 0x8A3;
|
||||
return FatalResult_TooManyEvents;
|
||||
}
|
||||
|
||||
*out = this->events[this->events_gotten++].revent;
|
||||
|
|
|
@ -30,3 +30,5 @@ class FatalEventManager {
|
|||
Result GetEvent(Handle *out);
|
||||
void SignalEvents();
|
||||
};
|
||||
|
||||
FatalEventManager *GetEventManager();
|
|
@ -67,11 +67,17 @@ void __appInit(void) {
|
|||
fatalSimple(rc);
|
||||
}
|
||||
|
||||
rc = pminfoInitialize();
|
||||
if (R_FAILED(rc)) {
|
||||
fatalSimple(rc);
|
||||
}
|
||||
|
||||
CheckAtmosphereVersion(CURRENT_ATMOSPHERE_VERSION);
|
||||
}
|
||||
|
||||
void __appExit(void) {
|
||||
/* Cleanup services. */
|
||||
pminfoExit();
|
||||
setsysExit();
|
||||
smExit();
|
||||
}
|
||||
|
|
|
@ -18,8 +18,6 @@
|
|||
#include "fatal_private.hpp"
|
||||
#include "fatal_event_manager.hpp"
|
||||
|
||||
static FatalEventManager g_EventManager;
|
||||
|
||||
Result PrivateService::GetFatalEvent(Out<CopiedHandle> out_h) {
|
||||
return g_EventManager.GetEvent(out_h.GetHandlePointer());
|
||||
return GetEventManager()->GetEvent(out_h.GetHandlePointer());
|
||||
}
|
||||
|
|
55
stratosphere/fatal/source/fatal_task.cpp
Normal file
55
stratosphere/fatal/source/fatal_task.cpp
Normal file
|
@ -0,0 +1,55 @@
|
|||
/*
|
||||
* Copyright (c) 2018 Atmosphère-NX
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <switch.h>
|
||||
#include "fatal_types.hpp"
|
||||
#include "fatal_task.hpp"
|
||||
|
||||
static constexpr size_t MaxTasks = 8;
|
||||
static HosThread g_task_threads[MaxTasks];
|
||||
static size_t g_num_threads = 0;
|
||||
|
||||
|
||||
static void RunTaskThreadFunc(void *arg) {
|
||||
IFatalTask *task = reinterpret_cast<IFatalTask *>(arg);
|
||||
|
||||
Result rc = task->Run();
|
||||
if (R_FAILED(rc)) {
|
||||
/* TODO: Log task failure, somehow? */
|
||||
}
|
||||
}
|
||||
|
||||
static void RunTask(IFatalTask *task) {
|
||||
if (g_num_threads >= MaxTasks) {
|
||||
std::abort();
|
||||
}
|
||||
|
||||
HosThread *cur_thread = &g_task_threads[g_num_threads++];
|
||||
|
||||
cur_thread->Initialize(&RunTaskThreadFunc, task, 0x4000, 15);
|
||||
cur_thread->Start();
|
||||
}
|
||||
|
||||
void RunFatalTasks(FatalContext *ctx, u64 title_id, bool error_report, Event *erpt_event, Event *battery_event) {
|
||||
/* TODO: RunTask(new ErrorReportTask(ctx, title_id, error_report, erpt_event); */
|
||||
/* TODO: RunTask(new PowerControlTask(ctx, title_id, battery_event); */
|
||||
/* TODO: RunTask(new ShowFatalTask(ctx, title_id, battery_event); */
|
||||
/* TODO: RunTask(new StopSoundTask(); */
|
||||
/* TODO: RunTask(new BacklightControlTask(); */
|
||||
/* TODO: RunTask(new AdjustClockTask(); */
|
||||
/* TODO: RunTask(new PowerButtonTask(erpt_event); */
|
||||
/* TODO: RunTask(new StateTransitionStop(); */
|
||||
}
|
31
stratosphere/fatal/source/fatal_task.hpp
Normal file
31
stratosphere/fatal/source/fatal_task.hpp
Normal file
|
@ -0,0 +1,31 @@
|
|||
/*
|
||||
* Copyright (c) 2018 Atmosphère-NX
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <switch.h>
|
||||
#include <stratosphere.hpp>
|
||||
#include "fatal_types.hpp"
|
||||
|
||||
class IFatalTask {
|
||||
protected:
|
||||
FatalContext *ctx;
|
||||
u64 title_id;
|
||||
public:
|
||||
virtual Result Run() = 0;
|
||||
virtual const char *GetName() const = 0;
|
||||
};
|
||||
|
||||
void RunFatalTasks(FatalContext *ctx, u64 title_id, bool error_report, Event *erpt_event, Event *battery_event);
|
|
@ -19,6 +19,7 @@
|
|||
#include <stratosphere.hpp>
|
||||
|
||||
enum FatalResult : Result {
|
||||
FatalResult_AlreadyThrown = 0x6A3,
|
||||
FatalResult_TooManyEvents = 0x8A3,
|
||||
FatalResult_InRepairWithoutVolHeld = 0xAA3,
|
||||
FatalResult_InRepairWithoutTimeReviserCartridge = 0xCA3,
|
||||
|
@ -91,6 +92,11 @@ struct FatalCpuContext {
|
|||
u32 type;
|
||||
};
|
||||
|
||||
struct FatalContext {
|
||||
u32 error_code;
|
||||
FatalCpuContext cpu_ctx;
|
||||
};
|
||||
|
||||
static_assert(sizeof(Aarch64CpuContext) == 0x248, "Aarch64CpuContext definition!");
|
||||
static_assert(sizeof(Aarch32CpuContext) == 0xE0, "Aarch32CpuContext definition!");
|
||||
static_assert(sizeof(FatalCpuContext) == 0x250, "FatalCpuContext definition!");
|
||||
|
|
|
@ -16,9 +16,61 @@
|
|||
|
||||
#include <switch.h>
|
||||
#include "fatal_user.hpp"
|
||||
#include "fatal_event_manager.hpp"
|
||||
#include "fatal_task.hpp"
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
Result UserService::ThrowFatalImpl(u32 error, u64 pid, FatalType policy, FatalCpuContext *context) {
|
||||
/* TODO */
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue