rosalina: ndm + shutdown issue workaround

This commit is contained in:
TuxSH 2020-07-16 17:55:31 +01:00
parent d6e72080d9
commit 748b771618
3 changed files with 44 additions and 18 deletions

View File

@ -21,6 +21,10 @@
extern bool miniSocEnabled;
Result miniSocInit(void);
void miniSocLockState(void);
void miniSocUnlockState(bool force);
Result miniSocExitDirect(void);
Result miniSocExit(void);

View File

@ -180,6 +180,8 @@ static void handlePreTermNotification(u32 notificationId)
(void)notificationId;
// Might be subject to a race condition, but heh.
miniSocUnlockState(true);
// Disable input redirection
InputRedirection_Disable(100 * 1000 * 1000LL);

View File

@ -1,3 +1,4 @@
/*
* This file is part of Luma3DS.
* Copyright (C) 2016-2020 Aurora Wright, TuxSH
@ -54,6 +55,41 @@ static Result SOCU_Shutdown(void)
return cmdbuf[1];
}
// unsafe but what can I do?
void miniSocLockState(void)
{
Result res = 0;
__dmb();
if (!exclusiveStateEntered && isServiceUsable("ndm:u"))
{
ndmuInit();
res = NDMU_EnterExclusiveState(NDM_EXCLUSIVE_STATE_INFRASTRUCTURE);
if (R_SUCCEEDED(res))
res = NDMU_LockState(); // prevents ndm from switching to StreetPass when the lid is closed
exclusiveStateEntered = R_SUCCEEDED(res);
__dmb();
}
}
void miniSocUnlockState(bool force)
{
Result res = 0;
__dmb();
if (exclusiveStateEntered)
{
if (!force)
{
res = NDMU_UnlockState();
if (R_SUCCEEDED(res))
res = NDMU_LeaveExclusiveState();
}
ndmuExit();
exclusiveStateEntered = R_FAILED(res);
__dmb();
}
}
Result miniSocInit(void)
{
if(AtomicPostIncrement(&miniSocRefCount))
@ -87,15 +123,7 @@ Result miniSocInit(void)
ret = SOCU_Initialize(miniSocMemHandle, socContextSize);
if(ret != 0) goto cleanup;
if (!exclusiveStateEntered && isServiceUsable("ndm:u"))
{
ndmuInit();
ret = NDMU_EnterExclusiveState(NDM_EXCLUSIVE_STATE_INFRASTRUCTURE);
if (R_SUCCEEDED(ret))
ret = NDMU_LockState(); // prevents ndm from switching to StreetPass when the lid is closed
//ndmuExit();
exclusiveStateEntered = R_SUCCEEDED(ret);
}
miniSocLockState();
svcKernelSetState(0x10000, 0x10);
miniSocEnabled = true;
@ -140,15 +168,7 @@ Result miniSocExitDirect(void)
svcControlMemory(&tmp, socContextAddr, socContextAddr, socContextSize, MEMOP_FREE, MEMPERM_DONTCARE);
if(ret == 0)
{
if (exclusiveStateEntered && isServiceUsable("ndm:u"))
{
//ndmuInit();
ret = NDMU_UnlockState();
if (R_SUCCEEDED(ret))
ret = NDMU_LeaveExclusiveState();
ndmuExit();
exclusiveStateEntered = R_FAILED(ret);
}
miniSocUnlockState(false);
miniSocEnabled = false;
svcKernelSetState(0x10000, 0x10);