From 1228cd6903e5d5f5572fd431f18b12d0ada145f6 Mon Sep 17 00:00:00 2001 From: Michael Scire Date: Sat, 10 Nov 2018 02:21:29 -0800 Subject: [PATCH] fatal: misc cleanup, verified to reboot on hardware --- stratosphere/fatal/fatal.json | 5 +++-- stratosphere/fatal/source/fatal_event_manager.hpp | 2 +- stratosphere/fatal/source/fatal_task.cpp | 3 +++ .../fatal/source/fatal_task_error_report.cpp | 2 ++ stratosphere/fatal/source/fatal_user.cpp | 14 +++++++------- stratosphere/fatal/source/fatal_user.hpp | 2 +- 6 files changed, 17 insertions(+), 11 deletions(-) diff --git a/stratosphere/fatal/fatal.json b/stratosphere/fatal/fatal.json index 9dc17d9a9..380b2b85f 100644 --- a/stratosphere/fatal/fatal.json +++ b/stratosphere/fatal/fatal.json @@ -14,7 +14,7 @@ "filesystem_access": { "permissions": "0x0000000000100000" }, - "service_access": ["bpc", "erpt:c", "fsp-srv", "gpio", "i2c", "lbl", "lm", "nvdrv:s", "pcv", "pl:u", "pm:info", "psm", "set", "set:sys", "spsm", "vi:m", "vi:s"], + "service_access": ["bpc", "bpc:c", "erpt:c", "fsp-srv", "gpio", "i2c", "lbl", "lm", "nvdrv:s", "pcv", "pl:u", "pm:info", "psm", "set", "set:sys", "spsm", "vi:m", "vi:s"], "service_host": ["fatal:p", "fatal:u"], "kernel_capabilities": [{ "type": "kernel_flags", @@ -75,7 +75,8 @@ "svcReplyAndReceiveLight": "0x42", "svcReplyAndReceive": "0x43", "svcReplyAndReceiveWithUserBuffer": "0x44", - "svcCreateEvent": "0x45" + "svcCreateEvent": "0x45", + "svcReadWriteRegister": "0x4E" } }, { "type": "min_kernel_version", diff --git a/stratosphere/fatal/source/fatal_event_manager.hpp b/stratosphere/fatal/source/fatal_event_manager.hpp index e96ab0f63..6b0bd5f69 100644 --- a/stratosphere/fatal/source/fatal_event_manager.hpp +++ b/stratosphere/fatal/source/fatal_event_manager.hpp @@ -24,7 +24,7 @@ class FatalEventManager { HosMutex lock; size_t events_gotten = 0; - Event events[3]; + Event events[NumFatalEvents]; public: FatalEventManager(); Result GetEvent(Handle *out); diff --git a/stratosphere/fatal/source/fatal_task.cpp b/stratosphere/fatal/source/fatal_task.cpp index 381d3c176..407b78e8c 100644 --- a/stratosphere/fatal/source/fatal_task.cpp +++ b/stratosphere/fatal/source/fatal_task.cpp @@ -34,6 +34,9 @@ static void RunTaskThreadFunc(void *arg) { if (R_FAILED(rc)) { /* TODO: Log task failure, somehow? */ } + + /* Finish. */ + svcExitThread(); } static void RunTask(IFatalTask *task) { diff --git a/stratosphere/fatal/source/fatal_task_error_report.cpp b/stratosphere/fatal/source/fatal_task_error_report.cpp index 72decd371..111c4ce38 100644 --- a/stratosphere/fatal/source/fatal_task_error_report.cpp +++ b/stratosphere/fatal/source/fatal_task_error_report.cpp @@ -25,4 +25,6 @@ Result ErrorReportTask::Run() { /* Signal we're done with our job. */ eventFire(this->erpt_event); + + return 0; } \ No newline at end of file diff --git a/stratosphere/fatal/source/fatal_user.cpp b/stratosphere/fatal/source/fatal_user.cpp index f683de4cc..b21aefc29 100644 --- a/stratosphere/fatal/source/fatal_user.cpp +++ b/stratosphere/fatal/source/fatal_user.cpp @@ -58,7 +58,7 @@ Result UserService::ThrowFatalImpl(u32 error, u64 pid, FatalType policy, FatalCp /* Create events. */ Event erpt_event; Event battery_event; - if (R_FAILED(eventCreate(&erpt_event, true)) || R_FAILED(eventCreate(&battery_event, true))) { + if (R_FAILED(eventCreate(&erpt_event, false)) || R_FAILED(eventCreate(&battery_event, false))) { std::abort(); } @@ -85,11 +85,11 @@ Result UserService::ThrowFatalWithPolicy(u32 error, PidDescriptor pid_desc, Fata return ThrowFatalImpl(error, pid_desc.pid, policy, &ctx); } -Result UserService::ThrowFatalWithCpuContext(u32 error, PidDescriptor pid_desc, FatalType policy, InBuffer _ctx) { - /* Require exactly one context passed in. */ - if (_ctx.num_elements != 1) { - return 0xF601; +Result UserService::ThrowFatalWithCpuContext(u32 error, PidDescriptor pid_desc, FatalType policy, InBuffer _ctx) { + if (_ctx.num_elements < sizeof(FatalCpuContext)) { + FatalCpuContext ctx = {0}; + return ThrowFatalImpl(error, pid_desc.pid, policy, &ctx); + } else { + return ThrowFatalImpl(error, pid_desc.pid, policy, reinterpret_cast(_ctx.buffer)); } - - return ThrowFatalImpl(error, pid_desc.pid, policy, _ctx.buffer); } \ No newline at end of file diff --git a/stratosphere/fatal/source/fatal_user.hpp b/stratosphere/fatal/source/fatal_user.hpp index 48e4f9591..ab46a4a9e 100644 --- a/stratosphere/fatal/source/fatal_user.hpp +++ b/stratosphere/fatal/source/fatal_user.hpp @@ -33,7 +33,7 @@ class UserService final : public IServiceObject { /* Actual commands. */ Result ThrowFatal(u32 error, PidDescriptor pid_desc); Result ThrowFatalWithPolicy(u32 error, PidDescriptor pid_desc, FatalType policy); - Result ThrowFatalWithCpuContext(u32 error, PidDescriptor pid_desc, FatalType policy, InBuffer _ctx); + Result ThrowFatalWithCpuContext(u32 error, PidDescriptor pid_desc, FatalType policy, InBuffer _ctx); public: DEFINE_SERVICE_DISPATCH_TABLE { MakeServiceCommandMeta(),