This repository has been archived on 2022-05-31. You can view files and clone it, but cannot push or open issues or pull requests.
Luma3DS-3GX/sysmodules/sm/source/processes.c

76 lines
2.0 KiB
C
Raw Normal View History

2017-11-02 15:11:55 +01:00
/*
processes.c
(c) TuxSH, 2017
This is part of 3ds_sm, which is licensed under the MIT license (see LICENSE for details).
*/
#include "list.h"
#include "processes.h"
#include "services.h"
ProcessDataList processDataInUseList = { NULL, NULL }, freeProcessDataList = { NULL, NULL };
ProcessData *findProcessData(u32 pid)
{
for(ProcessData *node = processDataInUseList.first; node != NULL; node = node->next)
{
if(node->pid == pid)
return node;
}
return NULL;
}
ProcessData *doRegisterProcess(u32 pid, char (*serviceAccessList)[8], u32 serviceAccessListSize)
{
(void)serviceAccessList; // Service access list checks removed for Luma3DS, see original 3ds_sm for implementation details.
(void)serviceAccessListSize;
2017-11-02 15:11:55 +01:00
ProcessData *processData = (ProcessData *)allocateNode(&processDataInUseList, &freeProcessDataList, sizeof(ProcessData), false);
assertSuccess(svcCreateSemaphore(&processData->notificationSemaphore, 0, 0x10));
processData->pid = pid;
return processData;
}
Result RegisterProcess(u32 pid, char (*serviceAccessList)[8], u32 serviceAccessListSize)
{
serviceAccessListSize = serviceAccessListSize - (serviceAccessListSize % 8);
if(findProcessData(pid) != NULL)
return 0xD9006403;
else if(serviceAccessListSize > 8 * (IS_PRE_93 ? 32 : 34))
return 0xD9006405;
else
{
doRegisterProcess(pid, serviceAccessList, serviceAccessListSize);
return 0;
}
}
Result UnregisterProcess(u32 pid)
{
ProcessData *processData = findProcessData(pid);
if(processData == NULL)
return 0xD8806404;
svcCloseHandle(processData->notificationSemaphore);
// Unregister the services registered by the process
u32 i = 0;
while(i < nbServices)
2017-11-02 15:11:55 +01:00
{
if(servicesInfo[i].pid == pid)
{
svcCloseHandle(servicesInfo[i].clientPort);
servicesInfo[i] = servicesInfo[--nbServices];
}
else
++i;
2017-11-02 15:11:55 +01:00
}
moveNode(processData, &freeProcessDataList, false);
return 0;
}