1
0
Fork 0
mirror of https://github.com/DarkMatterCore/nxdumptool.git synced 2024-11-26 20:22:17 +00:00

services: completely ditch smRegisterService() and just use the AtmosphereHasService SM API extension.

This extension was already being used - however, smRegisterService() was also being used as a fallback method.

More than a year and a half has already passed since this feature was introduced, and both SX OS and ReiNX apparently support it now, so it's a justified change.
This commit is contained in:
Pablo Curiel 2021-02-24 23:36:53 -04:00
parent a90d8f2074
commit 5eb96cbece
4 changed files with 20 additions and 40 deletions

View file

@ -97,7 +97,7 @@ static bool memRetrieveProgramMemory(MemoryLocation *location, bool is_segment)
if (is_segment && location->program_id == FS_SYSMODULE_TID) if (is_segment && location->program_id == FS_SYSMODULE_TID)
{ {
/* If dealing with FS, locate the "real" .text segment, since Atmosphere emuMMC has two. */ /* If dealing with FS, locate the "real" .text segment, since Atmosphère emuMMC has two. */
do { do {
rc = svcQueryDebugProcessMemory(&mem_info, &page_info, debug_handle, addr); rc = svcQueryDebugProcessMemory(&mem_info, &page_info, debug_handle, addr);
if (R_FAILED(rc)) if (R_FAILED(rc))

View file

@ -38,7 +38,7 @@ typedef struct {
/* Function prototypes. */ /* Function prototypes. */
static Result smHasService(bool *out_has_service, SmServiceName name); static Result smAtmosphereHasService(bool *out, SmServiceName name);
static Result servicesNifmUserInitialize(void); static Result servicesNifmUserInitialize(void);
static bool servicesClkGetServiceType(void *arg); static bool servicesClkGetServiceType(void *arg);
@ -190,27 +190,30 @@ void servicesChangeHardwareClockRates(u32 cpu_rate, u32 mem_rate)
mutexUnlock(&g_servicesMutex); mutexUnlock(&g_servicesMutex);
} }
Result servicesAtmosphereHasService(bool *out_has_service, const char *name) Result servicesHasService(bool *out, const char *name)
{ {
if (!out_has_service || !name || !*name) if (!out || !name || !*name)
{ {
LOGFILE("Invalid parameters!"); LOGFILE("Invalid parameters!");
return MAKERESULT(Module_Libnx, LibnxError_IoError); return MAKERESULT(Module_Libnx, LibnxError_IoError);
} }
*out = false;
Result rc = 0;
SmServiceName service_name = smEncodeName(name); SmServiceName service_name = smEncodeName(name);
Result rc = smHasService(out_has_service, service_name); rc = smAtmosphereHasService(out, service_name);
if (R_FAILED(rc)) LOGFILE("smHasService failed for \"%s\"! (0x%08X).", name, rc); if (R_FAILED(rc)) LOGFILE("smAtmosphereHasService failed for \"%s\"! (0x%08X).", name, rc);
return rc; return rc;
} }
static Result smHasService(bool *out_has_service, SmServiceName name) /* SM API extension available in Atmosphère and Atmosphère-based CFWs. */
static Result smAtmosphereHasService(bool *out, SmServiceName name)
{ {
u8 tmp = 0; u8 tmp = 0;
Result rc = serviceDispatchInOut(smGetServiceSession(), 65100, name, tmp); Result rc = serviceDispatchInOut(smGetServiceSession(), 65100, name, tmp);
if (R_SUCCEEDED(rc) && out_has_service) *out_has_service = (tmp & 1); if (R_SUCCEEDED(rc) && out) *out = tmp;
return rc; return rc;
} }

View file

@ -45,8 +45,8 @@ bool servicesCheckInitializedServiceByName(const char *name);
/// Changes CPU/MEM clock rates at runtime. /// Changes CPU/MEM clock rates at runtime.
void servicesChangeHardwareClockRates(u32 cpu_rate, u32 mem_rate); void servicesChangeHardwareClockRates(u32 cpu_rate, u32 mem_rate);
/// Wrapper for the Atmosphere-only SM API "HasService" extension. /// Wrapper for the "AtmosphereHasService" SM API extension from Atmosphère and Atmosphère-based CFWs.
/// Perfectly safe under development units. Not available in older Atmosphere releases. /// Perfectly safe under development units. Not available in older Atmosphère releases.
Result servicesAtmosphereHasService(bool *out_has_service, const char *name); Result servicesHasService(bool *out, const char *name);
#endif /* __SERVICES_H__ */ #endif /* __SERVICES_H__ */

View file

@ -66,7 +66,7 @@ static const char *g_illegalFileSystemChars = "\\/:*?\"<>|^";
/* Function prototypes. */ /* Function prototypes. */
static bool _utilsGetCustomFirmwareType(void); static void _utilsGetCustomFirmwareType(void);
static bool _utilsIsDevelopmentUnit(void); static bool _utilsIsDevelopmentUnit(void);
@ -98,7 +98,7 @@ bool utilsInitializeResources(void)
/* Retrieve custom firmware type. */ /* Retrieve custom firmware type. */
if (!_utilsGetCustomFirmwareType()) goto end; if (!_utilsGetCustomFirmwareType()) goto end;
LOGFILE("Detected %s CFW.", (g_customFirmwareType == UtilsCustomFirmwareType_Atmosphere ? "Atmosphere" : (g_customFirmwareType == UtilsCustomFirmwareType_SXOS ? "SX OS" : "ReiNX"))); LOGFILE("Detected %s CFW.", (g_customFirmwareType == UtilsCustomFirmwareType_Atmosphere ? "Atmosphère" : (g_customFirmwareType == UtilsCustomFirmwareType_SXOS ? "SX OS" : "ReiNX")));
/* Initialize needed services. */ /* Initialize needed services. */
if (!servicesInitialize()) if (!servicesInitialize())
@ -751,37 +751,14 @@ void utilsOverclockSystem(bool overclock)
servicesChangeHardwareClockRates(cpuClkRate, memClkRate); servicesChangeHardwareClockRates(cpuClkRate, memClkRate);
} }
static bool _utilsGetCustomFirmwareType(void) static void _utilsGetCustomFirmwareType(void)
{ {
bool has_service = false, tx_srv = false, rnx_srv = false; bool has_srv = false, tx_srv = false, rnx_srv = false;
/* First, check if we're running under Atmosphere or an Atmosphere-based CFW by using a SM API extension that's only provided by it. */ tx_srv = (R_SUCCEEDED(servicesHasService(&has_srv, "tx")) && has_srv);
if (R_SUCCEEDED(servicesAtmosphereHasService(&has_service, "ncm"))) rnx_srv = (R_SUCCEEDED(servicesHasService(&has_srv, "rnx")) && has_srv);
{
/* We're running under Atmosphere or an Atmosphere-based CFW. Time to check which one is it. */
tx_srv = (R_SUCCEEDED(servicesAtmosphereHasService(&has_service, "tx")) && has_service);
rnx_srv = (R_SUCCEEDED(servicesAtmosphereHasService(&has_service, "rnx")) && has_service);
} else {
/* Odds are we're not running under Atmosphere, or maybe we're running under an old Atmosphere version without SM API extensions. */
/* We'll use the smRegisterService() trick to check for running services. */
/* But first, we need to re-initialize SM in order to avoid 0xF601 (port remote dead) errors. */
smExit();
Result rc = smInitialize();
if (R_FAILED(rc))
{
LOGFILE("smInitialize failed! (0x%08X).", rc);
return false;
}
tx_srv = servicesCheckRunningServiceByName("tx");
rnx_srv = servicesCheckRunningServiceByName("rnx");
}
/* Finally, determine the CFW type. */
g_customFirmwareType = (rnx_srv ? UtilsCustomFirmwareType_ReiNX : (tx_srv ? UtilsCustomFirmwareType_SXOS : UtilsCustomFirmwareType_Atmosphere)); g_customFirmwareType = (rnx_srv ? UtilsCustomFirmwareType_ReiNX : (tx_srv ? UtilsCustomFirmwareType_SXOS : UtilsCustomFirmwareType_Atmosphere));
return true;
} }
static bool _utilsIsDevelopmentUnit(void) static bool _utilsIsDevelopmentUnit(void)