yuzu-emu
/
yuzu
Archived
1
0
Fork 0

Deglobalize System: Fatal

This commit is contained in:
David Marcec 2019-09-21 18:43:03 +10:00
parent c33faabb27
commit a40e5b2def
6 changed files with 29 additions and 20 deletions

View File

@ -20,8 +20,8 @@
namespace Service::Fatal { namespace Service::Fatal {
Module::Interface::Interface(std::shared_ptr<Module> module, const char* name) Module::Interface::Interface(std::shared_ptr<Module> module, Core::System& system, const char* name)
: ServiceFramework(name), module(std::move(module)) {} : ServiceFramework(name), module(std::move(module)), system(system) {}
Module::Interface::~Interface() = default; Module::Interface::~Interface() = default;
@ -64,7 +64,8 @@ enum class FatalType : u32 {
ErrorScreen = 2, 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(); const auto title_id = Core::CurrentProcess()->GetTitleID();
std::string crash_report = fmt::format( std::string crash_report = fmt::format(
"Yuzu {}-{} crash report\n" "Yuzu {}-{} crash report\n"
@ -101,18 +102,19 @@ static void GenerateErrorReport(ResultCode error_code, const FatalInfo& info) {
LOG_ERROR(Service_Fatal, "{}", crash_report); 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, 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.pstate, info.afsr0, info.afsr1, info.esr, info.far, info.registers, info.backtrace,
info.backtrace_size, info.ArchAsString(), info.unk10); 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}", LOG_ERROR(Service_Fatal, "Threw fatal error type {} with error code 0x{:X}",
static_cast<u32>(fatal_type), error_code.raw); static_cast<u32>(fatal_type), error_code.raw);
switch (fatal_type) { switch (fatal_type) {
case FatalType::ErrorReportAndScreen: case FatalType::ErrorReportAndScreen:
GenerateErrorReport(error_code, info); GenerateErrorReport(system, error_code, info);
[[fallthrough]]; [[fallthrough]];
case FatalType::ErrorScreen: case FatalType::ErrorScreen:
// Since we have no fatal:u error screen. We should just kill execution instead // 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; break;
// Should not throw a fatal screen but should generate an error report // Should not throw a fatal screen but should generate an error report
case FatalType::ErrorReport: case FatalType::ErrorReport:
GenerateErrorReport(error_code, info); GenerateErrorReport(system, error_code, info);
break; break;
} }
} }
@ -130,7 +132,7 @@ void Module::Interface::ThrowFatal(Kernel::HLERequestContext& ctx) {
IPC::RequestParser rp{ctx}; IPC::RequestParser rp{ctx};
const auto error_code = rp.Pop<ResultCode>(); const auto error_code = rp.Pop<ResultCode>();
ThrowFatalError(error_code, FatalType::ErrorScreen, {}); ThrowFatalError(system, error_code, FatalType::ErrorScreen, {});
IPC::ResponseBuilder rb{ctx, 2}; IPC::ResponseBuilder rb{ctx, 2};
rb.Push(RESULT_SUCCESS); rb.Push(RESULT_SUCCESS);
} }
@ -141,7 +143,8 @@ void Module::Interface::ThrowFatalWithPolicy(Kernel::HLERequestContext& ctx) {
const auto error_code = rp.Pop<ResultCode>(); const auto error_code = rp.Pop<ResultCode>();
const auto fatal_type = rp.PopEnum<FatalType>(); const auto fatal_type = rp.PopEnum<FatalType>();
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}; IPC::ResponseBuilder rb{ctx, 2};
rb.Push(RESULT_SUCCESS); 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!"); ASSERT_MSG(fatal_info.size() == sizeof(FatalInfo), "Invalid fatal info buffer size!");
std::memcpy(&info, fatal_info.data(), sizeof(FatalInfo)); 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}; IPC::ResponseBuilder rb{ctx, 2};
rb.Push(RESULT_SUCCESS); rb.Push(RESULT_SUCCESS);
} }
void InstallInterfaces(SM::ServiceManager& service_manager) { void InstallInterfaces(SM::ServiceManager& service_manager, Core::System& system) {
auto module = std::make_shared<Module>(); auto module = std::make_shared<Module>();
std::make_shared<Fatal_P>(module)->InstallAsService(service_manager); std::make_shared<Fatal_P>(module, system)->InstallAsService(service_manager);
std::make_shared<Fatal_U>(module)->InstallAsService(service_manager); std::make_shared<Fatal_U>(module, system)->InstallAsService(service_manager);
} }
} // namespace Service::Fatal } // namespace Service::Fatal

View File

@ -6,13 +6,17 @@
#include "core/hle/service/service.h" #include "core/hle/service/service.h"
namespace Core {
class System;
}
namespace Service::Fatal { namespace Service::Fatal {
class Module final { class Module final {
public: public:
class Interface : public ServiceFramework<Interface> { class Interface : public ServiceFramework<Interface> {
public: public:
explicit Interface(std::shared_ptr<Module> module, const char* name); explicit Interface(std::shared_ptr<Module> module, Core::System& system, const char* name);
~Interface() override; ~Interface() override;
void ThrowFatal(Kernel::HLERequestContext& ctx); void ThrowFatal(Kernel::HLERequestContext& ctx);
@ -21,9 +25,10 @@ public:
protected: protected:
std::shared_ptr<Module> module; std::shared_ptr<Module> module;
Core::System& system;
}; };
}; };
void InstallInterfaces(SM::ServiceManager& service_manager); void InstallInterfaces(SM::ServiceManager& service_manager, Core::System& system);
} // namespace Service::Fatal } // namespace Service::Fatal

View File

@ -6,8 +6,8 @@
namespace Service::Fatal { namespace Service::Fatal {
Fatal_P::Fatal_P(std::shared_ptr<Module> module) Fatal_P::Fatal_P(std::shared_ptr<Module> module, Core::System& system)
: Module::Interface(std::move(module), "fatal:p") {} : Module::Interface(std::move(module), system, "fatal:p") {}
Fatal_P::~Fatal_P() = default; Fatal_P::~Fatal_P() = default;

View File

@ -10,7 +10,7 @@ namespace Service::Fatal {
class Fatal_P final : public Module::Interface { class Fatal_P final : public Module::Interface {
public: public:
explicit Fatal_P(std::shared_ptr<Module> module); explicit Fatal_P(std::shared_ptr<Module> module, Core::System& system);
~Fatal_P() override; ~Fatal_P() override;
}; };

View File

@ -6,7 +6,8 @@
namespace Service::Fatal { namespace Service::Fatal {
Fatal_U::Fatal_U(std::shared_ptr<Module> module) : Module::Interface(std::move(module), "fatal:u") { Fatal_U::Fatal_U(std::shared_ptr<Module> module, Core::System& system)
: Module::Interface(std::move(module), system, "fatal:u") {
static const FunctionInfo functions[] = { static const FunctionInfo functions[] = {
{0, &Fatal_U::ThrowFatal, "ThrowFatal"}, {0, &Fatal_U::ThrowFatal, "ThrowFatal"},
{1, &Fatal_U::ThrowFatalWithPolicy, "ThrowFatalWithPolicy"}, {1, &Fatal_U::ThrowFatalWithPolicy, "ThrowFatalWithPolicy"},

View File

@ -10,7 +10,7 @@ namespace Service::Fatal {
class Fatal_U final : public Module::Interface { class Fatal_U final : public Module::Interface {
public: public:
explicit Fatal_U(std::shared_ptr<Module> module); explicit Fatal_U(std::shared_ptr<Module> module, Core::System& system);
~Fatal_U() override; ~Fatal_U() override;
}; };