From a79d3aa8aa5b60029e55169854b94e4e985e6024 Mon Sep 17 00:00:00 2001 From: Ash Date: Wed, 22 Nov 2017 10:39:04 +1100 Subject: [PATCH 1/3] [WiiU] Exception handler: fix coreinit handles, add opcode to DSIs Coreinit seems to get special handles, so adding a special case should make its relative addresses actually become helpful again. Let's just hope __PPCExit stays at 0x180! Also added the violating opcode to the DSI message; may have to move it in case it pushes stuff off the end of the screen. Untested at time of commit. Hopefully this should make debugging #5357 a bit easier... --- wiiu/system/exception_handler.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/wiiu/system/exception_handler.c b/wiiu/system/exception_handler.c index 7ec7dc3f90..1169c078a2 100644 --- a/wiiu/system/exception_handler.c +++ b/wiiu/system/exception_handler.c @@ -90,9 +90,8 @@ void __attribute__((__noreturn__)) exception_cb(OSContext* ctx, OSExceptionType /* First up, the pretty header that tells you wtf just happened */ if (type == OS_EXCEPTION_TYPE_DSI) { - /* Exception type and offending instruction location - Also initializes exception_msgbuf, use buf_add from now on */ - buf_add("DSI: Instr at %08" PRIX32, ctx->srr0); + /* Exception type and offending instruction location + opcode */ + buf_add("DSI: Instr at %08" PRIX32 " (%08 " PRIX32 ")", ctx->srr0, *(unsigned int*)(ctx->srr0)); /* Was this a read or a write? */ if (ctx->dsisr & DSISR_WRITE_ATTEMPTED) { buf_add(" bad write to"); @@ -216,6 +215,12 @@ void exception_print_symbol(uint32_t addr) { /* Try for a base address */ void* libAddr; OSDynLoad_Acquire(symbolName, &libAddr); + /* Special case for coreinit; which has broken handles */ + if (strcmp(symbolName, "coreinit.rpl")) { + void* PPCExit_addr; + OSDynLoad_FindExport(libAddr, 0, "__PPCExit", &PPCExit_addr); + libAddr = PPCExit_addr - 0x180; + } *seperator = '|'; /* We got one! */ if (libAddr) { From 469662345ff275f892986283e66fdfad59c05311 Mon Sep 17 00:00:00 2001 From: Ash Date: Fri, 1 Dec 2017 10:56:54 +1100 Subject: [PATCH 2/3] [WiiU] Exception handler: remove opcodes; fix strcmp misuse Thanks for @gblues for finding the strcmp bug. I've removed the opcode display since it's a bit unsafe - if the exception handler causes a DSI; Cafe OS will take over and freeze up the console. This is obviously not a good thing. There are possible situations where memory is executable and not readable; so this is just about covering all bases until a better solution can be implemented. Maybe we can experiment a bit more once this handler isn't being used so often ;) --- wiiu/system/exception_handler.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/wiiu/system/exception_handler.c b/wiiu/system/exception_handler.c index 1169c078a2..7e01e648f6 100644 --- a/wiiu/system/exception_handler.c +++ b/wiiu/system/exception_handler.c @@ -91,7 +91,7 @@ void __attribute__((__noreturn__)) exception_cb(OSContext* ctx, OSExceptionType /* First up, the pretty header that tells you wtf just happened */ if (type == OS_EXCEPTION_TYPE_DSI) { /* Exception type and offending instruction location + opcode */ - buf_add("DSI: Instr at %08" PRIX32 " (%08 " PRIX32 ")", ctx->srr0, *(unsigned int*)(ctx->srr0)); + buf_add("DSI: Instr at %08" PRIX32, ctx->srr0); /* Was this a read or a write? */ if (ctx->dsisr & DSISR_WRITE_ATTEMPTED) { buf_add(" bad write to"); @@ -216,7 +216,7 @@ void exception_print_symbol(uint32_t addr) { void* libAddr; OSDynLoad_Acquire(symbolName, &libAddr); /* Special case for coreinit; which has broken handles */ - if (strcmp(symbolName, "coreinit.rpl")) { + if (!strcmp(symbolName, "coreinit.rpl")) { void* PPCExit_addr; OSDynLoad_FindExport(libAddr, 0, "__PPCExit", &PPCExit_addr); libAddr = PPCExit_addr - 0x180; From 52fb8276d7609fe30f640687c3ce218bf75cc9fa Mon Sep 17 00:00:00 2001 From: Ash Date: Fri, 1 Dec 2017 11:03:09 +1100 Subject: [PATCH 3/3] [WiiU] Exception handler: minor comment tweak --- wiiu/system/exception_handler.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wiiu/system/exception_handler.c b/wiiu/system/exception_handler.c index 7e01e648f6..b867a77a2e 100644 --- a/wiiu/system/exception_handler.c +++ b/wiiu/system/exception_handler.c @@ -90,7 +90,7 @@ void __attribute__((__noreturn__)) exception_cb(OSContext* ctx, OSExceptionType /* First up, the pretty header that tells you wtf just happened */ if (type == OS_EXCEPTION_TYPE_DSI) { - /* Exception type and offending instruction location + opcode */ + /* Exception type and offending instruction location */ buf_add("DSI: Instr at %08" PRIX32, ctx->srr0); /* Was this a read or a write? */ if (ctx->dsisr & DSISR_WRITE_ATTEMPTED) {