From 37a971a70668c581defc997727367e32b20be44c Mon Sep 17 00:00:00 2001 From: Michael Scire Date: Thu, 1 May 2025 20:41:17 -0700 Subject: [PATCH] ldr/pm: update for 20.0.0 abi changes --- .../impl/ldr_process_manager_interface.hpp | 18 +-- .../include/stratosphere/ldr/ldr_pm_api.hpp | 6 +- .../include/stratosphere/ldr/ldr_types.hpp | 7 ++ .../source/ldr/ldr_ams.os.horizon.c | 10 +- .../source/ldr/ldr_ams.os.horizon.h | 2 +- .../source/ldr/ldr_pm_api.os.horizon.cpp | 13 +- .../vapours/results/loader_results.hpp | 26 ++-- .../loader/source/ldr_content_management.cpp | 26 ++-- .../loader/source/ldr_content_management.hpp | 10 +- .../loader/source/ldr_loader_service.cpp | 114 +++++++++--------- .../loader/source/ldr_loader_service.hpp | 16 +-- .../loader/source/ldr_process_creation.cpp | 12 +- .../loader/source/ldr_process_creation.hpp | 4 +- .../pm/source/impl/pm_process_attributes.hpp | 35 ++++++ .../pm/source/impl/pm_process_info.cpp | 6 +- .../pm/source/impl/pm_process_info.hpp | 10 +- .../pm/source/impl/pm_process_manager.cpp | 12 +- 17 files changed, 186 insertions(+), 141 deletions(-) create mode 100644 stratosphere/pm/source/impl/pm_process_attributes.hpp diff --git a/libraries/libstratosphere/include/stratosphere/ldr/impl/ldr_process_manager_interface.hpp b/libraries/libstratosphere/include/stratosphere/ldr/impl/ldr_process_manager_interface.hpp index 651b25bff..39c0bc3da 100644 --- a/libraries/libstratosphere/include/stratosphere/ldr/impl/ldr_process_manager_interface.hpp +++ b/libraries/libstratosphere/include/stratosphere/ldr/impl/ldr_process_manager_interface.hpp @@ -19,14 +19,14 @@ #include #include -#define AMS_LDR_I_PROCESS_MANAGER_INTERFACE_INTERFACE_INFO(C, H) \ - AMS_SF_METHOD_INFO(C, H, 0, Result, CreateProcess, (sf::OutMoveHandle proc_h, ldr::PinId id, u32 flags, sf::CopyHandle &&reslimit_h), (proc_h, id, flags, std::move(reslimit_h))) \ - AMS_SF_METHOD_INFO(C, H, 1, Result, GetProgramInfo, (sf::Out out_program_info, const ncm::ProgramLocation &loc), (out_program_info, loc)) \ - AMS_SF_METHOD_INFO(C, H, 2, Result, PinProgram, (sf::Out out_id, const ncm::ProgramLocation &loc), (out_id, loc)) \ - AMS_SF_METHOD_INFO(C, H, 3, Result, UnpinProgram, (ldr::PinId id), (id)) \ - AMS_SF_METHOD_INFO(C, H, 4, Result, SetEnabledProgramVerification, (bool enabled), (enabled), hos::Version_10_0_0) \ - AMS_SF_METHOD_INFO(C, H, 65000, void, AtmosphereHasLaunchedBootProgram, (sf::Out out, ncm::ProgramId program_id), (out, program_id)) \ - AMS_SF_METHOD_INFO(C, H, 65001, Result, AtmosphereGetProgramInfo, (sf::Out out_program_info, sf::Out out_status, const ncm::ProgramLocation &loc), (out_program_info, out_status, loc)) \ - AMS_SF_METHOD_INFO(C, H, 65002, Result, AtmospherePinProgram, (sf::Out out_id, const ncm::ProgramLocation &loc, const cfg::OverrideStatus &override_status), (out_id, loc, override_status)) +#define AMS_LDR_I_PROCESS_MANAGER_INTERFACE_INTERFACE_INFO(C, H) \ + AMS_SF_METHOD_INFO(C, H, 0, Result, CreateProcess, (sf::OutMoveHandle proc_h, ldr::PinId id, u32 flags, sf::CopyHandle &&reslimit_h, const ldr::ProgramAttributes &attrs), (proc_h, id, flags, std::move(reslimit_h), attrs)) \ + AMS_SF_METHOD_INFO(C, H, 1, Result, GetProgramInfo, (sf::Out out_program_info, const ncm::ProgramLocation &loc, const ldr::ProgramAttributes &attrs), (out_program_info, loc, attrs)) \ + AMS_SF_METHOD_INFO(C, H, 2, Result, PinProgram, (sf::Out out_id, const ncm::ProgramLocation &loc), (out_id, loc)) \ + AMS_SF_METHOD_INFO(C, H, 3, Result, UnpinProgram, (ldr::PinId id), (id)) \ + AMS_SF_METHOD_INFO(C, H, 4, Result, SetEnabledProgramVerification, (bool enabled), (enabled), hos::Version_10_0_0) \ + AMS_SF_METHOD_INFO(C, H, 65000, void, AtmosphereHasLaunchedBootProgram, (sf::Out out, ncm::ProgramId program_id), (out, program_id)) \ + AMS_SF_METHOD_INFO(C, H, 65001, Result, AtmosphereGetProgramInfo, (sf::Out out_program_info, sf::Out out_status, const ncm::ProgramLocation &loc, const ldr::ProgramAttributes &attrs), (out_program_info, out_status, loc, attrs)) \ + AMS_SF_METHOD_INFO(C, H, 65002, Result, AtmospherePinProgram, (sf::Out out_id, const ncm::ProgramLocation &loc, const cfg::OverrideStatus &override_status), (out_id, loc, override_status)) AMS_SF_DEFINE_INTERFACE(ams::ldr::impl, IProcessManagerInterface, AMS_LDR_I_PROCESS_MANAGER_INTERFACE_INTERFACE_INFO, 0x01518B8E) diff --git a/libraries/libstratosphere/include/stratosphere/ldr/ldr_pm_api.hpp b/libraries/libstratosphere/include/stratosphere/ldr/ldr_pm_api.hpp index dd5d34b9a..310c6fa51 100644 --- a/libraries/libstratosphere/include/stratosphere/ldr/ldr_pm_api.hpp +++ b/libraries/libstratosphere/include/stratosphere/ldr/ldr_pm_api.hpp @@ -20,15 +20,15 @@ namespace ams::ldr::pm { /* Process Manager API. */ - Result CreateProcess(os::NativeHandle *out, PinId pin_id, u32 flags, os::NativeHandle reslimit); - Result GetProgramInfo(ProgramInfo *out, const ncm::ProgramLocation &loc); + Result CreateProcess(os::NativeHandle *out, PinId pin_id, u32 flags, os::NativeHandle reslimit, ldr::ProgramAttributes attrs); + Result GetProgramInfo(ProgramInfo *out, const ncm::ProgramLocation &loc, ldr::ProgramAttributes attrs); Result PinProgram(PinId *out, const ncm::ProgramLocation &loc); Result UnpinProgram(PinId pin_id); Result SetEnabledProgramVerification(bool enabled); Result HasLaunchedBootProgram(bool *out, ncm::ProgramId program_id); /* Atmosphere extension API. */ - Result AtmosphereGetProgramInfo(ProgramInfo *out, cfg::OverrideStatus *out_status, const ncm::ProgramLocation &loc); + Result AtmosphereGetProgramInfo(ProgramInfo *out, cfg::OverrideStatus *out_status, const ncm::ProgramLocation &loc, ldr::ProgramAttributes attrs); Result AtmospherePinProgram(PinId *out, const ncm::ProgramLocation &loc, const cfg::OverrideStatus &status); } diff --git a/libraries/libstratosphere/include/stratosphere/ldr/ldr_types.hpp b/libraries/libstratosphere/include/stratosphere/ldr/ldr_types.hpp index 524657042..5cc2fbb8b 100644 --- a/libraries/libstratosphere/include/stratosphere/ldr/ldr_types.hpp +++ b/libraries/libstratosphere/include/stratosphere/ldr/ldr_types.hpp @@ -20,6 +20,7 @@ #include #include #include +#include namespace ams::ldr { @@ -265,4 +266,10 @@ namespace ams::ldr { }; static_assert(sizeof(Npdm) == 0x80 && util::is_pod::value, "Npdm definition!"); + struct ProgramAttributes { + ncm::ContentMetaPlatform platform; + fs::ContentAttributes content_attributes; + }; + static_assert(sizeof(ProgramAttributes) == 2 && util::is_pod::value, "ProgramAttributes definition!"); + } diff --git a/libraries/libstratosphere/source/ldr/ldr_ams.os.horizon.c b/libraries/libstratosphere/source/ldr/ldr_ams.os.horizon.c index 7d0b4f907..3a0dca194 100644 --- a/libraries/libstratosphere/source/ldr/ldr_ams.os.horizon.c +++ b/libraries/libstratosphere/source/ldr/ldr_ams.os.horizon.c @@ -32,8 +32,14 @@ Result ldrPmAtmosphereHasLaunchedBootProgram(bool *out, u64 program_id) { return _ldrAtmosphereHasLaunchedBootProgram(ldrPmGetServiceSession(), out, program_id); } -Result ldrPmAtmosphereGetProgramInfo(LoaderProgramInfo *out_program_info, CfgOverrideStatus *out_status, const NcmProgramLocation *loc) { - return serviceDispatchInOut(ldrPmGetServiceSession(), 65001, *loc, *out_status, +Result ldrPmAtmosphereGetProgramInfo(LoaderProgramInfo *out_program_info, CfgOverrideStatus *out_status, const NcmProgramLocation *loc, const LoaderProgramAttributes *attr) { + const struct { + LoaderProgramAttributes attr; + u16 pad1; + u32 pad2; + NcmProgramLocation loc; + } in = { *attr, 0, 0, *loc }; + return serviceDispatchInOut(ldrPmGetServiceSession(), 65001, in, *out_status, .buffer_attrs = { SfBufferAttr_Out | SfBufferAttr_HipcPointer | SfBufferAttr_FixedSize }, .buffers = { { out_program_info, sizeof(*out_program_info) } }, ); diff --git a/libraries/libstratosphere/source/ldr/ldr_ams.os.horizon.h b/libraries/libstratosphere/source/ldr/ldr_ams.os.horizon.h index 30a5e4163..b52807112 100644 --- a/libraries/libstratosphere/source/ldr/ldr_ams.os.horizon.h +++ b/libraries/libstratosphere/source/ldr/ldr_ams.os.horizon.h @@ -19,7 +19,7 @@ typedef struct { Result ldrPmAtmosphereHasLaunchedBootProgram(bool *out, u64 program_id); Result ldrDmntAtmosphereHasLaunchedBootProgram(bool *out, u64 program_id); -Result ldrPmAtmosphereGetProgramInfo(LoaderProgramInfo *out, CfgOverrideStatus *out_status, const NcmProgramLocation *loc); +Result ldrPmAtmosphereGetProgramInfo(LoaderProgramInfo *out, CfgOverrideStatus *out_status, const NcmProgramLocation *loc, const LoaderProgramAttributes *attr); Result ldrPmAtmospherePinProgram(u64 *out, const NcmProgramLocation *loc, const CfgOverrideStatus *status); #ifdef __cplusplus diff --git a/libraries/libstratosphere/source/ldr/ldr_pm_api.os.horizon.cpp b/libraries/libstratosphere/source/ldr/ldr_pm_api.os.horizon.cpp index 2e00417de..f461f9f7f 100644 --- a/libraries/libstratosphere/source/ldr/ldr_pm_api.os.horizon.cpp +++ b/libraries/libstratosphere/source/ldr/ldr_pm_api.os.horizon.cpp @@ -19,13 +19,14 @@ namespace ams::ldr::pm { /* Information API. */ - Result CreateProcess(os::NativeHandle *out, PinId pin_id, u32 flags, Handle reslimit) { - R_RETURN(ldrPmCreateProcess(pin_id.value, flags, reslimit, out)); + Result CreateProcess(os::NativeHandle *out, PinId pin_id, u32 flags, Handle reslimit, ldr::ProgramAttributes attrs) { + static_assert(sizeof(attrs) == sizeof(::LoaderProgramAttributes)); + R_RETURN(ldrPmCreateProcess(pin_id.value, flags, reslimit, reinterpret_cast(std::addressof(attrs)), out)); } - Result GetProgramInfo(ProgramInfo *out, const ncm::ProgramLocation &loc) { + Result GetProgramInfo(ProgramInfo *out, const ncm::ProgramLocation &loc, ldr::ProgramAttributes attrs) { static_assert(sizeof(*out) == sizeof(LoaderProgramInfo)); - R_RETURN(ldrPmGetProgramInfo(reinterpret_cast(std::addressof(loc)), reinterpret_cast(out))); + R_RETURN(ldrPmGetProgramInfo(reinterpret_cast(std::addressof(loc)), reinterpret_cast(std::addressof(attrs)), reinterpret_cast(out))); } Result PinProgram(PinId *out, const ncm::ProgramLocation &loc) { @@ -41,10 +42,10 @@ namespace ams::ldr::pm { R_RETURN(ldrPmAtmosphereHasLaunchedBootProgram(out, static_cast(program_id))); } - Result AtmosphereGetProgramInfo(ProgramInfo *out, cfg::OverrideStatus *out_status, const ncm::ProgramLocation &loc) { + Result AtmosphereGetProgramInfo(ProgramInfo *out, cfg::OverrideStatus *out_status, const ncm::ProgramLocation &loc, ldr::ProgramAttributes attrs) { static_assert(sizeof(*out_status) == sizeof(CfgOverrideStatus), "CfgOverrideStatus definition!"); static_assert(sizeof(*out) == sizeof(LoaderProgramInfo)); - R_RETURN(ldrPmAtmosphereGetProgramInfo(reinterpret_cast(out), reinterpret_cast(out_status), reinterpret_cast(std::addressof(loc)))); + R_RETURN(ldrPmAtmosphereGetProgramInfo(reinterpret_cast(out), reinterpret_cast(out_status), reinterpret_cast(std::addressof(loc)), reinterpret_cast(std::addressof(attrs)))); } Result SetEnabledProgramVerification(bool enabled) { diff --git a/libraries/libvapours/include/vapours/results/loader_results.hpp b/libraries/libvapours/include/vapours/results/loader_results.hpp index d9cfa62b5..25e3debee 100644 --- a/libraries/libvapours/include/vapours/results/loader_results.hpp +++ b/libraries/libvapours/include/vapours/results/loader_results.hpp @@ -21,20 +21,20 @@ R_DEFINE_NAMESPACE_RESULT_MODULE(ams::ldr, 9); namespace ams::ldr { - R_DEFINE_ERROR_RESULT(ArgumentOverflow, 1); - R_DEFINE_ERROR_RESULT(ArgumentCountOverflow, 2); - R_DEFINE_ERROR_RESULT(MetaOverflow, 3); - R_DEFINE_ERROR_RESULT(InvalidMeta, 4); - R_DEFINE_ERROR_RESULT(InvalidNso, 5); - R_DEFINE_ERROR_RESULT(InvalidPath, 6); - R_DEFINE_ERROR_RESULT(MaxProcess, 7); - R_DEFINE_ERROR_RESULT(NotPinned, 8); - R_DEFINE_ERROR_RESULT(InvalidProgramId, 9); - R_DEFINE_ERROR_RESULT(InvalidVersion, 10); - R_DEFINE_ERROR_RESULT(InvalidAcidSignature, 11); - R_DEFINE_ERROR_RESULT(InvalidNcaSignature, 12); + R_DEFINE_ERROR_RESULT(ArgumentOverflow, 1); + R_DEFINE_ERROR_RESULT(ArgumentCountOverflow, 2); + R_DEFINE_ERROR_RESULT(MetaOverflow, 3); + R_DEFINE_ERROR_RESULT(InvalidMeta, 4); + R_DEFINE_ERROR_RESULT(InvalidNso, 5); + R_DEFINE_ERROR_RESULT(InvalidPath, 6); + R_DEFINE_ERROR_RESULT(MaxProcess, 7); + R_DEFINE_ERROR_RESULT(NotPinned, 8); + R_DEFINE_ERROR_RESULT(InvalidProgramId, 9); + R_DEFINE_ERROR_RESULT(InvalidVersion, 10); + R_DEFINE_ERROR_RESULT(InvalidAcidSignature, 11); + R_DEFINE_ERROR_RESULT(InvalidNcaSignature, 12); - R_DEFINE_ERROR_RESULT(InvalidPlatformId, 14); + R_DEFINE_ERROR_RESULT(InvalidProgramAttributes, 14); R_DEFINE_ERROR_RESULT(OutOfAddressSpace, 51); R_DEFINE_ERROR_RESULT(InvalidNroImage, 52); diff --git a/stratosphere/loader/source/ldr_content_management.cpp b/stratosphere/loader/source/ldr_content_management.cpp index a08ddf6aa..f1d0dfa14 100644 --- a/stratosphere/loader/source/ldr_content_management.cpp +++ b/stratosphere/loader/source/ldr_content_management.cpp @@ -25,12 +25,12 @@ namespace ams::ldr { } /* ScopedCodeMount functionality. */ - ScopedCodeMount::ScopedCodeMount(const ncm::ProgramLocation &loc, ncm::ContentMetaPlatform platform) : m_lk(g_scoped_code_mount_lock), m_has_status(false), m_mounted_ams(false), m_mounted_sd_or_code(false), m_mounted_code(false) { - m_result = this->Initialize(loc, platform); + ScopedCodeMount::ScopedCodeMount(const ncm::ProgramLocation &loc, const ldr::ProgramAttributes &attrs) : m_lk(g_scoped_code_mount_lock), m_has_status(false), m_mounted_ams(false), m_mounted_sd_or_code(false), m_mounted_code(false) { + m_result = this->Initialize(loc, attrs); } - ScopedCodeMount::ScopedCodeMount(const ncm::ProgramLocation &loc, const cfg::OverrideStatus &o, ncm::ContentMetaPlatform platform) : m_lk(g_scoped_code_mount_lock), m_override_status(o), m_has_status(true), m_mounted_ams(false), m_mounted_sd_or_code(false), m_mounted_code(false) { - m_result = this->Initialize(loc, platform); + ScopedCodeMount::ScopedCodeMount(const ncm::ProgramLocation &loc, const cfg::OverrideStatus &o, const ldr::ProgramAttributes &attrs) : m_lk(g_scoped_code_mount_lock), m_override_status(o), m_has_status(true), m_mounted_ams(false), m_mounted_sd_or_code(false), m_mounted_code(false) { + m_result = this->Initialize(loc, attrs); } ScopedCodeMount::~ScopedCodeMount() { @@ -46,17 +46,17 @@ namespace ams::ldr { } } - Result ScopedCodeMount::Initialize(const ncm::ProgramLocation &loc, ncm::ContentMetaPlatform platform) { + Result ScopedCodeMount::Initialize(const ncm::ProgramLocation &loc, const ldr::ProgramAttributes &attrs) { /* Capture override status, if necessary. */ this->EnsureOverrideStatus(loc); AMS_ABORT_UNLESS(m_has_status); /* Get the content path. */ char content_path[fs::EntryNameLengthMax + 1]; - R_TRY(GetProgramPath(content_path, sizeof(content_path), loc, platform)); + R_TRY(GetProgramPath(content_path, sizeof(content_path), loc, attrs)); /* Get the content attributes. */ - const auto content_attributes = GetPlatformContentAttributes(platform); + const auto content_attributes = attrs.content_attributes; /* Mount the atmosphere code file system. */ R_TRY(fs::MountCodeForAtmosphereWithRedirection(std::addressof(m_ams_code_verification_data), AtmosphereCodeMountName, content_path, content_attributes, loc.program_id, static_cast(loc.storage_id), m_override_status.IsHbl(), m_override_status.IsProgramSpecific())); @@ -83,7 +83,7 @@ namespace ams::ldr { } /* Redirection API. */ - Result GetProgramPath(char *out_path, size_t out_size, const ncm::ProgramLocation &loc, ncm::ContentMetaPlatform platform) { + Result GetProgramPath(char *out_path, size_t out_size, const ncm::ProgramLocation &loc, const ldr::ProgramAttributes &attrs) { /* Check for storage id none. */ if (static_cast(loc.storage_id) == ncm::StorageId::None) { std::memset(out_path, 0, out_size); @@ -92,7 +92,7 @@ namespace ams::ldr { } /* Get the content attributes. */ - const auto content_attributes = GetPlatformContentAttributes(platform); + const auto content_attributes = attrs.content_attributes; AMS_UNUSED(content_attributes); lr::Path path; @@ -166,12 +166,4 @@ namespace ams::ldr { R_SUCCEED(); } - fs::ContentAttributes GetPlatformContentAttributes(ncm::ContentMetaPlatform platform) { - switch (platform) { - case ncm::ContentMetaPlatform::Nx: - return fs::ContentAttributes_None; - AMS_UNREACHABLE_DEFAULT_CASE(); - } - } - } diff --git a/stratosphere/loader/source/ldr_content_management.hpp b/stratosphere/loader/source/ldr_content_management.hpp index f44ef738e..d20c80709 100644 --- a/stratosphere/loader/source/ldr_content_management.hpp +++ b/stratosphere/loader/source/ldr_content_management.hpp @@ -34,8 +34,8 @@ namespace ams::ldr { bool m_mounted_sd_or_code; bool m_mounted_code; public: - ScopedCodeMount(const ncm::ProgramLocation &loc, ncm::ContentMetaPlatform platform); - ScopedCodeMount(const ncm::ProgramLocation &loc, const cfg::OverrideStatus &override_status, ncm::ContentMetaPlatform platform); + ScopedCodeMount(const ncm::ProgramLocation &loc, const ldr::ProgramAttributes &attrs); + ScopedCodeMount(const ncm::ProgramLocation &loc, const cfg::OverrideStatus &override_status, const ldr::ProgramAttributes &attrs); ~ScopedCodeMount(); Result GetResult() const { @@ -59,7 +59,7 @@ namespace ams::ldr { return m_base_code_verification_data; } private: - Result Initialize(const ncm::ProgramLocation &loc, ncm::ContentMetaPlatform platform); + Result Initialize(const ncm::ProgramLocation &loc, const ldr::ProgramAttributes &attrs); void EnsureOverrideStatus(const ncm::ProgramLocation &loc); }; @@ -76,10 +76,8 @@ namespace ams::ldr { #define ENCODE_CMPT_PATH(relative) "cmpt:" relative /* Redirection API. */ - Result GetProgramPath(char *out_path, size_t out_size, const ncm::ProgramLocation &loc, ncm::ContentMetaPlatform platform); + Result GetProgramPath(char *out_path, size_t out_size, const ncm::ProgramLocation &loc, const ldr::ProgramAttributes &attrs); Result RedirectProgramPath(const char *path, size_t size, const ncm::ProgramLocation &loc); Result RedirectHtmlDocumentPathForHbl(const ncm::ProgramLocation &loc); - fs::ContentAttributes GetPlatformContentAttributes(ncm::ContentMetaPlatform platform); - } diff --git a/stratosphere/loader/source/ldr_loader_service.cpp b/stratosphere/loader/source/ldr_loader_service.cpp index b363d6b13..17a4a9160 100644 --- a/stratosphere/loader/source/ldr_loader_service.cpp +++ b/stratosphere/loader/source/ldr_loader_service.cpp @@ -27,72 +27,72 @@ namespace ams::ldr { constinit ArgumentStore g_argument_store; - bool IsValidPlatform(ncm::ContentMetaPlatform platform) { - return platform == ncm::ContentMetaPlatform::Nx; - } - - Result CreateProcessByPlatform(os::NativeHandle *out, PinId pin_id, u32 flags, os::NativeHandle resource_limit, ncm::ContentMetaPlatform platform) { - /* Check that the platform is valid. */ - R_UNLESS(IsValidPlatform(platform), ldr::ResultInvalidPlatformId()); - - /* Get the location and override status. */ - ncm::ProgramLocation loc; - cfg::OverrideStatus override_status; - R_TRY(ldr::GetProgramLocationAndOverrideStatusFromPinId(std::addressof(loc), std::addressof(override_status), pin_id)); - - /* Get the program path. */ - char path[fs::EntryNameLengthMax]; - R_TRY(GetProgramPath(path, sizeof(path), loc, platform)); - path[sizeof(path) - 1] = '\x00'; - - /* Create the process. */ - R_RETURN(ldr::CreateProcess(out, pin_id, loc, override_status, path, g_argument_store.Get(loc.program_id), flags, resource_limit, platform)); - } - - Result GetProgramInfoByPlatform(ProgramInfo *out, cfg::OverrideStatus *out_status, const ncm::ProgramLocation &loc, ncm::ContentMetaPlatform platform) { - /* Check that the platform is valid. */ - R_UNLESS(IsValidPlatform(platform), ldr::ResultInvalidPlatformId()); - - /* Zero output. */ - std::memset(out, 0, sizeof(*out)); - - /* Get the program path. */ - char path[fs::EntryNameLengthMax]; - R_TRY(GetProgramPath(path, sizeof(path), loc, platform)); - path[sizeof(path) - 1] = '\x00'; - - /* Get the program info. */ - cfg::OverrideStatus status; - R_TRY(ldr::GetProgramInfo(out, std::addressof(status), loc, path, platform)); - - if (loc.program_id != out->program_id) { - /* Redirect the program path. */ - const ncm::ProgramLocation new_loc = ncm::ProgramLocation::Make(out->program_id, static_cast(loc.storage_id)); - R_TRY(RedirectProgramPath(path, sizeof(path), new_loc)); - - /* Update the arguments, as needed. */ - if (const auto *entry = g_argument_store.Get(loc.program_id); entry != nullptr) { - R_TRY(g_argument_store.Set(new_loc.program_id, entry->argument, entry->argument_size)); - } + bool IsValidProgramAttributes(const ldr::ProgramAttributes &attrs) { + /* Check that the attributes are valid; on NX, this means Platform = NX + no content attrs. */ + if (attrs.platform != ncm::ContentMetaPlatform::Nx) { + return false; + } + if (attrs.content_attributes != fs::ContentAttributes_None) { + return false; } - /* If we should, set the output status. */ - if (out_status != nullptr) { - *out_status = status; - } - - R_SUCCEED(); + return true; } } - Result LoaderService::CreateProcess(os::NativeHandle *out, PinId pin_id, u32 flags, os::NativeHandle resource_limit) { - R_RETURN(CreateProcessByPlatform(out, pin_id, flags, resource_limit, ncm::ContentMetaPlatform::Nx)); + Result LoaderService::CreateProcess(os::NativeHandle *out, PinId pin_id, u32 flags, os::NativeHandle resource_limit, const ProgramAttributes &attrs) { + /* Check that the program attributes are valid. */ + R_UNLESS(IsValidProgramAttributes(attrs), ldr::ResultInvalidProgramAttributes()); + + /* Get the location and override status. */ + ncm::ProgramLocation loc; + cfg::OverrideStatus override_status; + R_TRY(ldr::GetProgramLocationAndOverrideStatusFromPinId(std::addressof(loc), std::addressof(override_status), pin_id)); + + /* Get the program path. */ + char path[fs::EntryNameLengthMax]; + R_TRY(GetProgramPath(path, sizeof(path), loc, attrs)); + path[sizeof(path) - 1] = '\x00'; + + /* Create the process. */ + R_RETURN(ldr::CreateProcess(out, pin_id, loc, override_status, path, g_argument_store.Get(loc.program_id), flags, resource_limit, attrs)); } - Result LoaderService::GetProgramInfo(ProgramInfo *out, cfg::OverrideStatus *out_status, const ncm::ProgramLocation &loc) { - R_RETURN(GetProgramInfoByPlatform(out, out_status, loc, ncm::ContentMetaPlatform::Nx)); + Result LoaderService::GetProgramInfo(ProgramInfo *out, cfg::OverrideStatus *out_status, const ncm::ProgramLocation &loc, const ProgramAttributes &attrs) { + /* Check that the program attributes are valid. */ + R_UNLESS(IsValidProgramAttributes(attrs), ldr::ResultInvalidProgramAttributes()); + + /* Zero output. */ + std::memset(out, 0, sizeof(*out)); + + /* Get the program path. */ + char path[fs::EntryNameLengthMax]; + R_TRY(GetProgramPath(path, sizeof(path), loc, attrs)); + path[sizeof(path) - 1] = '\x00'; + + /* Get the program info. */ + cfg::OverrideStatus status; + R_TRY(ldr::GetProgramInfo(out, std::addressof(status), loc, path, attrs)); + + if (loc.program_id != out->program_id) { + /* Redirect the program path. */ + const ncm::ProgramLocation new_loc = ncm::ProgramLocation::Make(out->program_id, static_cast(loc.storage_id)); + R_TRY(RedirectProgramPath(path, sizeof(path), new_loc)); + + /* Update the arguments, as needed. */ + if (const auto *entry = g_argument_store.Get(loc.program_id); entry != nullptr) { + R_TRY(g_argument_store.Set(new_loc.program_id, entry->argument, entry->argument_size)); + } + } + + /* If we should, set the output status. */ + if (out_status != nullptr) { + *out_status = status; + } + + R_SUCCEED(); } Result LoaderService::PinProgram(PinId *out, const ncm::ProgramLocation &loc, const cfg::OverrideStatus &status) { diff --git a/stratosphere/loader/source/ldr_loader_service.hpp b/stratosphere/loader/source/ldr_loader_service.hpp index bad74cd80..9f5314c55 100644 --- a/stratosphere/loader/source/ldr_loader_service.hpp +++ b/stratosphere/loader/source/ldr_loader_service.hpp @@ -21,16 +21,16 @@ namespace ams::ldr { class LoaderService { public: /* Official commands. */ - Result CreateProcess(sf::OutMoveHandle proc_h, PinId id, u32 flags, sf::CopyHandle &&reslimit_h) { + Result CreateProcess(sf::OutMoveHandle proc_h, PinId id, u32 flags, sf::CopyHandle &&reslimit_h, const ProgramAttributes &attrs) { /* Create a handle to set the output to when done. */ os::NativeHandle handle = os::InvalidNativeHandle; ON_SCOPE_EXIT { proc_h.SetValue(handle, true); }; - R_RETURN(this->CreateProcess(std::addressof(handle), id, flags, reslimit_h.GetOsHandle())); + R_RETURN(this->CreateProcess(std::addressof(handle), id, flags, reslimit_h.GetOsHandle(), attrs)); } - Result GetProgramInfo(sf::Out out_program_info, const ncm::ProgramLocation &loc) { - R_RETURN(this->GetProgramInfo(out_program_info.GetPointer(), nullptr, loc)); + Result GetProgramInfo(sf::Out out_program_info, const ncm::ProgramLocation &loc, const ProgramAttributes &attrs) { + R_RETURN(this->GetProgramInfo(out_program_info.GetPointer(), nullptr, loc, attrs)); } Result PinProgram(sf::Out out_id, const ncm::ProgramLocation &loc) { @@ -75,16 +75,16 @@ namespace ams::ldr { return this->HasLaunchedBootProgram(out.GetPointer(), program_id); } - Result AtmosphereGetProgramInfo(sf::Out out_program_info, sf::Out out_status, const ncm::ProgramLocation &loc) { - R_RETURN(this->GetProgramInfo(out_program_info.GetPointer(), out_status.GetPointer(), loc)); + Result AtmosphereGetProgramInfo(sf::Out out_program_info, sf::Out out_status, const ncm::ProgramLocation &loc, const ProgramAttributes &attrs) { + R_RETURN(this->GetProgramInfo(out_program_info.GetPointer(), out_status.GetPointer(), loc, attrs)); } Result AtmospherePinProgram(sf::Out out_id, const ncm::ProgramLocation &loc, const cfg::OverrideStatus &override_status) { R_RETURN(this->PinProgram(out_id.GetPointer(), loc, override_status)); } private: - Result CreateProcess(os::NativeHandle *out, PinId pin_id, u32 flags, os::NativeHandle resource_limit); - Result GetProgramInfo(ProgramInfo *out, cfg::OverrideStatus *out_status, const ncm::ProgramLocation &loc); + Result CreateProcess(os::NativeHandle *out, PinId pin_id, u32 flags, os::NativeHandle resource_limit, const ProgramAttributes &attrs); + Result GetProgramInfo(ProgramInfo *out, cfg::OverrideStatus *out_status, const ncm::ProgramLocation &loc, const ProgramAttributes &attrs); Result PinProgram(PinId *out, const ncm::ProgramLocation &loc, const cfg::OverrideStatus &status); Result SetProgramArgument(ncm::ProgramId program_id, const void *argument, size_t size); Result GetProcessModuleInfo(u32 *out_count, ModuleInfo *out, size_t max_out_count, os::ProcessId process_id); diff --git a/stratosphere/loader/source/ldr_process_creation.cpp b/stratosphere/loader/source/ldr_process_creation.cpp index ad94e85d6..5f6f2226b 100644 --- a/stratosphere/loader/source/ldr_process_creation.cpp +++ b/stratosphere/loader/source/ldr_process_creation.cpp @@ -664,15 +664,15 @@ namespace ams::ldr { } /* Process Creation API. */ - Result CreateProcess(os::NativeHandle *out, PinId pin_id, const ncm::ProgramLocation &loc, const cfg::OverrideStatus &override_status, const char *path, const ArgumentStore::Entry *argument, u32 flags, os::NativeHandle resource_limit, ncm::ContentMetaPlatform platform) { + Result CreateProcess(os::NativeHandle *out, PinId pin_id, const ncm::ProgramLocation &loc, const cfg::OverrideStatus &override_status, const char *path, const ArgumentStore::Entry *argument, u32 flags, os::NativeHandle resource_limit, const ldr::ProgramAttributes &attrs) { /* Mount code. */ AMS_UNUSED(path); - ScopedCodeMount mount(loc, override_status, platform); + ScopedCodeMount mount(loc, override_status, attrs); R_TRY(mount.GetResult()); /* Load meta, possibly from cache. */ Meta meta; - R_TRY(LoadMetaFromCache(std::addressof(meta), loc, override_status, platform)); + R_TRY(LoadMetaFromCache(std::addressof(meta), loc, override_status, attrs.platform)); /* Validate meta. */ R_TRY(ValidateMeta(std::addressof(meta), loc, mount.GetCodeVerificationData())); @@ -720,16 +720,16 @@ namespace ams::ldr { R_SUCCEED(); } - Result GetProgramInfo(ProgramInfo *out, cfg::OverrideStatus *out_status, const ncm::ProgramLocation &loc, const char *path, ncm::ContentMetaPlatform platform) { + Result GetProgramInfo(ProgramInfo *out, cfg::OverrideStatus *out_status, const ncm::ProgramLocation &loc, const char *path, const ldr::ProgramAttributes &attrs) { Meta meta; /* Load Meta. */ { AMS_UNUSED(path); - ScopedCodeMount mount(loc, platform); + ScopedCodeMount mount(loc, attrs); R_TRY(mount.GetResult()); - R_TRY(LoadMeta(std::addressof(meta), loc, mount.GetOverrideStatus(), platform, false)); + R_TRY(LoadMeta(std::addressof(meta), loc, mount.GetOverrideStatus(), attrs.platform, false)); if (out_status != nullptr) { *out_status = mount.GetOverrideStatus(); } diff --git a/stratosphere/loader/source/ldr_process_creation.hpp b/stratosphere/loader/source/ldr_process_creation.hpp index 5e224a72a..0d24c7720 100644 --- a/stratosphere/loader/source/ldr_process_creation.hpp +++ b/stratosphere/loader/source/ldr_process_creation.hpp @@ -19,8 +19,8 @@ namespace ams::ldr { /* Process Creation API. */ - Result CreateProcess(os::NativeHandle *out, PinId pin_id, const ncm::ProgramLocation &loc, const cfg::OverrideStatus &override_status, const char *path, const ArgumentStore::Entry *argument, u32 flags, os::NativeHandle resource_limit, ncm::ContentMetaPlatform platform); - Result GetProgramInfo(ProgramInfo *out, cfg::OverrideStatus *out_status, const ncm::ProgramLocation &loc, const char *path, ncm::ContentMetaPlatform platform); + Result CreateProcess(os::NativeHandle *out, PinId pin_id, const ncm::ProgramLocation &loc, const cfg::OverrideStatus &override_status, const char *path, const ArgumentStore::Entry *argument, u32 flags, os::NativeHandle resource_limit, const ldr::ProgramAttributes &attrs); + Result GetProgramInfo(ProgramInfo *out, cfg::OverrideStatus *out_status, const ncm::ProgramLocation &loc, const char *path, const ldr::ProgramAttributes &attrs); Result PinProgram(PinId *out_id, const ncm::ProgramLocation &loc, const cfg::OverrideStatus &override_status); Result UnpinProgram(PinId id); diff --git a/stratosphere/pm/source/impl/pm_process_attributes.hpp b/stratosphere/pm/source/impl/pm_process_attributes.hpp new file mode 100644 index 000000000..b622be264 --- /dev/null +++ b/stratosphere/pm/source/impl/pm_process_attributes.hpp @@ -0,0 +1,35 @@ +/* + * Copyright (c) Atmosphère-NX + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +#pragma once +#include + +namespace ams::pm::impl { + + struct ProcessAttributes { + u8 unknown[3]; + ldr::ProgramAttributes program_attrs; + }; + static_assert(sizeof(ProcessAttributes) == 5); + + constexpr inline ProcessAttributes ProcessAttributes_Nx = { + .unknown = {}, + .program_attrs = { + .platform = ncm::ContentMetaPlatform::Nx, + .content_attributes = fs::ContentAttributes_None, + }, + }; + +} diff --git a/stratosphere/pm/source/impl/pm_process_info.cpp b/stratosphere/pm/source/impl/pm_process_info.cpp index 90373b55a..d472803dc 100644 --- a/stratosphere/pm/source/impl/pm_process_info.cpp +++ b/stratosphere/pm/source/impl/pm_process_info.cpp @@ -76,7 +76,7 @@ namespace ams::pm::impl { } - ProcessInfo::ProcessInfo(os::NativeHandle h, os::ProcessId pid, ldr::PinId pin, const ncm::ProgramLocation &l, const cfg::OverrideStatus &s) : m_process_id(pid), m_pin_id(pin), m_loc(l), m_status(s), m_handle(h), m_state(svc::ProcessState_Created), m_flags(0) { + ProcessInfo::ProcessInfo(os::NativeHandle h, os::ProcessId pid, ldr::PinId pin, const ncm::ProgramLocation &l, const cfg::OverrideStatus &s, const ProcessAttributes &attrs) : m_process_id(pid), m_pin_id(pin), m_loc(l), m_status(s), m_handle(h), m_state(svc::ProcessState_Created), m_flags(0), m_attrs(attrs) { os::InitializeMultiWaitHolder(std::addressof(m_multi_wait_holder), m_handle); os::SetMultiWaitHolderUserData(std::addressof(m_multi_wait_holder), reinterpret_cast(this)); } @@ -106,8 +106,8 @@ namespace ams::pm::impl { return ProcessListAccessor(g_exit_list); } - ProcessInfo *AllocateProcessInfo(svc::Handle process_handle, os::ProcessId process_id, ldr::PinId pin_id, const ncm::ProgramLocation &location, const cfg::OverrideStatus &override_status) { - return g_process_info_allocator.AllocateProcessInfo(process_handle, process_id, pin_id, location, override_status); + ProcessInfo *AllocateProcessInfo(svc::Handle process_handle, os::ProcessId process_id, ldr::PinId pin_id, const ncm::ProgramLocation &location, const cfg::OverrideStatus &override_status, const ProcessAttributes &attrs) { + return g_process_info_allocator.AllocateProcessInfo(process_handle, process_id, pin_id, location, override_status, attrs); } void CleanupProcessInfo(ProcessListAccessor &list, ProcessInfo *process_info) { diff --git a/stratosphere/pm/source/impl/pm_process_info.hpp b/stratosphere/pm/source/impl/pm_process_info.hpp index f2dae02ae..66e64c436 100644 --- a/stratosphere/pm/source/impl/pm_process_info.hpp +++ b/stratosphere/pm/source/impl/pm_process_info.hpp @@ -15,6 +15,7 @@ */ #pragma once #include "pm_process_manager.hpp" +#include "pm_process_attributes.hpp" namespace ams::pm::impl { @@ -46,6 +47,7 @@ namespace ams::pm::impl { os::NativeHandle m_handle; svc::ProcessState m_state; u32 m_flags; + ProcessAttributes m_attrs; os::MultiWaitHolderType m_multi_wait_holder; private: void SetFlag(Flag flag) { @@ -60,7 +62,7 @@ namespace ams::pm::impl { return (m_flags & flag); } public: - ProcessInfo(os::NativeHandle h, os::ProcessId pid, ldr::PinId pin, const ncm::ProgramLocation &l, const cfg::OverrideStatus &s); + ProcessInfo(os::NativeHandle h, os::ProcessId pid, ldr::PinId pin, const ncm::ProgramLocation &l, const cfg::OverrideStatus &s, const ProcessAttributes &attrs); ~ProcessInfo(); void Cleanup(); @@ -88,6 +90,10 @@ namespace ams::pm::impl { return m_status; } + const ProcessAttributes &GetProcessAttributes() const { + return m_attrs; + } + svc::ProcessState GetState() const { return m_state; } @@ -235,7 +241,7 @@ namespace ams::pm::impl { ProcessListAccessor GetProcessList(); ProcessListAccessor GetExitList(); - ProcessInfo *AllocateProcessInfo(svc::Handle process_handle, os::ProcessId process_id, ldr::PinId pin_id, const ncm::ProgramLocation &location, const cfg::OverrideStatus &override_status); + ProcessInfo *AllocateProcessInfo(svc::Handle process_handle, os::ProcessId process_id, ldr::PinId pin_id, const ncm::ProgramLocation &location, const cfg::OverrideStatus &override_status, const ProcessAttributes &attrs); void CleanupProcessInfo(ProcessListAccessor &list, ProcessInfo *process_info); } diff --git a/stratosphere/pm/source/impl/pm_process_manager.cpp b/stratosphere/pm/source/impl/pm_process_manager.cpp index 32ef0feac..50600f0d4 100644 --- a/stratosphere/pm/source/impl/pm_process_manager.cpp +++ b/stratosphere/pm/source/impl/pm_process_manager.cpp @@ -117,14 +117,14 @@ namespace ams::pm::impl { R_SUCCEED(); } - Result LaunchProgramImpl(ProcessInfo **out_process_info, os::ProcessId *out_process_id, const ncm::ProgramLocation &loc, u32 flags) { + Result LaunchProgramImpl(ProcessInfo **out_process_info, os::ProcessId *out_process_id, const ncm::ProgramLocation &loc, u32 flags, const ProcessAttributes &attrs) { /* Set the output to nullptr, if we fail. */ *out_process_info = nullptr; /* Get Program Info. */ ldr::ProgramInfo program_info; cfg::OverrideStatus override_status; - R_TRY(ldr::pm::AtmosphereGetProgramInfo(std::addressof(program_info), std::addressof(override_status), loc)); + R_TRY(ldr::pm::AtmosphereGetProgramInfo(std::addressof(program_info), std::addressof(override_status), loc, attrs.program_attrs)); const bool is_application = (program_info.flags & ldr::ProgramInfoFlag_ApplicationTypeMask) == ldr::ProgramInfoFlag_Application; const bool allow_debug = (program_info.flags & ldr::ProgramInfoFlag_AllowDebug) || hos::GetVersion() < hos::Version_2_0_0; @@ -166,14 +166,14 @@ namespace ams::pm::impl { WaitResourceAvailable(std::addressof(program_info)); /* Actually create the process. */ - R_TRY(ldr::pm::CreateProcess(std::addressof(process_handle), pin_id, GetLoaderCreateProcessFlags(flags), GetResourceLimitHandle(std::addressof(program_info)))); + R_TRY(ldr::pm::CreateProcess(std::addressof(process_handle), pin_id, GetLoaderCreateProcessFlags(flags), GetResourceLimitHandle(std::addressof(program_info)), attrs.program_attrs)); } /* Get the process id. */ os::ProcessId process_id = os::GetProcessId(process_handle); /* Make new process info. */ - ProcessInfo *process_info = AllocateProcessInfo(process_handle, process_id, pin_id, fixed_location, override_status); + ProcessInfo *process_info = AllocateProcessInfo(process_handle, process_id, pin_id, fixed_location, override_status, attrs); AMS_ABORT_UNLESS(process_info != nullptr); /* Add the new process info to the process list. */ @@ -253,7 +253,7 @@ namespace ams::pm::impl { Result LaunchProgram(os::ProcessId *out_process_id, const ncm::ProgramLocation &loc, u32 flags) { /* Launch the program. */ ProcessInfo *process_info = nullptr; - R_TRY(LaunchProgramImpl(std::addressof(process_info), out_process_id, loc, flags)); + R_TRY(LaunchProgramImpl(std::addressof(process_info), out_process_id, loc, flags, ProcessAttributes_Nx)); /* Register the process info with the tracker. */ g_process_tracker.QueueEntry(process_info); @@ -268,7 +268,7 @@ namespace ams::pm::impl { R_UNLESS(!process_info->HasStarted(), pm::ResultAlreadyStarted()); ldr::ProgramInfo program_info; - R_TRY(ldr::pm::GetProgramInfo(std::addressof(program_info), process_info->GetProgramLocation())); + R_TRY(ldr::pm::GetProgramInfo(std::addressof(program_info), process_info->GetProgramLocation(), process_info->GetProcessAttributes().program_attrs)); R_RETURN(StartProcess(process_info, std::addressof(program_info))); }