Add client code for new custom pm commands, use them, fix pm race conditions
This commit is contained in:
10
sysmodules/rosalina/include/pmdbgext.h
Normal file
10
sysmodules/rosalina/include/pmdbgext.h
Normal file
@@ -0,0 +1,10 @@
|
||||
// License for this file: ctrulib's license
|
||||
// Copyright AuroraWright, TuxSH 2019
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <3ds/services/pmapp.h>
|
||||
|
||||
Result PMDBG_GetCurrentAppTitleId(u64 *outTitleId);
|
||||
Result PMDBG_DebugNextApplicationByForce(void);
|
||||
Result PMDBG_LaunchTitleDebug(Handle *outDebug, const FS_ProgramInfo *programInfo, u32 launchFlags);
|
||||
@@ -84,11 +84,15 @@ void __appInit()
|
||||
|
||||
if (R_FAILED(stealFsReg()) || R_FAILED(fsRegSetupPermissions()) || R_FAILED(fsInit()))
|
||||
svcBreak(USERBREAK_PANIC);
|
||||
|
||||
if (R_FAILED(pmDbgInit()))
|
||||
svcBreak(USERBREAK_PANIC);
|
||||
}
|
||||
|
||||
// this is called after main exits
|
||||
void __appExit()
|
||||
{
|
||||
pmDbgExit();
|
||||
fsExit();
|
||||
svcCloseHandle(*fsRegGetSessionHandle());
|
||||
srvExit();
|
||||
|
||||
@@ -34,6 +34,7 @@
|
||||
#include "utils.h" // for makeARMBranch
|
||||
#include "minisoc.h"
|
||||
#include "ifile.h"
|
||||
#include "pmdbgext.h"
|
||||
|
||||
Menu miscellaneousMenu = {
|
||||
"Miscellaneous options menu",
|
||||
@@ -54,31 +55,12 @@ void MiscellaneousMenu_SwitchBoot3dsxTargetTitle(void)
|
||||
|
||||
if(HBLDR_3DSX_TID == HBLDR_DEFAULT_3DSX_TID)
|
||||
{
|
||||
u32 pidList[0x40];
|
||||
s32 processAmount;
|
||||
|
||||
res = svcGetProcessList(&processAmount, pidList, 0x40);
|
||||
res = PMDBG_GetCurrentAppTitleId(&titleId);
|
||||
if(R_SUCCEEDED(res))
|
||||
{
|
||||
for(s32 i = 0; i < processAmount && (u32)(titleId >> 32) != 0x00040010 && (u32)(titleId >> 32) != 0x00040000; i++)
|
||||
{
|
||||
Handle processHandle;
|
||||
Result res = svcOpenProcess(&processHandle, pidList[i]);
|
||||
if(R_FAILED(res))
|
||||
continue;
|
||||
|
||||
svcGetProcessInfo((s64 *)&titleId, processHandle, 0x10001);
|
||||
svcCloseHandle(processHandle);
|
||||
}
|
||||
}
|
||||
|
||||
if(R_SUCCEEDED(res) && ((u32)(titleId >> 32) == 0x00040010 || (u32)(titleId >> 32) == 0x00040000))
|
||||
{
|
||||
HBLDR_3DSX_TID = titleId;
|
||||
miscellaneousMenu.items[0].title = "Switch the hb. title to hblauncher_loader";
|
||||
}
|
||||
else if(R_FAILED(res))
|
||||
sprintf(failureReason, "%08lx", (u32)res);
|
||||
else
|
||||
{
|
||||
res = -1;
|
||||
|
||||
47
sysmodules/rosalina/source/pmdbgext.c
Normal file
47
sysmodules/rosalina/source/pmdbgext.c
Normal file
@@ -0,0 +1,47 @@
|
||||
// License for this file: ctrulib's license
|
||||
// Copyright AuroraWright, TuxSH 2019
|
||||
|
||||
#include <string.h>
|
||||
#include <3ds/types.h>
|
||||
#include <3ds/result.h>
|
||||
#include <3ds/svc.h>
|
||||
#include <3ds/srv.h>
|
||||
#include <3ds/synchronization.h>
|
||||
#include <3ds/services/pmdbg.h>
|
||||
#include <3ds/ipc.h>
|
||||
|
||||
Result PMDBG_GetCurrentAppTitleId(u64 *outTitleId)
|
||||
{
|
||||
Result ret = 0;
|
||||
u32 *cmdbuf = getThreadCommandBuffer();
|
||||
cmdbuf[0] = IPC_MakeHeader(0x100, 0, 0);
|
||||
if(R_FAILED(ret = svcSendSyncRequest(*pmDbgGetSessionHandle()))) return ret;
|
||||
|
||||
memcpy(outTitleId, cmdbuf + 2, 8);
|
||||
return cmdbuf[1];
|
||||
}
|
||||
|
||||
Result PMDBG_DebugNextApplicationByForce(void)
|
||||
{
|
||||
Result ret = 0;
|
||||
u32 *cmdbuf = getThreadCommandBuffer();
|
||||
cmdbuf[0] = IPC_MakeHeader(0x101, 0, 0);
|
||||
|
||||
if(R_FAILED(ret = svcSendSyncRequest(*pmDbgGetSessionHandle()))) return ret;
|
||||
return cmdbuf[1];
|
||||
}
|
||||
|
||||
Result PMDBG_LaunchTitleDebug(Handle *outDebug, const FS_ProgramInfo *programInfo, u32 launchFlags)
|
||||
{
|
||||
Result ret = 0;
|
||||
u32 *cmdbuf = getThreadCommandBuffer();
|
||||
|
||||
cmdbuf[0] = IPC_MakeHeader(0x102, 5, 0);
|
||||
memcpy(&cmdbuf[1], programInfo, sizeof(FS_ProgramInfo));
|
||||
cmdbuf[5] = launchFlags;
|
||||
|
||||
if(R_FAILED(ret = svcSendSyncRequest(*pmDbgGetSessionHandle()))) return ret;
|
||||
|
||||
*outDebug = cmdbuf[3];
|
||||
return (Result)cmdbuf[1];
|
||||
}
|
||||
Reference in New Issue
Block a user