diff --git a/sysmodules/rosalina/include/menu.h b/sysmodules/rosalina/include/menu.h index 760d3b1..5dfc9e7 100644 --- a/sysmodules/rosalina/include/menu.h +++ b/sysmodules/rosalina/include/menu.h @@ -60,8 +60,9 @@ typedef struct Menu { MenuItem items[0x40]; } Menu; -extern bool terminationRequest; -extern Handle terminationRequestEvent; +extern bool menuShouldExit; +extern bool preTerminationRequested; +extern Handle preTerminationEvent; extern u32 menuCombo; diff --git a/sysmodules/rosalina/source/errdisp.c b/sysmodules/rosalina/source/errdisp.c index 5201647..ca20680 100644 --- a/sysmodules/rosalina/source/errdisp.c +++ b/sysmodules/rosalina/source/errdisp.c @@ -32,7 +32,7 @@ #include "fmt.h" #include "ifile.h" -extern Handle terminationRequestEvent; +extern Handle preTerminationEvent; static inline void assertSuccess(Result res) { @@ -254,7 +254,7 @@ void ERRF_HandleCommands(void) { ERRF_GetErrInfo(&info, (cmdbuf + 1), sizeof(ERRF_FatalErrInfo)); ERRF_SaveErrorToFile(&info); - if(info.type != ERRF_ERRTYPE_LOGGED || info.procId == 0) + if(!menuShouldExit && (info.type != ERRF_ERRTYPE_LOGGED || info.procId == 0)) { menuEnter(); @@ -321,7 +321,7 @@ void errDispThreadMain(void) do { - handles[0] = terminationRequestEvent; + handles[0] = preTerminationEvent; handles[1] = serverHandle; handles[2] = sessionHandle; @@ -365,7 +365,7 @@ void errDispThreadMain(void) } } } - while(!terminationRequest); + while(!preTerminationRequested); svcCloseHandle(sessionHandle); svcCloseHandle(clientHandle); diff --git a/sysmodules/rosalina/source/gdb/monitor.c b/sysmodules/rosalina/source/gdb/monitor.c index 73962a7..0fa81a4 100644 --- a/sysmodules/rosalina/source/gdb/monitor.c +++ b/sysmodules/rosalina/source/gdb/monitor.c @@ -9,15 +9,15 @@ #include "gdb/net.h" #include "gdb/debug.h" -extern Handle terminationRequestEvent; -extern bool terminationRequest; +extern Handle preTerminationEvent; +extern bool preTerminationRequested; void GDB_RunMonitor(GDBServer *server) { Handle handles[3 + MAX_DEBUG]; Result r = 0; - handles[0] = terminationRequestEvent; + handles[0] = preTerminationEvent; handles[1] = server->super.shall_terminate_event; handles[2] = server->statusUpdated; @@ -81,5 +81,5 @@ void GDB_RunMonitor(GDBServer *server) RecursiveLock_Unlock(&ctx->lock); } } - while(!terminationRequest && server->super.running); + while(!preTerminationRequested && server->super.running); } diff --git a/sysmodules/rosalina/source/input_redirection.c b/sysmodules/rosalina/source/input_redirection.c index 6417dbb..2c498d0 100644 --- a/sysmodules/rosalina/source/input_redirection.c +++ b/sysmodules/rosalina/source/input_redirection.c @@ -113,7 +113,7 @@ void inputRedirectionThreadMain(void) char buf[20]; u32 oldSpecialButtons = 0, specialButtons = 0; - while(inputRedirectionEnabled && !terminationRequest) + while(inputRedirectionEnabled && !preTerminationRequested) { struct pollfd pfd; pfd.fd = sock; diff --git a/sysmodules/rosalina/source/main.c b/sysmodules/rosalina/source/main.c index 0d3dc05..af6ea94 100644 --- a/sysmodules/rosalina/source/main.c +++ b/sysmodules/rosalina/source/main.c @@ -155,8 +155,9 @@ void initSystem(void) srvSetBlockingPolicy(true); // GetServiceHandle nonblocking if service port is full } -bool terminationRequest = false; -Handle terminationRequestEvent; +bool menuShouldExit = false; +bool preTerminationRequested = false; +Handle preTerminationEvent; extern bool isHidInitialized; static void handleTermNotification(u32 notificationId) @@ -188,8 +189,9 @@ static void handlePreTermNotification(u32 notificationId) hidExit(); // Termination request - terminationRequest = true; - svcSignalEvent(terminationRequestEvent); + menuShouldExit = true; + preTerminationRequested = true; + svcSignalEvent(preTerminationEvent); Draw_Unlock(); } @@ -232,7 +234,7 @@ int main(void) bufPtrs[2] = IPC_Desc_StaticBuffer(sizeof(ldrArgvBuf), 1); bufPtrs[3] = (u32)ldrArgvBuf; - if(R_FAILED(svcCreateEvent(&terminationRequestEvent, RESET_STICKY))) + if(R_FAILED(svcCreateEvent(&preTerminationEvent, RESET_STICKY))) svcBreak(USERBREAK_ASSERT); Draw_Init(); diff --git a/sysmodules/rosalina/source/menu.c b/sysmodules/rosalina/source/menu.c index 0c947fa..28fdc8e 100644 --- a/sysmodules/rosalina/source/menu.c +++ b/sysmodules/rosalina/source/menu.c @@ -61,7 +61,7 @@ u32 waitInputWithTimeout(s32 msec) { svcSleepThread(1 * 1000 * 1000LL); Draw_Lock(); - if (!isHidInitialized || terminationRequest) + if (!isHidInitialized || menuShouldExit) { keys = 0; Draw_Unlock(); @@ -72,7 +72,7 @@ u32 waitInputWithTimeout(s32 msec) hidScanInput(); keys = convertHidKeys(hidKeysDown()) | (convertHidKeys(hidKeysDownRepeat()) & DIRECTIONAL_KEYS); Draw_Unlock(); - } while (keys == 0 && !terminationRequest && isHidInitialized && (msec < 0 || n < msec)); + } while (keys == 0 && !menuShouldExit && isHidInitialized && (msec < 0 || n < msec)); return keys; @@ -89,7 +89,7 @@ static u32 scanHeldKeys(void) Draw_Lock(); - if (!isHidInitialized || terminationRequest) + if (!isHidInitialized || menuShouldExit) keys = 0; else { @@ -108,13 +108,13 @@ u32 waitComboWithTimeout(s32 msec) u32 tempKeys = 0; // Wait for nothing to be pressed - while (scanHeldKeys() != 0 && !terminationRequest && isHidInitialized && (msec < 0 || n < msec)) + while (scanHeldKeys() != 0 && !menuShouldExit && isHidInitialized && (msec < 0 || n < msec)) { svcSleepThread(1 * 1000 * 1000LL); n++; } - if (terminationRequest || !isHidInitialized || !(msec < 0 || n < msec)) + if (menuShouldExit || !isHidInitialized || !(msec < 0 || n < msec)) return 0; do @@ -130,7 +130,7 @@ u32 waitComboWithTimeout(s32 msec) if (i == 1) keys = tempKeys; } } - while((keys == 0 || scanHeldKeys() != 0) && !terminationRequest && isHidInitialized && (msec < 0 || n < msec)); + while((keys == 0 || scanHeldKeys() != 0) && !menuShouldExit && isHidInitialized && (msec < 0 || n < msec)); return keys; } @@ -171,8 +171,11 @@ void menuThreadMain(void) hidInit(); // assume this doesn't fail isHidInitialized = true; - while(!terminationRequest) + while(!preTerminationRequested) { + if (menuShouldExit) + continue; + Cheat_ApplyCheats(); if((scanHeldKeys() & menuCombo) == menuCombo) @@ -191,8 +194,9 @@ static s32 menuRefCount = 0; void menuEnter(void) { Draw_Lock(); - if(menuRefCount++ == 0) + if(!menuShouldExit && menuRefCount == 0) { + menuRefCount++; svcKernelSetState(0x10000, 1); svcSleepThread(5 * 1000 * 100LL); if (Draw_AllocateFramebufferCache() == 0) @@ -372,5 +376,5 @@ void menuShow(Menu *root) menuDraw(currentMenu, selectedItem); Draw_Unlock(); } - while(!terminationRequest); + while(!menuShouldExit); } diff --git a/sysmodules/rosalina/source/menus.c b/sysmodules/rosalina/source/menus.c index a4b6739..f978f63 100644 --- a/sysmodules/rosalina/source/menus.c +++ b/sysmodules/rosalina/source/menus.c @@ -89,7 +89,7 @@ void RosalinaMenu_ShowCredits(void) Draw_FlushFramebuffer(); Draw_Unlock(); } - while(!(waitInput() & KEY_B) && !terminationRequest); + while(!(waitInput() & KEY_B) && !menuShouldExit); } void RosalinaMenu_Reboot(void) @@ -117,7 +117,7 @@ void RosalinaMenu_Reboot(void) } else if(pressed & KEY_B) return; } - while(!terminationRequest); + while(!menuShouldExit); } void RosalinaMenu_PowerOff(void) // Soft shutdown. @@ -146,7 +146,7 @@ void RosalinaMenu_PowerOff(void) // Soft shutdown. else if(pressed & KEY_B) return; } - while(!terminationRequest); + while(!menuShouldExit); } @@ -310,7 +310,7 @@ end: Draw_FlushFramebuffer(); Draw_Unlock(); } - while(!(waitInput() & KEY_B) && !terminationRequest); + while(!(waitInput() & KEY_B) && !menuShouldExit); #undef TRY } diff --git a/sysmodules/rosalina/source/menus/cheats.c b/sysmodules/rosalina/source/menus/cheats.c index e2727e6..f313248 100644 --- a/sysmodules/rosalina/source/menus/cheats.c +++ b/sysmodules/rosalina/source/menus/cheats.c @@ -1944,7 +1944,7 @@ void RosalinaMenu_Cheats(void) Draw_FlushFramebuffer(); Draw_Unlock(); - } while (!(waitInput() & KEY_B) && !terminationRequest); + } while (!(waitInput() & KEY_B) && !menuShouldExit); } else { @@ -1982,14 +1982,14 @@ void RosalinaMenu_Cheats(void) Draw_FlushFramebuffer(); Draw_Unlock(); - if (terminationRequest) break; + if (menuShouldExit) break; u32 pressed; do { pressed = waitInputWithTimeout(50); if (pressed != 0) break; - } while (pressed == 0 && !terminationRequest); + } while (pressed == 0 && !menuShouldExit); if (pressed & KEY_B) break; @@ -2025,7 +2025,7 @@ void RosalinaMenu_Cheats(void) pagePrev = page; page = selected / CHEATS_PER_MENU_PAGE; - } while (!terminationRequest); + } while (!menuShouldExit); } } diff --git a/sysmodules/rosalina/source/menus/debugger.c b/sysmodules/rosalina/source/menus/debugger.c index d8e6aff..82a514e 100644 --- a/sysmodules/rosalina/source/menus/debugger.c +++ b/sysmodules/rosalina/source/menus/debugger.c @@ -139,13 +139,13 @@ void DebuggerMenu_EnableDebugger(void) if(!done) { res = GDB_InitializeServer(&gdbServer); - Handle handles[3] = { gdbServer.super.started_event, gdbServer.super.shall_terminate_event, terminationRequestEvent }; + Handle handles[3] = { gdbServer.super.started_event, gdbServer.super.shall_terminate_event, preTerminationEvent }; s32 idx; if(R_SUCCEEDED(res)) { debuggerCreateSocketThread(); debuggerCreateDebugThread(); - res = svcWaitSynchronizationN(&idx, handles, 3, false, 10 * 1000 * 1000 * 1000LL); + res = svcWaitSynchronizationN(&idx, handles, 3, false, 5 * 1000 * 1000 * 1000LL); if(res == 0) res = gdbServer.super.init_result; } @@ -162,7 +162,7 @@ void DebuggerMenu_EnableDebugger(void) Draw_FlushFramebuffer(); Draw_Unlock(); } - while(!(waitInput() & KEY_B) && !terminationRequest); + while(!(waitInput() & KEY_B) && !menuShouldExit); } void DebuggerMenu_DisableDebugger(void) @@ -183,7 +183,7 @@ void DebuggerMenu_DisableDebugger(void) Draw_FlushFramebuffer(); Draw_Unlock(); } - while(!(waitInput() & KEY_B) && !terminationRequest); + while(!(waitInput() & KEY_B) && !menuShouldExit); } void DebuggerMenu_DebugNextApplicationByForce(void) @@ -232,7 +232,7 @@ void DebuggerMenu_DebugNextApplicationByForce(void) Draw_FlushFramebuffer(); Draw_Unlock(); } - while(!(waitInput() & KEY_B) && !terminationRequest); + while(!(waitInput() & KEY_B) && !menuShouldExit); } void debuggerSocketThreadMain(void) diff --git a/sysmodules/rosalina/source/menus/miscellaneous.c b/sysmodules/rosalina/source/menus/miscellaneous.c index 44cde04..515c09b 100644 --- a/sysmodules/rosalina/source/menus/miscellaneous.c +++ b/sysmodules/rosalina/source/menus/miscellaneous.c @@ -95,7 +95,7 @@ void MiscellaneousMenu_SwitchBoot3dsxTargetTitle(void) Draw_FlushFramebuffer(); Draw_Unlock(); } - while(!(waitInput() & KEY_B) && !terminationRequest); + while(!(waitInput() & KEY_B) && !menuShouldExit); } static void MiscellaneousMenu_ConvertComboToString(char *out, u32 combo) @@ -161,7 +161,7 @@ void MiscellaneousMenu_ChangeMenuCombo(void) Draw_FlushFramebuffer(); Draw_Unlock(); } - while(!(waitInput() & KEY_B) && !terminationRequest); + while(!(waitInput() & KEY_B) && !menuShouldExit); } void MiscellaneousMenu_SaveSettings(void) @@ -227,7 +227,7 @@ void MiscellaneousMenu_SaveSettings(void) Draw_FlushFramebuffer(); Draw_Unlock(); } - while(!(waitInput() & KEY_B) && !terminationRequest); + while(!(waitInput() & KEY_B) && !menuShouldExit); } void MiscellaneousMenu_InputRedirection(void) @@ -327,7 +327,7 @@ void MiscellaneousMenu_InputRedirection(void) Draw_FlushFramebuffer(); Draw_Unlock(); } - while(!(waitInput() & KEY_B) && !terminationRequest); + while(!(waitInput() & KEY_B) && !menuShouldExit); } void MiscellaneousMenu_SyncTimeDate(void) @@ -368,7 +368,7 @@ void MiscellaneousMenu_SyncTimeDate(void) Draw_FlushFramebuffer(); Draw_Unlock(); } - while(!(input & (KEY_A | KEY_B)) && !terminationRequest); + while(!(input & (KEY_A | KEY_B)) && !menuShouldExit); if (input & KEY_B) return; @@ -410,6 +410,6 @@ void MiscellaneousMenu_SyncTimeDate(void) Draw_FlushFramebuffer(); Draw_Unlock(); } - while(!(input & KEY_B) && !terminationRequest); + while(!(input & KEY_B) && !menuShouldExit); } diff --git a/sysmodules/rosalina/source/menus/process_list.c b/sysmodules/rosalina/source/menus/process_list.c index 6cbd77e..096cc8a 100644 --- a/sysmodules/rosalina/source/menus/process_list.c +++ b/sysmodules/rosalina/source/menus/process_list.c @@ -197,7 +197,7 @@ end: Draw_FlushFramebuffer(); Draw_Unlock(); } - while(!(waitInput() & KEY_B) && !terminationRequest); + while(!(waitInput() & KEY_B) && !menuShouldExit); #undef TRY } @@ -568,7 +568,7 @@ static void ProcessListMenu_MemoryViewer(const ProcessInfo *info) if(menus[menuMode].selected >= menus[menuMode].max) menus[menuMode].selected = menus[menuMode].max - 1; } - while(!terminationRequest); + while(!menuShouldExit); clearMenu(); } @@ -685,7 +685,7 @@ void RosalinaMenu_ProcessList(void) Draw_FlushFramebuffer(); Draw_Unlock(); - if(terminationRequest) + if(menuShouldExit) break; u32 pressed; @@ -698,7 +698,7 @@ void RosalinaMenu_ProcessList(void) if(memcmp(infos, infosPrev, sizeof(infos)) != 0) break; } - while(pressed == 0 && !terminationRequest); + while(pressed == 0 && !menuShouldExit); if(pressed & KEY_B) break; @@ -728,5 +728,5 @@ void RosalinaMenu_ProcessList(void) pagePrev = page; page = selected / PROCESSES_PER_MENU_PAGE; } - while(!terminationRequest); + while(!menuShouldExit); } diff --git a/sysmodules/rosalina/source/menus/sysconfig.c b/sysmodules/rosalina/source/menus/sysconfig.c index 8eab110..674577a 100644 --- a/sysmodules/rosalina/source/menus/sysconfig.c +++ b/sysmodules/rosalina/source/menus/sysconfig.c @@ -78,7 +78,7 @@ void SysConfigMenu_ToggleLEDs(void) else if(pressed & KEY_B) return; } - while(!terminationRequest); + while(!menuShouldExit); } void SysConfigMenu_ToggleWireless(void) @@ -148,7 +148,7 @@ void SysConfigMenu_ToggleWireless(void) else if(pressed & KEY_B) return; } - while(!terminationRequest); + while(!menuShouldExit); } void SysConfigMenu_UpdateStatus(bool control) @@ -227,7 +227,7 @@ static bool SysConfigMenu_ForceWifiConnection(int slot) if(pressed & KEY_B) break; } - while(!terminationRequest); + while(!menuShouldExit); return forcedConnection; } @@ -270,7 +270,7 @@ void SysConfigMenu_TogglePowerButton(void) else if(pressed & KEY_B) return; } - while(!terminationRequest); + while(!menuShouldExit); } void SysConfigMenu_ControlWifi(void) @@ -332,7 +332,7 @@ void SysConfigMenu_ControlWifi(void) else if(pressed & KEY_B) return; } - while(!terminationRequest); + while(!menuShouldExit); } void SysConfigMenu_DisableForcedWifiConnection(void) @@ -355,5 +355,5 @@ void SysConfigMenu_DisableForcedWifiConnection(void) if(pressed & KEY_B) return; } - while(!terminationRequest); + while(!menuShouldExit); } diff --git a/sysmodules/rosalina/source/sock_util.c b/sysmodules/rosalina/source/sock_util.c index 16485d4..d32ef67 100644 --- a/sysmodules/rosalina/source/sock_util.c +++ b/sysmodules/rosalina/source/sock_util.c @@ -14,8 +14,8 @@ #include "minisoc.h" #include "sock_util.h" -extern Handle terminationRequestEvent; -extern bool terminationRequest; +extern Handle preTerminationEvent; +extern bool preTerminationRequested; // soc's poll function is odd, and doesn't like -1 as fd. // so this compacts everything together @@ -104,7 +104,7 @@ Result server_init(struct sock_server *serv) Result server_bind(struct sock_server *serv, u16 port) { int server_sockfd; - Handle handles[2] = { terminationRequestEvent, serv->shall_terminate_event }; + Handle handles[2] = { preTerminationEvent, serv->shall_terminate_event }; s32 idx = -1; server_sockfd = socSocket(AF_INET, SOCK_STREAM, 0); @@ -163,7 +163,7 @@ Result server_bind(struct sock_server *serv, u16 port) static bool server_should_exit(struct sock_server *serv) { - return svcWaitSynchronization(serv->shall_terminate_event, 0) == 0 || svcWaitSynchronization(terminationRequestEvent, 0) == 0; + return svcWaitSynchronization(serv->shall_terminate_event, 0) == 0 || svcWaitSynchronization(preTerminationEvent, 0) == 0; } void server_run(struct sock_server *serv) @@ -172,7 +172,7 @@ void server_run(struct sock_server *serv) serv->running = true; svcSignalEvent(serv->started_event); - while(serv->running && !terminationRequest) + while(serv->running && !preTerminationRequested) { if(server_should_exit(serv)) goto abort_connections;