From 4f5df9cf569b00c03cca0fef691f43b8708811d5 Mon Sep 17 00:00:00 2001 From: Michael Scire Date: Fri, 2 May 2025 21:04:56 -0700 Subject: [PATCH] ldr/fsldr: update for 20.0.0 --- nx/include/switch/services/fsldr.h | 3 +- nx/include/switch/services/ldr.h | 9 ++++- nx/source/services/fsldr.c | 25 ++++++++++-- nx/source/services/ldr.c | 63 ++++++++++++++++++++++-------- 4 files changed, 77 insertions(+), 23 deletions(-) diff --git a/nx/include/switch/services/fsldr.h b/nx/include/switch/services/fsldr.h index 2016aa07..d2406ed6 100644 --- a/nx/include/switch/services/fsldr.h +++ b/nx/include/switch/services/fsldr.h @@ -9,6 +9,7 @@ #include "../sf/service.h" #include "../services/fs.h" #include "../crypto/sha256.h" +#include "../services/ncm_types.h" typedef struct { u8 signature[0x100]; @@ -26,5 +27,5 @@ void fsldrExit(void); /// Gets the Service object for the actual fsp-ldr service session. Service* fsldrGetServiceSession(void); -Result fsldrOpenCodeFileSystem(FsCodeInfo* out_code_info, u64 tid, const char *path, FsContentAttributes attr, FsFileSystem* out); +Result fsldrOpenCodeFileSystem(FsCodeInfo* out_code_info, u64 tid, NcmStorageId storage_id, const char *path, FsContentAttributes attr, FsFileSystem* out); Result fsldrIsArchivedProgram(u64 pid, bool *out); diff --git a/nx/include/switch/services/ldr.h b/nx/include/switch/services/ldr.h index ac46c1fe..5f784fe5 100644 --- a/nx/include/switch/services/ldr.h +++ b/nx/include/switch/services/ldr.h @@ -42,6 +42,11 @@ typedef struct { u64 size; } LoaderModuleInfo; +typedef struct { + u8 platform; ///< NcmContentMetaPlatform + u8 content_attributes; ///< FsContentAttributes +} LoaderProgramAttributes; + /// Initialize ldr:shel. Result ldrShellInitialize(void); @@ -76,8 +81,8 @@ Result ldrDmntSetProgramArguments(u64 program_id, const void *args, size_t args_ 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); ///< [19.0.0+/Atmosphere] +Result ldrPmCreateProcess(u64 pin_id, u32 flags, Handle reslimit_h, const LoaderProgramAttributes *attrs, Handle *out_process_h); +Result ldrPmGetProgramInfo(const NcmProgramLocation *loc, const LoaderProgramAttributes *attrs, 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); diff --git a/nx/source/services/fsldr.c b/nx/source/services/fsldr.c index 08ea01cd..c5965f91 100644 --- a/nx/source/services/fsldr.c +++ b/nx/source/services/fsldr.c @@ -32,13 +32,32 @@ Service* fsldrGetServiceSession(void) { return &g_fsldrSrv; } -Result fsldrOpenCodeFileSystem(FsCodeInfo* out_code_info, u64 tid, const char *path, FsContentAttributes attr, FsFileSystem* out) { +Result fsldrOpenCodeFileSystem(FsCodeInfo* out_code_info, u64 tid, NcmStorageId storage_id, const char *path, FsContentAttributes attr, FsFileSystem* out) { memset(out_code_info, 0, sizeof(*out_code_info)); char send_path[FS_MAX_PATH]={0}; - strncpy(send_path, path, FS_MAX_PATH-1); + if (hosversionBefore(20,0,0)) + strncpy(send_path, path, FS_MAX_PATH-1); - if (hosversionAtLeast(17,0,0)) { + if (hosversionAtLeast(20,0,0)) { + const struct { + u8 attr; + u8 storage_id; + u64 tid; + } in = { attr, storage_id, tid }; + + serviceAssumeDomain(&g_fsldrSrv); + return serviceDispatchIn(&g_fsldrSrv, 0, in, + .buffer_attrs = { + SfBufferAttr_HipcMapAlias | SfBufferAttr_Out, + }, + .buffers = { + { out_code_info, sizeof(*out_code_info) }, + }, + .out_num_objects = 1, + .out_objects = &out->s, + ); + } else if (hosversionAtLeast(17,0,0)) { const struct { u8 attr; u64 tid; diff --git a/nx/source/services/ldr.c b/nx/source/services/ldr.c index bc54e6a4..fd4ea29b 100644 --- a/nx/source/services/ldr.c +++ b/nx/source/services/ldr.c @@ -79,28 +79,57 @@ Result ldrDmntGetProcessModuleInfo(u64 pid, LoaderModuleInfo *out_module_infos, ); } -Result ldrPmCreateProcess(u64 pin_id, u32 flags, Handle reslimit_h, Handle *out_process_h) { - const struct { - u32 flags; - u32 pad; - u64 pin_id; - } in = { flags, 0, pin_id }; - return serviceDispatchIn(&g_ldrPmSrv, 0, in, - .in_num_handles = 1, - .in_handles = { reslimit_h }, - .out_handle_attrs = { SfOutHandleAttr_HipcMove }, - .out_handles = out_process_h, - ); +Result ldrPmCreateProcess(u64 pin_id, u32 flags, Handle reslimit_h, const LoaderProgramAttributes *attrs, Handle *out_process_h) { + if (hosversionIsAtmosphere() || hosversionAtLeast(20,0,0)) { + const struct { + LoaderProgramAttributes attr; + u16 pad; + u32 flags; + u64 pin_id; + } in = { *attrs, 0, flags, pin_id }; + return serviceDispatchIn(&g_ldrPmSrv, 0, in, + .in_num_handles = 1, + .in_handles = { reslimit_h }, + .out_handle_attrs = { SfOutHandleAttr_HipcMove }, + .out_handles = out_process_h, + ); + } else { + const struct { + u32 flags; + u32 pad; + u64 pin_id; + } in = { flags, 0, pin_id }; + return serviceDispatchIn(&g_ldrPmSrv, 0, in, + .in_num_handles = 1, + .in_handles = { reslimit_h }, + .out_handle_attrs = { SfOutHandleAttr_HipcMove }, + .out_handles = out_process_h, + ); + } } -Result ldrPmGetProgramInfo(const NcmProgramLocation *loc, LoaderProgramInfo *out_program_info) { +Result ldrPmGetProgramInfo(const NcmProgramLocation *loc, const LoaderProgramAttributes *attrs, 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) } }, - ); + if (hosversionIsAtmosphere() || hosversionAtLeast(20,0,0)) { + const struct { + LoaderProgramAttributes attr; + u16 pad1; + u32 pad2; + NcmProgramLocation loc; + } in = { *attrs, 0, 0, *loc }; + _Static_assert(sizeof(in) == 0x18); + return serviceDispatchIn(&g_ldrPmSrv, 1, in, + .buffer_attrs = { SfBufferAttr_Out | SfBufferAttr_HipcPointer | SfBufferAttr_FixedSize }, + .buffers = { { out_program_info, sizeof(*out_program_info) } }, + ); + } else { + 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) {