Fix crash when exiting NFW games takes too long

This commit is contained in:
Maschell 2022-10-07 12:44:59 +02:00
parent abfdc45068
commit 032bdf5b11
2 changed files with 23 additions and 1 deletions

View File

@ -30,7 +30,7 @@ void ZombiUFix() {
* ZombiU doesn't exit properly. It just calls exit(0) after receiving the
* request to exit. If exiting takes too long, other threads will run again
* and crash for some reason. The (hacky) solution is to set the priority
* of (some) ZombiU threads to something very high.
* of (some) ZombiU threads to something very high (=> low priority).
*/
if (OSGetTitleID() == 0x000500001010EF00 || // ZombiU EUR
OSGetTitleID() == 0x000500001011A700 || // ZombiU EUR

View File

@ -4,9 +4,31 @@
#include "logger.h"
#include <coreinit/dynload.h>
#include <coreinit/filesystem_fsa.h>
#include <coreinit/interrupts.h>
#include <coreinit/scheduler.h>
#include <string_view>
void NWF_Fix() {
// Some games using the NWF (like Dot Arcade) keep a thread called "PlatformInputAppStateListenerThread" running,
// which will cause a DSI exception if the title is not closing fast enough.
auto *curThread = OSGetCurrentThread();
__OSLockScheduler(curThread);
int state = OSDisableInterrupts();
OSThread *t = *((OSThread **) 0x100567F8);
while (t) {
if (std::string_view(t->name) == "PlatformInputAppStateListenerThread") {
t->priority = 0x80;
OSReport("Set priority to %d for thread %08X (%s) to prevent it from running/crashing\n", t->priority, t, t->name);
}
t = t->activeLink.next;
}
OSRestoreInterrupts(state);
__OSUnlockScheduler(curThread);
}
DECL_FUNCTION(void, __PPCExit, uint32_t u1) {
NWF_Fix();
CallHook(WUMS_HOOK_APPLICATION_ENDS);
CallHook(WUMS_HOOK_FINI_WUT_SOCKETS);
CallHook(WUMS_HOOK_FINI_WUT_DEVOPTAB);