rosalina: prevent disconnect when shell is closed

Fuck ndm, fuck StreetPass
This commit is contained in:
TuxSH 2020-07-11 21:39:36 +01:00
parent dc67d438dc
commit 4c01bb453c
6 changed files with 30 additions and 3 deletions

View File

@ -17,6 +17,8 @@
#define _REENT_ONLY #define _REENT_ONLY
#include <errno.h> #include <errno.h>
#define ROSALINA_PREVENT_DISCONNECT (*(volatile bool*)0x1FF81108)
#define SYNC_ERROR ENODEV #define SYNC_ERROR ENODEV
extern bool miniSocEnabled; extern bool miniSocEnabled;

View File

@ -140,7 +140,7 @@ static void handleSleepNotification(u32 notificationId)
switch (notificationId) switch (notificationId)
{ {
case PTMNOTIFID_SLEEP_REQUESTED: case PTMNOTIFID_SLEEP_REQUESTED:
PTMSYSM_ReplyToSleepQuery(miniSocEnabled); // deny sleep request if we have network stuff running PTMSYSM_ReplyToSleepQuery(ROSALINA_PREVENT_DISCONNECT); // deny sleep request if we have network stuff running
break; break;
case PTMNOTIFID_GOING_TO_SLEEP: case PTMNOTIFID_GOING_TO_SLEEP:
case PTMNOTIFID_SLEEP_ALLOWED: case PTMNOTIFID_SLEEP_ALLOWED:

View File

@ -91,6 +91,7 @@ Result miniSocInit(void)
svcKernelSetState(0x10000, 2); svcKernelSetState(0x10000, 2);
miniSocEnabled = true; miniSocEnabled = true;
ROSALINA_PREVENT_DISCONNECT = true;
return 0; return 0;
cleanup: cleanup:
@ -134,6 +135,7 @@ Result miniSocExitDirect(void)
{ {
svcKernelSetState(0x10000, 2); svcKernelSetState(0x10000, 2);
miniSocEnabled = false; miniSocEnabled = false;
ROSALINA_PREVENT_DISCONNECT = false;
} }
return ret; return ret;
} }

View File

@ -17,6 +17,7 @@ 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;

View File

@ -8,6 +8,23 @@ This is part of 3ds_sm, which is licensed under the MIT license (see LICENSE for
#include "notifications.h" #include "notifications.h"
#include "processes.h" #include "processes.h"
// 0 by default
#define ROSALINA_PREVENT_DISCONNECT (*(volatile bool*)0x1FF81108)
static bool isNotificationInhibited(const ProcessData *processData, u32 notificationId)
{
u32 pid = processData->pid;
switch(notificationId)
{
// Shell opened, shell closed
case 0x213:
case 0x214:
return pid == ndmuServicePid && ROSALINA_PREVENT_DISCONNECT;
default:
return false;
}
}
static bool doPublishNotification(ProcessData *processData, u32 notificationId, u32 flags) static bool doPublishNotification(ProcessData *processData, u32 notificationId, u32 flags)
{ {
if((flags & 1) && processData->nbPendingNotifications != 0) // only send if not already pending if((flags & 1) && processData->nbPendingNotifications != 0) // only send if not already pending
@ -118,7 +135,7 @@ Result PublishToSubscriber(u32 notificationId, u32 flags)
{ {
for(ProcessData *node = processDataInUseList.first; node != NULL; node = node->next) for(ProcessData *node = processDataInUseList.first; node != NULL; node = node->next)
{ {
if(!node->notificationEnabled) if(!node->notificationEnabled || isNotificationInhibited(node, notificationId))
continue; continue;
u16 i; u16 i;
@ -138,7 +155,7 @@ Result PublishAndGetSubscriber(u32 *pidCount, u32 *pidList, u32 notificationId,
u32 nb = 0; u32 nb = 0;
for(ProcessData *node = processDataInUseList.first; node != NULL; node = node->next) for(ProcessData *node = processDataInUseList.first; node != NULL; node = node->next)
{ {
if(!node->notificationEnabled) if(!node->notificationEnabled || isNotificationInhibited(node, notificationId))
continue; continue;
u16 i; u16 i;

View File

@ -13,6 +13,8 @@ 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)
@ -96,6 +98,9 @@ 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;
} }