loader: port guest fault diagnostics and remove host stack traces

Co-authored-by: Ali Almohaya <AliAlmohaya@gmail.com>
This commit is contained in:
nmzik
2026-09-09 13:54:51 +04:00
parent 1af19eabf0
commit c7b0d77970
11 changed files with 41 additions and 145 deletions
+36
View File
@@ -801,6 +801,42 @@ static bool KytyExceptionHandler(const Common::HostException::ExceptionInfo& exc
return true;
}
}
// Report whatever guest context can be read safely before terminating: which guest thread
// faulted, the register file, the faulting code bytes and the top of its stack.
{
char thread_name[64] = "(host thread)";
if (auto self = Libs::LibKernel::PthreadSelfOrNull(); self != nullptr) {
if (Libs::LibKernel::PthreadGetname(self, thread_name) != 0) {
std::snprintf(thread_name, sizeof(thread_name), "(unnamed guest thread)");
}
}
std::printf("--- Guest fault context ---\n");
std::printf("thread: %s\n", thread_name);
std::printf("rax=%016" PRIx64 " rbx=%016" PRIx64 " rcx=%016" PRIx64 " rdx=%016" PRIx64 "\n"
"rsi=%016" PRIx64 " rdi=%016" PRIx64 " rbp=%016" PRIx64 " rsp=%016" PRIx64 "\n"
"r8 =%016" PRIx64 " r9 =%016" PRIx64 " r10=%016" PRIx64 " r11=%016" PRIx64 "\n"
"r12=%016" PRIx64 " r13=%016" PRIx64 " r14=%016" PRIx64 " r15=%016" PRIx64 "\n",
info->rax, info->rbx, info->rcx, info->rdx, info->rsi, info->rdi, info->rbp,
info->rsp, info->r8, info->r9, info->r10, info->r11, info->r12, info->r13,
info->r14, info->r15);
if (IsReadableRange(info->exception_address - 48, 96)) {
const auto* code = reinterpret_cast<const uint8_t*>(info->exception_address - 48);
std::printf("code (pc-48 .. pc+48, fault at byte 48):");
for (int i = 0; i < 96; i++) {
std::printf("%s%02x", (i % 16 == 0) ? "\n " : " ", code[i]);
}
std::printf("\n");
}
if (IsReadableRange(info->rsp, 32 * sizeof(uint64_t))) {
const auto* stack = reinterpret_cast<const uint64_t*>(info->rsp);
std::printf("stack:");
for (int i = 0; i < 32; i++) {
std::printf("%s %016" PRIx64, (i % 4 == 0) ? "\n " : "", stack[i]);
}
std::printf("\n");
}
std::fflush(stdout);
}
EXIT("Unhandled host exception: type=%u code=%u pc=0x%016" PRIx64
" access=%u address=0x%016" PRIx64 "\n",
static_cast<unsigned>(info->type), info->native_code, info->exception_address,