add nifmSetServiceType to set which nifm service to init

This commit is contained in:
exelix 2019-03-15 21:07:47 +01:00
parent 19dc760d52
commit a6c409ac69
2 changed files with 30 additions and 20 deletions

View File

@ -9,6 +9,19 @@
#include "../kernel/ipc.h"
#include "../services/sm.h"
typedef enum {
NifmServiceType_NotInitialized = 0,
NifmServiceType_User = 1,
NifmServiceType_System = 2,
NifmServiceType_Admin = 3,
} NifmServiceType;
/**
* @brief Sets the \ref NifmServiceType for initialization. Call this function before \ref nifmInitialize.
* @note By default nifm:u will be used.
*/
void nifmSetServiceType(NifmServiceType serviceType);
Result nifmInitialize(void);
void nifmExit(void);

View File

@ -9,13 +9,6 @@
#include "arm/atomics.h"
#include "runtime/hosversion.h"
typedef enum {
NifmServiceType_NotInitialized = 0,
NifmServiceType_User = 1,
NifmServiceType_System = 2,
NifmServiceType_Admin = 3,
} NifmServiceType;
static NifmServiceType g_nifmServiceType = NifmServiceType_NotInitialized;
static Service g_nifmSrv;
@ -25,25 +18,29 @@ static u64 g_refCnt;
static Result _nifmCreateGeneralService(Service* out, u64 in);
static Result _nifmCreateGeneralServiceOld(Service* out);
void nifmSetServiceType(NifmServiceType serviceType) {
g_nifmServiceType = serviceType;
}
Result nifmInitialize(void) {
atomicIncrement64(&g_refCnt);
if (serviceIsActive(&g_nifmSrv))
return 0;
Result rc = smGetService(&g_nifmSrv, "nifm:a");
g_nifmServiceType = NifmServiceType_Admin;
if (R_FAILED(rc))
{
rc = smGetService(&g_nifmSrv, "nifm:s");
g_nifmServiceType = NifmServiceType_System;
}
if (R_FAILED(rc))
{
rc = smGetService(&g_nifmSrv, "nifm:u");
Result rc = 0;
switch (g_nifmServiceType) {
case NifmServiceType_NotInitialized:
case NifmServiceType_User:
g_nifmServiceType = NifmServiceType_User;
rc = smGetService(&g_nifmSrv, "nifm:u");
break;
case NifmServiceType_System:
rc = smGetService(&g_nifmSrv, "nifm:s");
break;
case NifmServiceType_Admin:
rc = smGetService(&g_nifmSrv, "nifm:a");
break;
}
if (R_SUCCEEDED(rc)) rc = serviceConvertToDomain(&g_nifmSrv);