From 250a5777f7833a60da2434cab567bcf9263a1967 Mon Sep 17 00:00:00 2001 From: Michael Scire Date: Thu, 10 Oct 2024 03:00:32 -0700 Subject: [PATCH] ldr:pm: Update ProgramInfo --- nx/include/switch/services/ldr.h | 17 ++++++++++++++++- nx/source/services/ldr.c | 13 +++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/nx/include/switch/services/ldr.h b/nx/include/switch/services/ldr.h index acc753f1..ac46c1fe 100644 --- a/nx/include/switch/services/ldr.h +++ b/nx/include/switch/services/ldr.h @@ -20,6 +20,20 @@ typedef struct { u32 acid_fac_size; u32 aci0_fah_size; u8 ac_buffer[0x3E0]; +} LoaderProgramInfoV1; + +typedef struct { + u8 main_thread_priority; + u8 default_cpu_id; + u16 application_type; + u32 main_thread_stack_size; + u64 program_id; + u32 acid_sac_size; + u32 aci0_sac_size; + u32 acid_fac_size; + u32 aci0_fah_size; + u8 unused_20[0x10]; + u8 ac_buffer[0x3E0]; } LoaderProgramInfo; typedef struct { @@ -63,7 +77,8 @@ Result ldrDmntFlushArguments(void); Result ldrDmntGetProcessModuleInfo(u64 pid, LoaderModuleInfo *out_module_infos, size_t max_out_modules, s32 *num_out); Result ldrPmCreateProcess(u64 pin_id, u32 flags, Handle reslimit_h, Handle *out_process_h); -Result ldrPmGetProgramInfo(const NcmProgramLocation *loc, LoaderProgramInfo *out_program_info); +Result ldrPmGetProgramInfo(const NcmProgramLocation *loc, LoaderProgramInfo *out_program_info); ///< [19.0.0+/Atmosphere] +Result ldrPmGetProgramInfoV1(const NcmProgramLocation *loc, LoaderProgramInfoV1 *out_program_info); ///< [1.0.0-18.1.0/Non-Atmosphere] Result ldrPmPinProgram(const NcmProgramLocation *loc, u64 *out_pin_id); Result ldrPmUnpinProgram(u64 pin_id); Result ldrPmSetEnabledProgramVerification(bool enabled); ///< [10.0.0+] diff --git a/nx/source/services/ldr.c b/nx/source/services/ldr.c index 8271577d..bc54e6a4 100644 --- a/nx/source/services/ldr.c +++ b/nx/source/services/ldr.c @@ -94,6 +94,19 @@ Result ldrPmCreateProcess(u64 pin_id, u32 flags, Handle reslimit_h, Handle *out_ } Result ldrPmGetProgramInfo(const NcmProgramLocation *loc, LoaderProgramInfo *out_program_info) { + if (!hosversionIsAtmosphere() && hosversionBefore(19, 0, 0)) + return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); + + return serviceDispatchIn(&g_ldrPmSrv, 1, *loc, + .buffer_attrs = { SfBufferAttr_Out | SfBufferAttr_HipcPointer | SfBufferAttr_FixedSize }, + .buffers = { { out_program_info, sizeof(*out_program_info) } }, + ); +} + +Result ldrPmGetProgramInfoV1(const NcmProgramLocation *loc, LoaderProgramInfoV1 *out_program_info) { + if (hosversionIsAtmosphere() || hosversionAtLeast(19,0,0)) + return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); + return serviceDispatchIn(&g_ldrPmSrv, 1, *loc, .buffer_attrs = { SfBufferAttr_Out | SfBufferAttr_HipcPointer | SfBufferAttr_FixedSize }, .buffers = { { out_program_info, sizeof(*out_program_info) } },