From 57708a93a4c8bb20feafe770e13f8b8b556248b1 Mon Sep 17 00:00:00 2001 From: blu-dev Date: Sun, 26 Sep 2021 16:50:15 -0700 Subject: [PATCH] flush logger thread on cpu exception (#43) --- source/main.cpp | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/source/main.cpp b/source/main.cpp index 1b02601..cdd9528 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -10,15 +10,17 @@ nn::os::UserExceptionInfo exception_info; const char* RomMountName = "rom"; void exception_handler(nn::os::UserExceptionInfo* info) { - skyline::logger::s_Instance->LogFormat("Exception occurred!\n"); + skyline::logger::s_Instance->LogFormat("Exception occurred!"); - skyline::logger::s_Instance->LogFormat("Error description: %x\n", info->ErrorDescription); + skyline::logger::s_Instance->LogFormat("Error description: %x", info->ErrorDescription); for (int i = 0; i < 29; i++) - skyline::logger::s_Instance->LogFormat("X[%02i]: %" PRIx64 "\n", i, info->CpuRegisters[i].x); - skyline::logger::s_Instance->LogFormat("FP: %" PRIx64 "\n", info->FP.x); - skyline::logger::s_Instance->LogFormat("LR: %" PRIx64 "\n", info->LR.x); - skyline::logger::s_Instance->LogFormat("SP: %" PRIx64 "\n", info->SP.x); - skyline::logger::s_Instance->LogFormat("PC: %" PRIx64 "\n", info->PC.x); + skyline::logger::s_Instance->LogFormat("X[%02i]: %" PRIx64, i, info->CpuRegisters[i].x); + skyline::logger::s_Instance->LogFormat("FP: %" PRIx64, info->FP.x); + skyline::logger::s_Instance->LogFormat("LR: %" PRIx64, info->LR.x); + skyline::logger::s_Instance->LogFormat("SP: %" PRIx64, info->SP.x); + skyline::logger::s_Instance->LogFormat("PC: %" PRIx64, info->PC.x); + skyline::logger::s_Instance->Flush(); + asm("svc 0x26"); } static skyline::utils::Task* after_romfs_task = new skyline::utils::Task{[]() { @@ -85,6 +87,8 @@ void skyline_main() { nn::os::SetUserExceptionHandler(exception_handler, exception_handler_stack, sizeof(exception_handler_stack), &exception_info); + A64HookFunction(reinterpret_cast(nn::os::SetUserExceptionHandler), reinterpret_cast(stub), nullptr); + // hook to prevent the game from double mounting romfs A64HookFunction(reinterpret_cast(nn::fs::MountRom), reinterpret_cast(handleNnFsMountRom), (void**)&nnFsMountRomImpl); @@ -144,4 +148,4 @@ extern "C" void skyline_init() { virtmemSetup(); // needed for libnx JIT skyline_main(); -} +} \ No newline at end of file