pm: fix handling of "force next app debug" when autobooting homebrew

This commit is contained in:
TuxSH 2023-01-17 00:06:02 +00:00
parent 19f7ef372b
commit 571592ca7c
4 changed files with 21 additions and 10 deletions

View File

@ -290,8 +290,16 @@ static Result launchTitleImpl(Handle *debug, ProcessData **outProcessData, const
return res; return res;
} }
Result launchTitleImplWrapper(Handle *outDebug, u32 *outPid, const FS_ProgramInfo *programInfo, const FS_ProgramInfo *programInfoUpdate, u32 launchFlags) static Result launchTitleImplWrapper(Handle *outDebug, u32 *outPid, const FS_ProgramInfo *programInfo, const FS_ProgramInfo *programInfoUpdate, u32 launchFlags)
{ {
// Not in official PM, but we need to check here as well to avoid a race condition
ProcessList_Lock(&g_manager.processList);
if (g_manager.runningApplicationData != NULL && (launchFlags & PMLAUNCHFLAG_NORMAL_APPLICATION) != 0) {
ProcessList_Unlock(&g_manager.processList);
return 0xC8A05BF0;
}
ProcessList_Unlock(&g_manager.processList);
ExHeader_Info *exheaderInfo = ExHeaderInfoHeap_New(); ExHeader_Info *exheaderInfo = ExHeaderInfoHeap_New();
if (exheaderInfo == NULL) { if (exheaderInfo == NULL) {
panic(0); panic(0);
@ -319,7 +327,7 @@ static void LaunchTitleAsync(void *argdata)
launchTitleImplWrapper(NULL, NULL, &args->programInfo, &args->programInfoUpdate, args->launchFlags); launchTitleImplWrapper(NULL, NULL, &args->programInfo, &args->programInfoUpdate, args->launchFlags);
} }
Result LaunchTitle(u32 *outPid, const FS_ProgramInfo *programInfo, u32 launchFlags) Result LaunchTitle(u32 *outPid, const FS_ProgramInfo *programInfo, u32 launchFlags, bool allowAsync)
{ {
ProcessData *process, *foundProcess = NULL; ProcessData *process, *foundProcess = NULL;
bool originallyDebugged = launchFlags & PMLAUNCHFLAG_QUEUE_DEBUG_APPLICATION; bool originallyDebugged = launchFlags & PMLAUNCHFLAG_QUEUE_DEBUG_APPLICATION;
@ -362,7 +370,7 @@ Result LaunchTitle(u32 *outPid, const FS_ProgramInfo *programInfo, u32 launchFla
} }
return 0; return 0;
} else { } else {
if (launchFlags & PMLAUNCHFLAG_QUEUE_DEBUG_APPLICATION || !(launchFlags & PMLAUNCHFLAG_NORMAL_APPLICATION)) { if (!allowAsync || launchFlags & PMLAUNCHFLAG_QUEUE_DEBUG_APPLICATION || !(launchFlags & PMLAUNCHFLAG_NORMAL_APPLICATION)) {
Result res = launchTitleImplWrapper(NULL, outPid, programInfo, programInfo, launchFlags); Result res = launchTitleImplWrapper(NULL, outPid, programInfo, programInfo, launchFlags);
if (R_SUCCEEDED(res) && (launchFlags & PMLAUNCHFLAG_NORMAL_APPLICATION)) { if (R_SUCCEEDED(res) && (launchFlags & PMLAUNCHFLAG_NORMAL_APPLICATION)) {
g_debugNextApplication = false; g_debugNextApplication = false;
@ -445,7 +453,7 @@ Result LaunchApp(const FS_ProgramInfo *programInfo, u32 launchFlags)
assertSuccess(setAppCpuTimeLimit(0)); assertSuccess(setAppCpuTimeLimit(0));
ProcessList_Unlock(&g_manager.processList); ProcessList_Unlock(&g_manager.processList);
return LaunchTitle(NULL, programInfo, launchFlags | PMLAUNCHFLAG_LOAD_DEPENDENCIES | PMLAUNCHFLAG_NORMAL_APPLICATION); return LaunchTitle(NULL, programInfo, launchFlags | PMLAUNCHFLAG_LOAD_DEPENDENCIES | PMLAUNCHFLAG_NORMAL_APPLICATION, true);
} }
Result RunQueuedProcess(Handle *outDebug) Result RunQueuedProcess(Handle *outDebug)

View File

@ -9,7 +9,7 @@ enum {
PMLAUNCHFLAGEXT_FAKE_DEPENDENCY_LOADING = BIT(24), PMLAUNCHFLAGEXT_FAKE_DEPENDENCY_LOADING = BIT(24),
}; };
Result LaunchTitle(u32 *outPid, const FS_ProgramInfo *programInfo, u32 launchFlags); Result LaunchTitle(u32 *outPid, const FS_ProgramInfo *programInfo, u32 launchFlags, bool allowAsync);
Result LaunchTitleUpdate(const FS_ProgramInfo *programInfo, const FS_ProgramInfo *programInfoUpdate, u32 launchFlags); Result LaunchTitleUpdate(const FS_ProgramInfo *programInfo, const FS_ProgramInfo *programInfoUpdate, u32 launchFlags);
Result LaunchApp(const FS_ProgramInfo *programInfo, u32 launchFlags); Result LaunchApp(const FS_ProgramInfo *programInfo, u32 launchFlags);
Result RunQueuedProcess(Handle *outDebug); Result RunQueuedProcess(Handle *outDebug);
@ -20,5 +20,3 @@ Result autolaunchSysmodules(void);
// Custom // Custom
Result DebugNextApplicationByForce(bool debug); Result DebugNextApplicationByForce(bool debug);
Result LaunchTitleDebug(Handle *outDebug, const FS_ProgramInfo *programInfo, u32 launchFlags); Result LaunchTitleDebug(Handle *outDebug, const FS_ProgramInfo *programInfo, u32 launchFlags);
Result launchTitleImplWrapper(Handle *outDebug, u32 *outPid, const FS_ProgramInfo *programInfo, const FS_ProgramInfo *programInfoUpdate, u32 launchFlags);

View File

@ -26,7 +26,7 @@ void pmAppHandleCommands(void *ctx)
switch (cmdhdr >> 16) { switch (cmdhdr >> 16) {
case 1: case 1:
memcpy(&programInfo, cmdbuf + 1, sizeof(FS_ProgramInfo)); memcpy(&programInfo, cmdbuf + 1, sizeof(FS_ProgramInfo));
cmdbuf[1] = LaunchTitle(&pid, &programInfo, cmdbuf[5]); cmdbuf[1] = LaunchTitle(&pid, &programInfo, cmdbuf[5], true);
cmdbuf[2] = pid; cmdbuf[2] = pid;
cmdbuf[0] = IPC_MakeHeader(1, 2, 0); cmdbuf[0] = IPC_MakeHeader(1, 2, 0);
break; break;

View File

@ -6,6 +6,7 @@
#include "exheader_info_heap.h" #include "exheader_info_heap.h"
#include "task_runner.h" #include "task_runner.h"
#include "launch.h" #include "launch.h"
#include "reslimit.h"
void forceMountSdCard(void) void forceMountSdCard(void)
{ {
@ -440,11 +441,15 @@ static void ChainloadHomebrewDirtyAsync(void *argdata)
ProcessList_Unlock(&g_manager.processList); ProcessList_Unlock(&g_manager.processList);
} while (app != NULL); } while (app != NULL);
// There is a small time window where we could fail (with another app spawning)
// Since this is a dirty workaround for hb support on SAFE_FIRM, we can opt not to support // Since this is a dirty workaround for hb support on SAFE_FIRM, we can opt not to support
// launch-from-gamecard/update support. // launch-from-gamecard/update support.
launchFlags &= ~PMLAUNCHFLAG_USE_UPDATE_TITLE; // Also clear the debug queue flag, obviously (it'll be reset by the "force next app debug"
// mechanism if needed)
launchFlags &= ~(PMLAUNCHFLAG_USE_UPDATE_TITLE | PMLAUNCHFLAG_QUEUE_DEBUG_APPLICATION);
launchFlags |= PMLAUNCHFLAGEXT_FAKE_DEPENDENCY_LOADING; launchFlags |= PMLAUNCHFLAGEXT_FAKE_DEPENDENCY_LOADING;
res = launchTitleImplWrapper(NULL, NULL, &programInfo, NULL, launchFlags); assertSuccess(setAppCpuTimeLimit(0));
res = LaunchTitle(NULL, &programInfo, launchFlags, false);
} }
} }