mirror of
https://github.com/Atmosphere-NX/Atmosphere.git
synced 2025-05-23 11:16:57 -04:00
ldr/pm: update for 20.0.0 abi changes
This commit is contained in:
parent
6bab59ea3d
commit
37a971a706
17 changed files with 186 additions and 141 deletions
|
@ -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<ncm::StorageId>(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<ncm::StorageId>(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();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
||||
}
|
||||
|
|
|
@ -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<ncm::StorageId>(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<ncm::StorageId>(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) {
|
||||
|
|
|
@ -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<ProgramInfo> out_program_info, const ncm::ProgramLocation &loc) {
|
||||
R_RETURN(this->GetProgramInfo(out_program_info.GetPointer(), nullptr, loc));
|
||||
Result GetProgramInfo(sf::Out<ProgramInfo> 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<PinId> out_id, const ncm::ProgramLocation &loc) {
|
||||
|
@ -75,16 +75,16 @@ namespace ams::ldr {
|
|||
return this->HasLaunchedBootProgram(out.GetPointer(), program_id);
|
||||
}
|
||||
|
||||
Result AtmosphereGetProgramInfo(sf::Out<ProgramInfo> out_program_info, sf::Out<cfg::OverrideStatus> out_status, const ncm::ProgramLocation &loc) {
|
||||
R_RETURN(this->GetProgramInfo(out_program_info.GetPointer(), out_status.GetPointer(), loc));
|
||||
Result AtmosphereGetProgramInfo(sf::Out<ProgramInfo> out_program_info, sf::Out<cfg::OverrideStatus> 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<PinId> 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);
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue