rosalina/sm: properly interact with ndm
This commit is contained in:
parent
ba26ae0f1c
commit
e096aaabc4
@ -16,27 +16,12 @@ static u32 socContextAddr = 0x08000000;
|
|||||||
static u32 socContextSize = 0x60000;
|
static u32 socContextSize = 0x60000;
|
||||||
static Handle miniSocHandle;
|
static Handle miniSocHandle;
|
||||||
static Handle miniSocMemHandle;
|
static Handle miniSocMemHandle;
|
||||||
|
static bool exclusiveStateEntered = false;
|
||||||
|
|
||||||
bool miniSocEnabled = false;
|
bool miniSocEnabled = false;
|
||||||
|
|
||||||
s32 _net_convert_error(s32 sock_retval);
|
s32 _net_convert_error(s32 sock_retval);
|
||||||
|
|
||||||
// To prevent ndm:u from disconnecting us
|
|
||||||
static Result srvExtAddToNdmuWorkaroundCount(s32 count)
|
|
||||||
{
|
|
||||||
Result ret = 0;
|
|
||||||
u32 *cmdbuf = getThreadCommandBuffer();
|
|
||||||
|
|
||||||
cmdbuf[0] = IPC_MakeHeader(0x1000,1,0);
|
|
||||||
cmdbuf[1] = (u32)count;
|
|
||||||
|
|
||||||
ret = svcSendSyncRequest(*srvGetSessionHandle());
|
|
||||||
if(ret != 0)
|
|
||||||
return ret;
|
|
||||||
|
|
||||||
return cmdbuf[1];
|
|
||||||
}
|
|
||||||
|
|
||||||
static Result SOCU_Initialize(Handle memhandle, u32 memsize)
|
static Result SOCU_Initialize(Handle memhandle, u32 memsize)
|
||||||
{
|
{
|
||||||
Result ret = 0;
|
Result ret = 0;
|
||||||
@ -102,9 +87,18 @@ Result miniSocInit(void)
|
|||||||
ret = SOCU_Initialize(miniSocMemHandle, socContextSize);
|
ret = SOCU_Initialize(miniSocMemHandle, socContextSize);
|
||||||
if(ret != 0) goto cleanup;
|
if(ret != 0) goto cleanup;
|
||||||
|
|
||||||
|
if (!exclusiveStateEntered)
|
||||||
|
{
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
svcKernelSetState(0x10000, 0x10);
|
svcKernelSetState(0x10000, 0x10);
|
||||||
miniSocEnabled = true;
|
miniSocEnabled = true;
|
||||||
srvExtAddToNdmuWorkaroundCount(1);
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
@ -132,7 +126,6 @@ cleanup:
|
|||||||
|
|
||||||
Result miniSocExitDirect(void)
|
Result miniSocExitDirect(void)
|
||||||
{
|
{
|
||||||
//if (miniSocRefCount != 0) __builtin_trap();
|
|
||||||
Result ret = 0;
|
Result ret = 0;
|
||||||
u32 tmp;
|
u32 tmp;
|
||||||
|
|
||||||
@ -147,8 +140,17 @@ Result miniSocExitDirect(void)
|
|||||||
svcControlMemory(&tmp, socContextAddr, socContextAddr, socContextSize, MEMOP_FREE, MEMPERM_DONTCARE);
|
svcControlMemory(&tmp, socContextAddr, socContextAddr, socContextSize, MEMOP_FREE, MEMPERM_DONTCARE);
|
||||||
if(ret == 0)
|
if(ret == 0)
|
||||||
{
|
{
|
||||||
|
if (exclusiveStateEntered)
|
||||||
|
{
|
||||||
|
//ndmuInit();
|
||||||
|
ret = NDMU_UnlockState();
|
||||||
|
if (R_SUCCEEDED(ret))
|
||||||
|
ret = NDMU_LeaveExclusiveState();
|
||||||
|
ndmuExit();
|
||||||
|
exclusiveStateEntered = R_FAILED(ret);
|
||||||
|
}
|
||||||
|
|
||||||
miniSocEnabled = false;
|
miniSocEnabled = false;
|
||||||
srvExtAddToNdmuWorkaroundCount(-1);
|
|
||||||
svcKernelSetState(0x10000, 0x10);
|
svcKernelSetState(0x10000, 0x10);
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -17,7 +17,6 @@ This is part of 3ds_sm, which is licensed under the MIT license (see LICENSE for
|
|||||||
|
|
||||||
extern u32 nbSection0Modules;
|
extern u32 nbSection0Modules;
|
||||||
extern Handle resumeGetServiceHandleOrPortRegisteredSemaphore;
|
extern Handle resumeGetServiceHandleOrPortRegisteredSemaphore;
|
||||||
extern u32 ndmuServicePid;
|
|
||||||
|
|
||||||
struct SessionDataList;
|
struct SessionDataList;
|
||||||
|
|
||||||
|
@ -10,17 +10,11 @@ This is part of 3ds_sm, which is licensed under the MIT license (see LICENSE for
|
|||||||
|
|
||||||
#include <stdatomic.h>
|
#include <stdatomic.h>
|
||||||
|
|
||||||
static atomic_int ndmuWorkaroundCount;
|
|
||||||
|
|
||||||
static bool isNotificationInhibited(const ProcessData *processData, u32 notificationId)
|
static bool isNotificationInhibited(const ProcessData *processData, u32 notificationId)
|
||||||
{
|
{
|
||||||
u32 pid = processData->pid;
|
(void)processData;
|
||||||
switch(notificationId)
|
switch(notificationId)
|
||||||
{
|
{
|
||||||
// Shell opened, shell closed
|
|
||||||
case 0x213:
|
|
||||||
case 0x214:
|
|
||||||
return pid == ndmuServicePid && atomic_load(&ndmuWorkaroundCount) > 0;
|
|
||||||
default:
|
default:
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -207,10 +201,3 @@ Result PublishToAll(u32 notificationId)
|
|||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
Result AddToNdmuWorkaroundCount(s32 count)
|
|
||||||
{
|
|
||||||
// Note: no check is made to (current value)+count
|
|
||||||
atomic_fetch_add(&ndmuWorkaroundCount, count);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
@ -13,8 +13,6 @@ This is part of 3ds_sm, which is licensed under the MIT license (see LICENSE for
|
|||||||
ServiceInfo servicesInfo[0xA0] = { 0 };
|
ServiceInfo servicesInfo[0xA0] = { 0 };
|
||||||
u32 nbServices = 0; // including "ports" registered with getPort
|
u32 nbServices = 0; // including "ports" registered with getPort
|
||||||
|
|
||||||
u32 ndmuServicePid = 3; // use our PID as default.
|
|
||||||
|
|
||||||
static Result checkServiceName(const char *name, s32 nameSize)
|
static Result checkServiceName(const char *name, s32 nameSize)
|
||||||
{
|
{
|
||||||
if(nameSize <= 0 || nameSize > 8)
|
if(nameSize <= 0 || nameSize > 8)
|
||||||
@ -98,9 +96,6 @@ static Result doRegisterServiceOrPort(u32 pid, Handle *serverPort, Handle client
|
|||||||
if(!isNamedPort)
|
if(!isNamedPort)
|
||||||
*serverPort = portServer;
|
*serverPort = portServer;
|
||||||
|
|
||||||
if(R_SUCCEEDED(res) && strcmp(name, "ndm:u") == 0)
|
|
||||||
ndmuServicePid = pid;
|
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -167,14 +167,6 @@ Result srvHandleCommands(SessionData *sessionData)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case 0x1000: // Custom command: AddToNdmuWorkaroundCount
|
|
||||||
{
|
|
||||||
res = AddToNdmuWorkaroundCount((s32)cmdbuf[1]);
|
|
||||||
cmdbuf[0] = IPC_MakeHeader(0x1000, 1, 0);;
|
|
||||||
cmdbuf[1] = (u32)res;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
goto invalid_command;
|
goto invalid_command;
|
||||||
break;
|
break;
|
||||||
|
Reference in New Issue
Block a user