From 11f820efa75ca2093635aa94f3111375d644a976 Mon Sep 17 00:00:00 2001 From: TuxSH Date: Mon, 15 Jan 2018 02:52:50 +0100 Subject: [PATCH] Check service existence before GetServiceHandle --- sysmodules/rosalina/source/menu.c | 5 ++++- sysmodules/rosalina/source/menus/debugger.c | 10 ++++------ sysmodules/rosalina/source/minisoc.c | 15 +++++++++++++-- 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/sysmodules/rosalina/source/menu.c b/sysmodules/rosalina/source/menu.c index f396460..d60af63 100644 --- a/sysmodules/rosalina/source/menu.c +++ b/sysmodules/rosalina/source/menu.c @@ -193,13 +193,16 @@ static void menuDraw(Menu *menu, u32 selected) s64 out; u32 version, commitHash; bool isRelease; + bool isMcuHwcRegistered; - if(R_SUCCEEDED(mcuHwcInit())) + if(R_SUCCEEDED(srvIsServiceRegistered(&isMcuHwcRegistered, "mcu::HWC")) && isMcuHwcRegistered && R_SUCCEEDED(mcuHwcInit())) { if(R_FAILED(MCUHWC_GetBatteryLevel(&batteryLevel))) batteryLevel = 255; mcuHwcExit(); } + else + batteryLevel = 255; svcGetSystemInfo(&out, 0x10000, 0); version = (u32)out; diff --git a/sysmodules/rosalina/source/menus/debugger.c b/sysmodules/rosalina/source/menus/debugger.c index 3b8632c..82b02bd 100644 --- a/sysmodules/rosalina/source/menus/debugger.c +++ b/sysmodules/rosalina/source/menus/debugger.c @@ -69,12 +69,10 @@ void DebuggerMenu_EnableDebugger(void) bool done = false, alreadyEnabled = gdbServer.super.running; Result res = 0; char buf[65]; - bool cantStart; - Handle dummy; + bool isSocURegistered; - res = OpenProcessByName("socket", &dummy); - cantStart = R_FAILED(res); - svcCloseHandle(dummy); + res = srvIsServiceRegistered(&isSocURegistered, "soc:U"); + isSocURegistered = R_SUCCEEDED(res) && isSocURegistered; Draw_Lock(); Draw_ClearFramebuffer(); @@ -88,7 +86,7 @@ void DebuggerMenu_EnableDebugger(void) if(alreadyEnabled) Draw_DrawString(10, 30, COLOR_WHITE, "Already enabled!"); - else if(cantStart) + else if(!isSocURegistered) Draw_DrawString(10, 30, COLOR_WHITE, "Can't start the debugger before the system has fi-\nnished loading."); else { diff --git a/sysmodules/rosalina/source/minisoc.c b/sysmodules/rosalina/source/minisoc.c index 76c2d22..e894ed6 100644 --- a/sysmodules/rosalina/source/minisoc.c +++ b/sysmodules/rosalina/source/minisoc.c @@ -80,6 +80,18 @@ Result miniSocInit() u32 tmp = 0; Result ret = 0; + bool isSocURegistered; + + ret = srvIsServiceRegistered(&isSocURegistered, "soc:U"); + if(ret != 0) goto cleanup; + if(!isSocURegistered) + { + ret = -1; + goto cleanup; + } + + ret = srvGetServiceHandle(&SOCU_handle, "soc:U"); + if(ret != 0) goto cleanup; ret = svcControlMemory(&tmp, socContextAddr, 0, socContextSize, MEMOP_ALLOC, MEMPERM_READ | MEMPERM_WRITE); if(ret != 0) goto cleanup; @@ -89,8 +101,7 @@ Result miniSocInit() ret = svcCreateMemoryBlock(&socMemhandle, (u32)socContextAddr, socContextSize, 0, 3); if(ret != 0) goto cleanup; - ret = srvGetServiceHandle(&SOCU_handle, "soc:U"); - if(ret != 0) goto cleanup; + ret = SOCU_Initialize(socMemhandle, socContextSize); if(ret != 0) goto cleanup;