From ae77cbea972a2360433bb0338e7997c7459f767c Mon Sep 17 00:00:00 2001 From: fincs Date: Sat, 10 Nov 2018 16:34:51 +0100 Subject: [PATCH] gfx/hid/irs/nv/vi: changes related to sysmodule users, see details: - Removed hard dependency on applet - Allow appletGetAppletResourceUserId to fail (using default zero in that case) - nvInitialize uses nvdrv:s for AppletType_None - gfx now uses weak global __nx_gfx_vi_service_type for the ViServiceType passed to viInitialize --- nx/source/display/gfx.c | 4 +++- nx/source/services/hid.c | 11 ++--------- nx/source/services/irs.c | 11 +++-------- nx/source/services/nv.c | 10 ++++------ nx/source/services/vi.c | 5 ----- 5 files changed, 12 insertions(+), 29 deletions(-) diff --git a/nx/source/display/gfx.c b/nx/source/display/gfx.c index 34a9cc2b..9e6a4fd7 100644 --- a/nx/source/display/gfx.c +++ b/nx/source/display/gfx.c @@ -12,6 +12,8 @@ #include "display/gfx.h" #include "nvidia/map.h" +__attribute__((weak)) ViServiceType __nx_gfx_vi_service_type = ViServiceType_Default; + static bool g_gfxInitialized = 0; static ViDisplay g_gfxDisplay; static Event g_gfxDisplayVsyncEvent; @@ -231,7 +233,7 @@ Result gfxInitDefault(void) { return rc; } - rc = viInitialize(ViServiceType_Default); + rc = viInitialize(__nx_gfx_vi_service_type); if (R_SUCCEEDED(rc)) rc = viOpenDefaultDisplay(&g_gfxDisplay); diff --git a/nx/source/services/hid.c b/nx/source/services/hid.c index f674f5a4..2e688937 100644 --- a/nx/source/services/hid.c +++ b/nx/source/services/hid.c @@ -61,17 +61,12 @@ Result hidInitialize(void) if (serviceIsActive(&g_hidSrv)) return 0; - if (R_FAILED(appletInitialize())) - return MAKERESULT(Module_Libnx, LibnxError_AppletFailedToInitialize); - Result rc; Handle sharedmem_handle; - u64 AppletResourceUserId; - rc = appletGetAppletResourceUserId(&AppletResourceUserId); // If this failed (for example because we're a sysmodule) AppletResourceUserId stays zero - if (R_FAILED(rc)) - AppletResourceUserId = 0; + u64 AppletResourceUserId = 0; + appletGetAppletResourceUserId(&AppletResourceUserId); rc = smGetService(&g_hidSrv, "hid"); if (R_FAILED(rc)) @@ -124,8 +119,6 @@ void hidExit(void) serviceClose(&g_hidIAppletResource); serviceClose(&g_hidSrv); shmemClose(&g_hidSharedmem); - - appletExit(); } } diff --git a/nx/source/services/irs.c b/nx/source/services/irs.c index a2101c25..405f5176 100644 --- a/nx/source/services/irs.c +++ b/nx/source/services/irs.c @@ -32,19 +32,15 @@ Result irsInitialize(void) if (serviceIsActive(&g_irsSrv)) return 0; - if (R_FAILED(appletInitialize())) - return MAKERESULT(Module_Libnx, LibnxError_AppletFailedToInitialize); - Result rc; Handle sharedmem_handle; - u64 AppletResourceUserId=0; g_irsSensorActivated = 0; memset(g_irsCameras, 0, sizeof(g_irsCameras)); - rc = appletGetAppletResourceUserId(&AppletResourceUserId); - if (R_FAILED(rc)) - return rc; + // If this failed (for example because we're a sysmodule) AppletResourceUserId stays zero + u64 AppletResourceUserId=0; + appletGetAppletResourceUserId(&AppletResourceUserId); rc = smGetService(&g_irsSrv, "irs"); if (R_FAILED(rc)) @@ -83,7 +79,6 @@ void irsExit(void) serviceClose(&g_irsSrv); shmemClose(&g_irsSharedmem); - appletExit(); } } diff --git a/nx/source/services/nv.c b/nx/source/services/nv.c index 610fb8ce..fcf5cd09 100644 --- a/nx/source/services/nv.c +++ b/nx/source/services/nv.c @@ -28,15 +28,14 @@ Result nvInitialize(void) if (serviceIsActive(&g_nvSrv)) return 0; - if (R_FAILED(appletInitialize())) { - atomicDecrement64(&g_refCnt); - return MAKERESULT(Module_Libnx, LibnxError_AppletFailedToInitialize); - } - Result rc = 0; u64 AppletResourceUserId = 0; switch (appletGetAppletType()) { + case AppletType_None: + rc = smGetService(&g_nvSrv, "nvdrv:s"); + break; + case AppletType_Default: case AppletType_Application: case AppletType_SystemApplication: @@ -91,7 +90,6 @@ void nvExit(void) serviceClose(&g_nvSrvClone); serviceClose(&g_nvSrv); tmemClose(&g_nvTransfermem); - appletExit(); } } diff --git a/nx/source/services/vi.c b/nx/source/services/vi.c index a24bc85d..8ddb7c33 100644 --- a/nx/source/services/vi.c +++ b/nx/source/services/vi.c @@ -26,9 +26,6 @@ Result viInitialize(ViServiceType service_type) if (serviceIsActive(&g_viIApplicationDisplayService)) return MAKERESULT(Module_Libnx, LibnxError_AlreadyInitialized); - if (R_FAILED(appletInitialize())) - return MAKERESULT(Module_Libnx, LibnxError_AppletFailedToInitialize); - Service root_srv; Result rc = 0; @@ -88,8 +85,6 @@ void viExit(void) serviceClose(&g_viIHOSBinderDriverRelay); serviceClose(&g_viIApplicationDisplayService); g_viServiceType = ViServiceType_Default; - - appletExit(); } Service* viGetSession_IApplicationDisplayService(void)