Skip to content

Commit

Permalink
flush logger thread on cpu exception (skyline-dev#43)
Browse files Browse the repository at this point in the history
  • Loading branch information
blu-dev committed Sep 26, 2021
1 parent e831ae3 commit 57708a9
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions source/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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{[]() {
Expand Down Expand Up @@ -85,6 +87,8 @@ void skyline_main() {
nn::os::SetUserExceptionHandler(exception_handler, exception_handler_stack, sizeof(exception_handler_stack),
&exception_info);

A64HookFunction(reinterpret_cast<void*>(nn::os::SetUserExceptionHandler), reinterpret_cast<void*>(stub), nullptr);

// hook to prevent the game from double mounting romfs
A64HookFunction(reinterpret_cast<void*>(nn::fs::MountRom), reinterpret_cast<void*>(handleNnFsMountRom),
(void**)&nnFsMountRomImpl);
Expand Down Expand Up @@ -144,4 +148,4 @@ extern "C" void skyline_init() {
virtmemSetup(); // needed for libnx JIT

skyline_main();
}
}

0 comments on commit 57708a9

Please sign in to comment.