From 24b9341c992ec884a3c486e2b441c7092e23b595 Mon Sep 17 00:00:00 2001 From: fincs Date: Mon, 18 Jul 2016 00:26:52 +0200 Subject: [PATCH] Fix lingering parameter bug with APTREINIT (aka hax 2.x) --- libctru/source/services/apt.c | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/libctru/source/services/apt.c b/libctru/source/services/apt.c index da939eb..625527d 100644 --- a/libctru/source/services/apt.c +++ b/libctru/source/services/apt.c @@ -129,6 +129,20 @@ Result aptSendCommand(u32* aptcmdbuf) return res; } +static void aptClearParamQueue(void) +{ + // Check for parameters? + for (;;) + { + APT_Command cmd; + Result res = APT_GlanceParameter(envGetAptAppId(), aptParameters, sizeof(aptParameters), NULL, &cmd, NULL, NULL); + if (R_FAILED(res) || cmd==APTCMD_NONE) break; + _aptDebug(2, cmd); + svcClearEvent(aptEvents[2]); + APT_CancelParameter(APPID_NONE, envGetAptAppId(), NULL); + } +} + static void aptInitCaptureInfo(aptCaptureBufInfo* capinfo) { GSPGPU_CaptureInfo gspcapinfo; @@ -265,7 +279,10 @@ void aptExit(void) closeAptLock = false; srvInit(); // Keep srv initialized } else + { APT_Finalize(envGetAptAppId()); + aptClearParamQueue(); + } svcSignalEvent(aptEvents[0]); threadJoin(aptEventHandlerThread, U64_MAX); @@ -400,20 +417,6 @@ APT_Command aptWaitForWakeUp(APT_Transition transition) return cmd; } -static void aptClearParamQueue(void) -{ - // Check for parameters? - for (;;) - { - APT_Command cmd; - Result res = APT_GlanceParameter(envGetAptAppId(), aptParameters, sizeof(aptParameters), NULL, &cmd, NULL, NULL); - if (R_FAILED(res) || cmd==APTCMD_NONE) break; - _aptDebug(2, cmd); - svcClearEvent(aptEvents[2]); - APT_CancelParameter(APPID_NONE, envGetAptAppId(), NULL); - } -} - static void aptScreenTransfer(NS_APPID appId, bool sysApplet) { aptCallHook(APTHOOK_ONSUSPEND);