diff --git a/sysmodules/rosalina/source/minisoc.c b/sysmodules/rosalina/source/minisoc.c index 77ef571..50c96bd 100644 --- a/sysmodules/rosalina/source/minisoc.c +++ b/sysmodules/rosalina/source/minisoc.c @@ -16,27 +16,12 @@ static u32 socContextAddr = 0x08000000; static u32 socContextSize = 0x60000; static Handle miniSocHandle; static Handle miniSocMemHandle; +static bool exclusiveStateEntered = false; bool miniSocEnabled = false; 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) { Result ret = 0; @@ -102,9 +87,18 @@ Result miniSocInit(void) ret = SOCU_Initialize(miniSocMemHandle, socContextSize); 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); miniSocEnabled = true; - srvExtAddToNdmuWorkaroundCount(1); return 0; @@ -132,7 +126,6 @@ cleanup: Result miniSocExitDirect(void) { - //if (miniSocRefCount != 0) __builtin_trap(); Result ret = 0; u32 tmp; @@ -147,8 +140,17 @@ Result miniSocExitDirect(void) svcControlMemory(&tmp, socContextAddr, socContextAddr, socContextSize, MEMOP_FREE, MEMPERM_DONTCARE); if(ret == 0) { + if (exclusiveStateEntered) + { + //ndmuInit(); + ret = NDMU_UnlockState(); + if (R_SUCCEEDED(ret)) + ret = NDMU_LeaveExclusiveState(); + ndmuExit(); + exclusiveStateEntered = R_FAILED(ret); + } + miniSocEnabled = false; - srvExtAddToNdmuWorkaroundCount(-1); svcKernelSetState(0x10000, 0x10); } return ret; diff --git a/sysmodules/sm/source/common.h b/sysmodules/sm/source/common.h index c750ece..7ee7f6b 100644 --- a/sysmodules/sm/source/common.h +++ b/sysmodules/sm/source/common.h @@ -17,7 +17,6 @@ This is part of 3ds_sm, which is licensed under the MIT license (see LICENSE for extern u32 nbSection0Modules; extern Handle resumeGetServiceHandleOrPortRegisteredSemaphore; -extern u32 ndmuServicePid; struct SessionDataList; diff --git a/sysmodules/sm/source/notifications.c b/sysmodules/sm/source/notifications.c index ce8e015..18465a7 100644 --- a/sysmodules/sm/source/notifications.c +++ b/sysmodules/sm/source/notifications.c @@ -10,17 +10,11 @@ This is part of 3ds_sm, which is licensed under the MIT license (see LICENSE for #include -static atomic_int ndmuWorkaroundCount; - static bool isNotificationInhibited(const ProcessData *processData, u32 notificationId) { - u32 pid = processData->pid; + (void)processData; switch(notificationId) { - // Shell opened, shell closed - case 0x213: - case 0x214: - return pid == ndmuServicePid && atomic_load(&ndmuWorkaroundCount) > 0; default: return false; } @@ -207,10 +201,3 @@ Result PublishToAll(u32 notificationId) return 0; } - -Result AddToNdmuWorkaroundCount(s32 count) -{ - // Note: no check is made to (current value)+count - atomic_fetch_add(&ndmuWorkaroundCount, count); - return 0; -} diff --git a/sysmodules/sm/source/services.c b/sysmodules/sm/source/services.c index 67274b4..a81af7c 100644 --- a/sysmodules/sm/source/services.c +++ b/sysmodules/sm/source/services.c @@ -13,8 +13,6 @@ This is part of 3ds_sm, which is licensed under the MIT license (see LICENSE for ServiceInfo servicesInfo[0xA0] = { 0 }; u32 nbServices = 0; // including "ports" registered with getPort -u32 ndmuServicePid = 3; // use our PID as default. - static Result checkServiceName(const char *name, s32 nameSize) { if(nameSize <= 0 || nameSize > 8) @@ -98,9 +96,6 @@ static Result doRegisterServiceOrPort(u32 pid, Handle *serverPort, Handle client if(!isNamedPort) *serverPort = portServer; - if(R_SUCCEEDED(res) && strcmp(name, "ndm:u") == 0) - ndmuServicePid = pid; - return res; } diff --git a/sysmodules/sm/source/srv.c b/sysmodules/sm/source/srv.c index a27a6fa..5afb505 100644 --- a/sysmodules/sm/source/srv.c +++ b/sysmodules/sm/source/srv.c @@ -167,14 +167,6 @@ Result srvHandleCommands(SessionData *sessionData) break; } - case 0x1000: // Custom command: AddToNdmuWorkaroundCount - { - res = AddToNdmuWorkaroundCount((s32)cmdbuf[1]); - cmdbuf[0] = IPC_MakeHeader(0x1000, 1, 0);; - cmdbuf[1] = (u32)res; - break; - } - default: goto invalid_command; break;