From a40e5b2def2502f3bc8c159959b4ac1e262b4188 Mon Sep 17 00:00:00 2001 From: David Marcec Date: Sat, 21 Sep 2019 18:43:03 +1000 Subject: [PATCH] Deglobalize System: Fatal --- src/core/hle/service/fatal/fatal.cpp | 29 ++++++++++++++------------ src/core/hle/service/fatal/fatal.h | 9 ++++++-- src/core/hle/service/fatal/fatal_p.cpp | 4 ++-- src/core/hle/service/fatal/fatal_p.h | 2 +- src/core/hle/service/fatal/fatal_u.cpp | 3 ++- src/core/hle/service/fatal/fatal_u.h | 2 +- 6 files changed, 29 insertions(+), 20 deletions(-) diff --git a/src/core/hle/service/fatal/fatal.cpp b/src/core/hle/service/fatal/fatal.cpp index 01fa06ad3c..b2ebf62401 100644 --- a/src/core/hle/service/fatal/fatal.cpp +++ b/src/core/hle/service/fatal/fatal.cpp @@ -20,8 +20,8 @@ namespace Service::Fatal { -Module::Interface::Interface(std::shared_ptr module, const char* name) - : ServiceFramework(name), module(std::move(module)) {} +Module::Interface::Interface(std::shared_ptr module, Core::System& system, const char* name) + : ServiceFramework(name), module(std::move(module)), system(system) {} Module::Interface::~Interface() = default; @@ -64,7 +64,8 @@ enum class FatalType : u32 { ErrorScreen = 2, }; -static void GenerateErrorReport(ResultCode error_code, const FatalInfo& info) { +static void GenerateErrorReport(Core::System& system, ResultCode error_code, + const FatalInfo& info) { const auto title_id = Core::CurrentProcess()->GetTitleID(); std::string crash_report = fmt::format( "Yuzu {}-{} crash report\n" @@ -101,18 +102,19 @@ static void GenerateErrorReport(ResultCode error_code, const FatalInfo& info) { LOG_ERROR(Service_Fatal, "{}", crash_report); - Core::System::GetInstance().GetReporter().SaveCrashReport( + system.GetReporter().SaveCrashReport( title_id, error_code, info.set_flags, info.program_entry_point, info.sp, info.pc, info.pstate, info.afsr0, info.afsr1, info.esr, info.far, info.registers, info.backtrace, info.backtrace_size, info.ArchAsString(), info.unk10); } -static void ThrowFatalError(ResultCode error_code, FatalType fatal_type, const FatalInfo& info) { +static void ThrowFatalError(Core::System& system, ResultCode error_code, FatalType fatal_type, + const FatalInfo& info) { LOG_ERROR(Service_Fatal, "Threw fatal error type {} with error code 0x{:X}", static_cast(fatal_type), error_code.raw); switch (fatal_type) { case FatalType::ErrorReportAndScreen: - GenerateErrorReport(error_code, info); + GenerateErrorReport(system, error_code, info); [[fallthrough]]; case FatalType::ErrorScreen: // Since we have no fatal:u error screen. We should just kill execution instead @@ -120,7 +122,7 @@ static void ThrowFatalError(ResultCode error_code, FatalType fatal_type, const F break; // Should not throw a fatal screen but should generate an error report case FatalType::ErrorReport: - GenerateErrorReport(error_code, info); + GenerateErrorReport(system, error_code, info); break; } } @@ -130,7 +132,7 @@ void Module::Interface::ThrowFatal(Kernel::HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto error_code = rp.Pop(); - ThrowFatalError(error_code, FatalType::ErrorScreen, {}); + ThrowFatalError(system, error_code, FatalType::ErrorScreen, {}); IPC::ResponseBuilder rb{ctx, 2}; rb.Push(RESULT_SUCCESS); } @@ -141,7 +143,8 @@ void Module::Interface::ThrowFatalWithPolicy(Kernel::HLERequestContext& ctx) { const auto error_code = rp.Pop(); const auto fatal_type = rp.PopEnum(); - ThrowFatalError(error_code, fatal_type, {}); // No info is passed with ThrowFatalWithPolicy + ThrowFatalError(system, error_code, fatal_type, + {}); // No info is passed with ThrowFatalWithPolicy IPC::ResponseBuilder rb{ctx, 2}; rb.Push(RESULT_SUCCESS); } @@ -157,15 +160,15 @@ void Module::Interface::ThrowFatalWithCpuContext(Kernel::HLERequestContext& ctx) ASSERT_MSG(fatal_info.size() == sizeof(FatalInfo), "Invalid fatal info buffer size!"); std::memcpy(&info, fatal_info.data(), sizeof(FatalInfo)); - ThrowFatalError(error_code, fatal_type, info); + ThrowFatalError(system, error_code, fatal_type, info); IPC::ResponseBuilder rb{ctx, 2}; rb.Push(RESULT_SUCCESS); } -void InstallInterfaces(SM::ServiceManager& service_manager) { +void InstallInterfaces(SM::ServiceManager& service_manager, Core::System& system) { auto module = std::make_shared(); - std::make_shared(module)->InstallAsService(service_manager); - std::make_shared(module)->InstallAsService(service_manager); + std::make_shared(module, system)->InstallAsService(service_manager); + std::make_shared(module, system)->InstallAsService(service_manager); } } // namespace Service::Fatal diff --git a/src/core/hle/service/fatal/fatal.h b/src/core/hle/service/fatal/fatal.h index 09371ff7fd..bd9339dfca 100644 --- a/src/core/hle/service/fatal/fatal.h +++ b/src/core/hle/service/fatal/fatal.h @@ -6,13 +6,17 @@ #include "core/hle/service/service.h" +namespace Core { +class System; +} + namespace Service::Fatal { class Module final { public: class Interface : public ServiceFramework { public: - explicit Interface(std::shared_ptr module, const char* name); + explicit Interface(std::shared_ptr module, Core::System& system, const char* name); ~Interface() override; void ThrowFatal(Kernel::HLERequestContext& ctx); @@ -21,9 +25,10 @@ public: protected: std::shared_ptr module; + Core::System& system; }; }; -void InstallInterfaces(SM::ServiceManager& service_manager); +void InstallInterfaces(SM::ServiceManager& service_manager, Core::System& system); } // namespace Service::Fatal diff --git a/src/core/hle/service/fatal/fatal_p.cpp b/src/core/hle/service/fatal/fatal_p.cpp index 9e5f872ff5..066ccf6b01 100644 --- a/src/core/hle/service/fatal/fatal_p.cpp +++ b/src/core/hle/service/fatal/fatal_p.cpp @@ -6,8 +6,8 @@ namespace Service::Fatal { -Fatal_P::Fatal_P(std::shared_ptr module) - : Module::Interface(std::move(module), "fatal:p") {} +Fatal_P::Fatal_P(std::shared_ptr module, Core::System& system) + : Module::Interface(std::move(module), system, "fatal:p") {} Fatal_P::~Fatal_P() = default; diff --git a/src/core/hle/service/fatal/fatal_p.h b/src/core/hle/service/fatal/fatal_p.h index 6e9c5979f9..c6d953cb55 100644 --- a/src/core/hle/service/fatal/fatal_p.h +++ b/src/core/hle/service/fatal/fatal_p.h @@ -10,7 +10,7 @@ namespace Service::Fatal { class Fatal_P final : public Module::Interface { public: - explicit Fatal_P(std::shared_ptr module); + explicit Fatal_P(std::shared_ptr module, Core::System& system); ~Fatal_P() override; }; diff --git a/src/core/hle/service/fatal/fatal_u.cpp b/src/core/hle/service/fatal/fatal_u.cpp index 1572a20517..8d72ed4859 100644 --- a/src/core/hle/service/fatal/fatal_u.cpp +++ b/src/core/hle/service/fatal/fatal_u.cpp @@ -6,7 +6,8 @@ namespace Service::Fatal { -Fatal_U::Fatal_U(std::shared_ptr module) : Module::Interface(std::move(module), "fatal:u") { +Fatal_U::Fatal_U(std::shared_ptr module, Core::System& system) + : Module::Interface(std::move(module), system, "fatal:u") { static const FunctionInfo functions[] = { {0, &Fatal_U::ThrowFatal, "ThrowFatal"}, {1, &Fatal_U::ThrowFatalWithPolicy, "ThrowFatalWithPolicy"}, diff --git a/src/core/hle/service/fatal/fatal_u.h b/src/core/hle/service/fatal/fatal_u.h index 72cb6d0764..34c5c7f958 100644 --- a/src/core/hle/service/fatal/fatal_u.h +++ b/src/core/hle/service/fatal/fatal_u.h @@ -10,7 +10,7 @@ namespace Service::Fatal { class Fatal_U final : public Module::Interface { public: - explicit Fatal_U(std::shared_ptr module); + explicit Fatal_U(std::shared_ptr module, Core::System& system); ~Fatal_U() override; };