strat: TitleId -> ProgramId, titles->contents

This commit is contained in:
Michael Scire 2019-10-27 21:43:01 -07:00 committed by SciresM
parent 1636668762
commit ea3ebbaa7d
86 changed files with 1138 additions and 1140 deletions

View file

@ -50,12 +50,12 @@ dist: all
mkdir atmosphere-$(AMSVER)/atmosphere
mkdir atmosphere-$(AMSVER)/sept
mkdir atmosphere-$(AMSVER)/switch
mkdir -p atmosphere-$(AMSVER)/atmosphere/titles/0100000000000008
mkdir -p atmosphere-$(AMSVER)/atmosphere/titles/010000000000000D
mkdir -p atmosphere-$(AMSVER)/atmosphere/titles/0100000000000032
mkdir -p atmosphere-$(AMSVER)/atmosphere/titles/0100000000000034
mkdir -p atmosphere-$(AMSVER)/atmosphere/titles/0100000000000036
mkdir -p atmosphere-$(AMSVER)/atmosphere/titles/0100000000000037
mkdir -p atmosphere-$(AMSVER)/atmosphere/contents/0100000000000008
mkdir -p atmosphere-$(AMSVER)/atmosphere/contents/010000000000000D
mkdir -p atmosphere-$(AMSVER)/atmosphere/contents/0100000000000032
mkdir -p atmosphere-$(AMSVER)/atmosphere/contents/0100000000000034
mkdir -p atmosphere-$(AMSVER)/atmosphere/contents/0100000000000036
mkdir -p atmosphere-$(AMSVER)/atmosphere/contents/0100000000000037
mkdir -p atmosphere-$(AMSVER)/atmosphere/fatal_errors
cp fusee/fusee-primary/fusee-primary.bin atmosphere-$(AMSVER)/atmosphere/reboot_payload.bin
cp fusee/fusee-mtc/fusee-mtc.bin atmosphere-$(AMSVER)/atmosphere/fusee-mtc.bin
@ -70,16 +70,16 @@ dist: all
cp common/defaults/system_settings.ini atmosphere-$(AMSVER)/atmosphere/system_settings.ini
cp -r common/defaults/kip_patches atmosphere-$(AMSVER)/atmosphere/kip_patches
cp -r common/defaults/hbl_html atmosphere-$(AMSVER)/atmosphere/hbl_html
cp stratosphere/boot2/boot2.nsp atmosphere-$(AMSVER)/atmosphere/titles/0100000000000008/exefs.nsp
cp stratosphere/dmnt/dmnt.nsp atmosphere-$(AMSVER)/atmosphere/titles/010000000000000D/exefs.nsp
cp stratosphere/eclct.stub/eclct.stub.nsp atmosphere-$(AMSVER)/atmosphere/titles/0100000000000032/exefs.nsp
cp stratosphere/fatal/fatal.nsp atmosphere-$(AMSVER)/atmosphere/titles/0100000000000034/exefs.nsp
cp stratosphere/creport/creport.nsp atmosphere-$(AMSVER)/atmosphere/titles/0100000000000036/exefs.nsp
cp stratosphere/ro/ro.nsp atmosphere-$(AMSVER)/atmosphere/titles/0100000000000037/exefs.nsp
mkdir -p atmosphere-$(AMSVER)/atmosphere/titles/0100000000000032/flags
touch atmosphere-$(AMSVER)/atmosphere/titles/0100000000000032/flags/boot2.flag
mkdir -p atmosphere-$(AMSVER)/atmosphere/titles/0100000000000037/flags
touch atmosphere-$(AMSVER)/atmosphere/titles/0100000000000037/flags/boot2.flag
cp stratosphere/boot2/boot2.nsp atmosphere-$(AMSVER)/atmosphere/contents/0100000000000008/exefs.nsp
cp stratosphere/dmnt/dmnt.nsp atmosphere-$(AMSVER)/atmosphere/contents/010000000000000D/exefs.nsp
cp stratosphere/eclct.stub/eclct.stub.nsp atmosphere-$(AMSVER)/atmosphere/contents/0100000000000032/exefs.nsp
cp stratosphere/fatal/fatal.nsp atmosphere-$(AMSVER)/atmosphere/contents/0100000000000034/exefs.nsp
cp stratosphere/creport/creport.nsp atmosphere-$(AMSVER)/atmosphere/contents/0100000000000036/exefs.nsp
cp stratosphere/ro/ro.nsp atmosphere-$(AMSVER)/atmosphere/contents/0100000000000037/exefs.nsp
mkdir -p atmosphere-$(AMSVER)/atmosphere/contents/0100000000000032/flags
touch atmosphere-$(AMSVER)/atmosphere/contents/0100000000000032/flags/boot2.flag
mkdir -p atmosphere-$(AMSVER)/atmosphere/contents/0100000000000037/flags
touch atmosphere-$(AMSVER)/atmosphere/contents/0100000000000037/flags/boot2.flag
cp troposphere/reboot_to_payload/reboot_to_payload.nro atmosphere-$(AMSVER)/switch/reboot_to_payload.nro
cd atmosphere-$(AMSVER); zip -r ../atmosphere-$(AMSVER).zip ./*; cd ../;
rm -r atmosphere-$(AMSVER)

View file

@ -52,7 +52,7 @@ extern "C" {
namespace ams {
ncm::TitleId CurrentTitleId = ncm::TitleId::Boot;
ncm::ProgramId CurrentProgramId = ncm::ProgramId::Boot;
void ExceptionHandler(FatalErrorContext *ctx) {
/* We're boot sysmodule, so manually reboot to fatal error. */

View file

@ -38,7 +38,7 @@ extern "C" {
namespace ams {
ncm::TitleId CurrentTitleId = ncm::TitleId::Boot2;
ncm::ProgramId CurrentProgramId = ncm::ProgramId::Boot2;
namespace result {

View file

@ -138,8 +138,8 @@ namespace ams::creport {
out->aarch64_ctx.SetBaseAddress(this->module_list.GetModuleStartAddress(0));
}
/* For ams fatal, which doesn't use afsr0, pass title_id instead. */
out->aarch64_ctx.SetTitleIdForAtmosphere(ncm::TitleId{this->process_info.title_id});
/* For ams fatal, which doesn't use afsr0, pass program_id instead. */
out->aarch64_ctx.SetProgramIdForAtmosphere(ncm::ProgramId{this->process_info.program_id});
}
void CrashReport::ProcessExceptions() {
@ -282,7 +282,7 @@ namespace ams::creport {
char file_path[FS_MAX_PATH];
/* Save crash report. */
std::snprintf(file_path, sizeof(file_path), "sdmc:/atmosphere/crash_reports/%011lu_%016lx.log", timestamp, this->process_info.title_id);
std::snprintf(file_path, sizeof(file_path), "sdmc:/atmosphere/crash_reports/%011lu_%016lx.log", timestamp, this->process_info.program_id);
FILE *fp = fopen(file_path, "w");
if (fp != nullptr) {
this->SaveToFile(fp);
@ -291,7 +291,7 @@ namespace ams::creport {
}
/* Dump threads. */
std::snprintf(file_path, sizeof(file_path), "sdmc:/atmosphere/crash_reports/dumps/%011lu_%016lx_thread_info.bin", timestamp, this->process_info.title_id);
std::snprintf(file_path, sizeof(file_path), "sdmc:/atmosphere/crash_reports/dumps/%011lu_%016lx_thread_info.bin", timestamp, this->process_info.program_id);
fp = fopen(file_path, "wb");
if (fp != nullptr) {
this->thread_list.DumpBinary(fp, this->crashed_thread.GetThreadId());
@ -311,7 +311,7 @@ namespace ams::creport {
std::memcpy(name_buf, this->process_info.name, sizeof(this->process_info.name));
fprintf(f_report, "Process Info:\n");
fprintf(f_report, " Process Name: %s\n", name_buf);
fprintf(f_report, " Title ID: %016lx\n", this->process_info.title_id);
fprintf(f_report, " Program ID: %016lx\n", this->process_info.program_id);
fprintf(f_report, " Process ID: %016lx\n", this->process_info.process_id);
fprintf(f_report, " Process Flags: %08x\n", this->process_info.flags);
if (hos::GetVersion() >= hos::Version_500) {

View file

@ -40,7 +40,7 @@ extern "C" {
namespace ams {
ncm::TitleId CurrentTitleId = ncm::TitleId::Creport;
ncm::ProgramId CurrentProgramId = ncm::ProgramId::Creport;
namespace result {

View file

@ -61,10 +61,10 @@ namespace ams::dmnt::cheat::impl {
Result AttachToApplicationProcess(bool on_process_launch);
bool ParseCheats(const char *s, size_t len);
bool LoadCheats(const ncm::TitleId title_id, const u8 *build_id);
bool LoadCheats(const ncm::ProgramId program_id, const u8 *build_id);
bool ParseCheatToggles(const char *s, size_t len);
bool LoadCheatToggles(const ncm::TitleId title_id);
void SaveCheatToggles(const ncm::TitleId title_id);
bool LoadCheatToggles(const ncm::ProgramId program_id);
void SaveCheatToggles(const ncm::ProgramId program_id);
bool GetNeedsReloadVm() const {
return this->needs_reload_vm;
@ -131,7 +131,7 @@ namespace ams::dmnt::cheat::impl {
/* Save cheat toggles. */
if (this->always_save_cheat_toggles || this->should_save_cheat_toggles) {
this->SaveCheatToggles(this->cheat_process_metadata.title_id);
this->SaveCheatToggles(this->cheat_process_metadata.program_id);
this->should_save_cheat_toggles = false;
}
@ -622,11 +622,11 @@ namespace ams::dmnt::cheat::impl {
/* Get process handle, use it to learn memory extents. */
{
Handle proc_h = INVALID_HANDLE;
ncm::TitleLocation loc = {};
ncm::ProgramLocation loc = {};
ON_SCOPE_EXIT { if (proc_h != INVALID_HANDLE) { R_ASSERT(svcCloseHandle(proc_h)); } };
R_ASSERT_IF_NEW_PROCESS(pm::dmnt::AtmosphereGetProcessInfo(&proc_h, &loc, this->cheat_process_metadata.process_id));
this->cheat_process_metadata.title_id = loc.title_id;
this->cheat_process_metadata.program_id = loc.program_id;
{
map::AddressSpaceInfo as_info;
@ -642,16 +642,16 @@ namespace ams::dmnt::cheat::impl {
/* If new process launch, we may not want to actually attach. */
if (on_process_launch) {
R_UNLESS(cfg::IsCheatEnableKeyHeld(this->cheat_process_metadata.title_id), ResultCheatNotAttached());
R_UNLESS(cfg::IsCheatEnableKeyHeld(this->cheat_process_metadata.program_id), ResultCheatNotAttached());
}
/* Get module information from loader. */
{
LoaderModuleInfo proc_modules[2];
u32 num_modules;
s32 num_modules;
/* TODO: ldr::dmnt:: */
R_ASSERT_IF_NEW_PROCESS(ldrDmntGetModuleInfos(static_cast<u64>(this->cheat_process_metadata.process_id), proc_modules, util::size(proc_modules), &num_modules));
R_ASSERT_IF_NEW_PROCESS(ldrDmntGetProcessModuleInfo(static_cast<u64>(this->cheat_process_metadata.process_id), proc_modules, util::size(proc_modules), &num_modules));
/* All applications must have two modules. */
/* Only accept one (which means we're attaching to HBL) */
@ -671,8 +671,8 @@ namespace ams::dmnt::cheat::impl {
}
/* Read cheats off the SD. */
if (!this->LoadCheats(this->cheat_process_metadata.title_id, this->cheat_process_metadata.main_nso_build_id) ||
!this->LoadCheatToggles(this->cheat_process_metadata.title_id)) {
if (!this->LoadCheats(this->cheat_process_metadata.program_id, this->cheat_process_metadata.main_nso_build_id) ||
!this->LoadCheatToggles(this->cheat_process_metadata.program_id)) {
/* If new process launch, require success. */
R_UNLESS(!on_process_launch, ResultCheatNotAttached());
}
@ -872,15 +872,15 @@ namespace ams::dmnt::cheat::impl {
return true;
}
bool CheatProcessManager::LoadCheats(const ncm::TitleId title_id, const u8 *build_id) {
bool CheatProcessManager::LoadCheats(const ncm::ProgramId program_id, const u8 *build_id) {
/* Reset existing entries. */
this->ResetAllCheatEntries();
/* Open the file for title/build_id. */
/* Open the file for program/build_id. */
FILE *f_cht = nullptr;
{
char path[FS_MAX_PATH+1] = {0};
std::snprintf(path, FS_MAX_PATH, "sdmc:/atmosphere/titles/%016lx/cheats/%02x%02x%02x%02x%02x%02x%02x%02x.txt", static_cast<u64>(title_id),
std::snprintf(path, FS_MAX_PATH, "sdmc:/atmosphere/contents/%016lx/cheats/%02x%02x%02x%02x%02x%02x%02x%02x.txt", static_cast<u64>(program_id),
build_id[0], build_id[1], build_id[2], build_id[3], build_id[4], build_id[5], build_id[6], build_id[7]);
f_cht = fopen(path, "rb");
@ -914,12 +914,12 @@ namespace ams::dmnt::cheat::impl {
return this->ParseCheats(cht_txt, std::strlen(cht_txt));
}
bool CheatProcessManager::LoadCheatToggles(const ncm::TitleId title_id) {
/* Open the file for title_id. */
bool CheatProcessManager::LoadCheatToggles(const ncm::ProgramId program_id) {
/* Open the file for program_id. */
FILE *f_tg = nullptr;
{
char path[FS_MAX_PATH+1] = {0};
std::snprintf(path, FS_MAX_PATH, "sdmc:/atmosphere/titles/%016lx/cheats/toggles.txt", static_cast<u64>(title_id));
std::snprintf(path, FS_MAX_PATH, "sdmc:/atmosphere/contents/%016lx/cheats/toggles.txt", static_cast<u64>(program_id));
f_tg = fopen(path, "rb");
}
@ -955,12 +955,12 @@ namespace ams::dmnt::cheat::impl {
return this->should_save_cheat_toggles;
}
void CheatProcessManager::SaveCheatToggles(const ncm::TitleId title_id) {
/* Open the file for title_id. */
void CheatProcessManager::SaveCheatToggles(const ncm::ProgramId program_id) {
/* Open the file for program_id. */
FILE *f_tg = nullptr;
{
char path[FS_MAX_PATH+1] = {0};
std::snprintf(path, FS_MAX_PATH, "sdmc:/atmosphere/titles/%016lx/cheats/toggles.txt", static_cast<u64>(title_id));
std::snprintf(path, FS_MAX_PATH, "sdmc:/atmosphere/contents/%016lx/cheats/toggles.txt", static_cast<u64>(program_id));
if ((f_tg = fopen(path, "wb")) == nullptr) {
return;
}

View file

@ -35,7 +35,7 @@ extern "C" {
namespace ams {
ncm::TitleId CurrentTitleId = ncm::TitleId::Dmnt;
ncm::ProgramId CurrentProgramId = ncm::ProgramId::Dmnt;
namespace result {

View file

@ -36,7 +36,7 @@ extern "C" {
namespace ams {
ncm::TitleId CurrentTitleId = ncm::TitleId::Eclct;
ncm::ProgramId CurrentProgramId = ncm::ProgramId::Eclct;
namespace result {

View file

@ -44,7 +44,7 @@ extern "C" {
namespace ams {
ncm::TitleId CurrentTitleId = ncm::TitleId::Fatal;
ncm::ProgramId CurrentProgramId = ncm::ProgramId::Fatal;
namespace result {

View file

@ -81,9 +81,9 @@ namespace ams::fatal::srv {
this->context.cpu_ctx.aarch32_ctx.stack_trace_size = std::max(size_t(this->context.cpu_ctx.aarch32_ctx.stack_trace_size), aarch32::CpuContext::MaxStackTraceDepth);
}
/* Get title id. */
pm::info::GetTitleId(&this->context.title_id, process_id);
this->context.is_creport = (this->context.title_id == ncm::TitleId::Creport);
/* Get program id. */
pm::info::GetProgramId(&this->context.program_id, process_id);
this->context.is_creport = (this->context.program_id == ncm::ProgramId::Creport);
if (!this->context.is_creport) {
/* On firmware version 2.0.0, use debugging SVCs to collect information. */
@ -91,11 +91,11 @@ namespace ams::fatal::srv {
fatal::srv::TryCollectDebugInformation(&this->context, process_id);
}
} else {
/* We received info from creport. Parse title id from afsr0. */
/* We received info from creport. Parse program id from afsr0. */
if (cpu_ctx.architecture == CpuContext::Architecture_Aarch64) {
this->context.title_id = cpu_ctx.aarch64_ctx.GetTitleIdForAtmosphere();
this->context.program_id = cpu_ctx.aarch64_ctx.GetProgramIdForAtmosphere();
} else {
this->context.title_id = cpu_ctx.aarch32_ctx.GetTitleIdForAtmosphere();
this->context.program_id = cpu_ctx.aarch32_ctx.GetProgramIdForAtmosphere();
}
}

View file

@ -76,14 +76,14 @@ namespace ams::fatal::srv {
}
/* Open report file. */
snprintf(file_path, sizeof(file_path) - 1, "sdmc:/atmosphere/fatal_reports/%011lu_%016lx.log", timestamp, static_cast<u64>(this->context->title_id));
snprintf(file_path, sizeof(file_path) - 1, "sdmc:/atmosphere/fatal_reports/%011lu_%016lx.log", timestamp, static_cast<u64>(this->context->program_id));
FILE *f_report = fopen(file_path, "w");
if (f_report != NULL) {
ON_SCOPE_EXIT { fclose(f_report); };
fprintf(f_report, "Atmosphère Fatal Report (v1.0):\n");
fprintf(f_report, "Result: 0x%X (2%03d-%04d)\n\n", this->context->result.GetValue(), this->context->result.GetModule(), this->context->result.GetDescription());
fprintf(f_report, "Title ID: %016lx\n", static_cast<u64>(this->context->title_id));
fprintf(f_report, "Program ID: %016lx\n", static_cast<u64>(this->context->program_id));
if (strlen(this->context->proc_name)) {
fprintf(f_report, "Process Name: %s\n", this->context->proc_name);
}
@ -117,7 +117,7 @@ namespace ams::fatal::srv {
}
if (this->context->stack_dump_size) {
snprintf(file_path, sizeof(file_path) - 1, "sdmc:/atmosphere/fatal_reports/dumps/%011lu_%016lx.bin", timestamp, static_cast<u64>(this->context->title_id));
snprintf(file_path, sizeof(file_path) - 1, "sdmc:/atmosphere/fatal_reports/dumps/%011lu_%016lx.bin", timestamp, static_cast<u64>(this->context->program_id));
FILE *f_stackdump = fopen(file_path, "wb");
if (f_stackdump == NULL) { return; }
ON_SCOPE_EXIT { fclose(f_stackdump); };

View file

@ -210,7 +210,7 @@ namespace ams::fatal::srv {
font::SetFontSize(16.0f);
font::PrintFormat(config.GetErrorMessage(), this->context->result.GetModule(), this->context->result.GetDescription(), this->context->result.GetValue());
font::AddSpacingLines(0.5f);
font::PrintFormatLine("Title: %016lX", static_cast<u64>(this->context->title_id));
font::PrintFormatLine( "Program: %016lX", static_cast<u64>(this->context->program_id));
font::AddSpacingLines(0.5f);
font::PrintFormatLine(u8"Firmware: %s (Atmosphère %u.%u.%u-%s)", config.GetFirmwareVersion().display_version, ATMOSPHERE_RELEASE_VERSION, ams::GetGitRevision());
font::AddSpacingLines(1.5f);

View file

@ -29,7 +29,7 @@ namespace ams::svc {
};
struct DebugInfoAttachProcess {
u64 title_id;
u64 program_id;
u64 process_id;
char name[0xC];
u32 flags;

View file

@ -24,7 +24,7 @@
#include "stratosphere/os.hpp"
#include "stratosphere/dd.hpp"
/* Lots of things depend on NCM, for Title IDs. */
/* Lots of things depend on NCM, for Program IDs. */
#include "stratosphere/ncm.hpp"
/* At this point, just include the rest alphabetically. */

View file

@ -95,7 +95,7 @@ namespace ams {
u32 magic;
u32 error_desc;
u64 title_id;
u64 program_id;
union {
u64 gprs[32];
struct {

View file

@ -31,18 +31,18 @@ namespace ams::cfg {
void WaitSdCardInitialized();
/* Override key utilities. */
bool IsTitleOverrideKeyHeld(ncm::TitleId title_id);
bool IsHblOverrideKeyHeld(ncm::TitleId title_id);
void GetOverrideKeyHeldStatus(bool *out_hbl, bool *out_title, ncm::TitleId title_id);
bool IsCheatEnableKeyHeld(ncm::TitleId title_id);
bool IsProgramOverrideKeyHeld(ncm::ProgramId program_id);
bool IsHblOverrideKeyHeld(ncm::ProgramId program_id);
void GetOverrideKeyHeldStatus(bool *out_hbl, bool *out_program, ncm::ProgramId program_id);
bool IsCheatEnableKeyHeld(ncm::ProgramId program_id);
/* Flag utilities. */
bool HasFlag(ncm::TitleId title_id, const char *flag);
bool HasTitleSpecificFlag(ncm::TitleId title_id, const char *flag);
bool HasFlag(ncm::ProgramId program_id, const char *flag);
bool HasContentSpecificFlag(ncm::ProgramId program_id, const char *flag);
bool HasGlobalFlag(const char *flag);
/* HBL Configuration utilities. */
bool IsHblTitleId(ncm::TitleId title_id);
bool IsHblProgramId(ncm::ProgramId program_id);
bool HasHblFlag(const char *flag);
const char *GetHblPath();

View file

@ -28,7 +28,7 @@ namespace ams::dmnt::cheat {
};
os::ProcessId process_id;
ncm::TitleId title_id;
ncm::ProgramId program_id;
MemoryRegionExtents main_nso_extents;
MemoryRegionExtents heap_extents;
MemoryRegionExtents alias_extents;

View file

@ -147,14 +147,14 @@ namespace ams::fatal {
std::memset(this, 0, sizeof(*this));
}
void SetTitleIdForAtmosphere(ncm::TitleId title_id) {
/* Right now, we mux title ID in through afsr when creport. */
void SetProgramIdForAtmosphere(ncm::ProgramId program_id) {
/* Right now, we mux program ID in through afsr when creport. */
/* TODO: Better way to do this? */
this->afsr0 = static_cast<RegisterType>(title_id);
this->afsr0 = static_cast<RegisterType>(program_id);
}
ncm::TitleId GetTitleIdForAtmosphere() const {
return ncm::TitleId{this->afsr0};
ncm::ProgramId GetProgramIdForAtmosphere() const {
return ncm::ProgramId{this->afsr0};
}
void SetRegisterValue(RegisterName name, RegisterType value) {
@ -265,15 +265,15 @@ namespace ams::fatal {
std::memset(this, 0, sizeof(*this));
}
void SetTitleIdForAtmosphere(ncm::TitleId title_id) {
/* Right now, we mux title ID in through afsr when creport. */
void SetProgramIdForAtmosphere(ncm::ProgramId program_id) {
/* Right now, we mux program ID in through afsr when creport. */
/* TODO: Better way to do this? */
this->afsr0 = static_cast<RegisterType>(static_cast<u64>(title_id) >> 0);
this->afsr1 = static_cast<RegisterType>(static_cast<u64>(title_id) >> 32);
this->afsr0 = static_cast<RegisterType>(static_cast<u64>(program_id) >> 0);
this->afsr1 = static_cast<RegisterType>(static_cast<u64>(program_id) >> 32);
}
ncm::TitleId GetTitleIdForAtmosphere() const {
return ncm::TitleId{(static_cast<u64>(this->afsr1) << 32ul) | (static_cast<u64>(this->afsr0) << 0ul)};
ncm::ProgramId GetProgramIdForAtmosphere() const {
return ncm::ProgramId{(static_cast<u64>(this->afsr1) << 32ul) | (static_cast<u64>(this->afsr0) << 0ul)};
}
void SetRegisterValue(RegisterName name, RegisterType value) {
@ -319,7 +319,7 @@ namespace ams::fatal {
struct ThrowContext {
Result result;
ncm::TitleId title_id;
ncm::ProgramId program_id;
char proc_name[0xD];
bool is_creport;
CpuContext cpu_ctx;
@ -331,7 +331,7 @@ namespace ams::fatal {
void ClearState() {
this->result = ResultSuccess();
this->title_id = ncm::TitleId::Invalid;
this->program_id = ncm::ProgramId::Invalid;
std::memset(this->proc_name, 0, sizeof(this->proc_name));
this->is_creport = false;
std::memset(&this->cpu_ctx, 0, sizeof(this->cpu_ctx));

View file

@ -21,9 +21,9 @@ namespace ams::ldr::pm {
/* Process Manager API. */
Result CreateProcess(Handle *out, PinId pin_id, u32 flags, Handle reslimit);
Result GetProgramInfo(ProgramInfo *out, const ncm::TitleLocation &loc);
Result PinTitle(PinId *out, const ncm::TitleLocation &loc);
Result UnpinTitle(PinId pin_id);
Result HasLaunchedTitle(bool *out, ncm::TitleId title_id);
Result GetProgramInfo(ProgramInfo *out, const ncm::ProgramLocation &loc);
Result PinProgram(PinId *out, const ncm::ProgramLocation &loc);
Result UnpinProgram(PinId pin_id);
Result HasLaunchedProgram(bool *out, ncm::ProgramId program_id);
}

View file

@ -27,7 +27,7 @@ namespace ams::ldr {
u8 default_cpu_id;
u16 flags;
u32 main_thread_stack_size;
ncm::TitleId title_id;
ncm::ProgramId program_id;
u32 acid_sac_size;
u32 aci_sac_size;
u32 acid_fac_size;
@ -149,7 +149,7 @@ namespace ams::ldr {
u32 magic;
u8 reserved_04[0xC];
ncm::TitleId title_id;
ncm::ProgramId program_id;
u8 reserved_18[0x8];
u32 fah_offset;
u32 fah_size;
@ -188,8 +188,8 @@ namespace ams::ldr {
u8 version;
u8 reserved_209[3];
u32 flags;
ncm::TitleId title_id_min;
ncm::TitleId title_id_max;
ncm::ProgramId program_id_min;
ncm::ProgramId program_id_max;
u32 fac_offset;
u32 fac_size;
u32 sac_offset;
@ -229,7 +229,7 @@ namespace ams::ldr {
u32 system_resource_size;
u32 version;
u32 main_thread_stack_size;
char title_name[0x10];
char program_name[0x10];
char product_code[0x10];
u8 reserved_40[0x30];
u32 aci_offset;

View file

@ -30,169 +30,169 @@ namespace ams::ncm {
SdCard = 5,
};
/* Title IDs. */
struct TitleId {
/* Program IDs (Formerly: Title IDs). */
struct ProgramId {
u64 value;
inline explicit operator u64() const {
return this->value;
}
/* Invalid Title ID. */
static const TitleId Invalid;
/* Invalid Program ID. */
static const ProgramId Invalid;
/* System Modules. */
static const TitleId SystemStart;
static const ProgramId SystemStart;
static const TitleId Fs;
static const TitleId Loader;
static const TitleId Ncm;
static const TitleId Pm;
static const TitleId Sm;
static const TitleId Boot;
static const TitleId Usb;
static const TitleId Tma;
static const TitleId Boot2;
static const TitleId Settings;
static const TitleId Bus;
static const TitleId Bluetooth;
static const TitleId Bcat;
static const TitleId Dmnt;
static const TitleId Friends;
static const TitleId Nifm;
static const TitleId Ptm;
static const TitleId Shell;
static const TitleId BsdSockets;
static const TitleId Hid;
static const TitleId Audio;
static const TitleId LogManager;
static const TitleId Wlan;
static const TitleId Cs;
static const TitleId Ldn;
static const TitleId NvServices;
static const TitleId Pcv;
static const TitleId Ppc;
static const TitleId NvnFlinger;
static const TitleId Pcie;
static const TitleId Account;
static const TitleId Ns;
static const TitleId Nfc;
static const TitleId Psc;
static const TitleId CapSrv;
static const TitleId Am;
static const TitleId Ssl;
static const TitleId Nim;
static const TitleId Cec;
static const TitleId Tspm;
static const TitleId Spl;
static const TitleId Lbl;
static const TitleId Btm;
static const TitleId Erpt;
static const TitleId Time;
static const TitleId Vi;
static const TitleId Pctl;
static const TitleId Npns;
static const TitleId Eupld;
static const TitleId Arp;
static const TitleId Glue;
static const TitleId Eclct;
static const TitleId Es;
static const TitleId Fatal;
static const TitleId Grc;
static const TitleId Creport;
static const TitleId Ro;
static const TitleId Profiler;
static const TitleId Sdb;
static const TitleId Migration;
static const TitleId Jit;
static const TitleId JpegDec;
static const TitleId SafeMode;
static const TitleId Olsc;
static const TitleId Dt;
static const TitleId Nd;
static const TitleId Ngct;
static const ProgramId Fs;
static const ProgramId Loader;
static const ProgramId Ncm;
static const ProgramId Pm;
static const ProgramId Sm;
static const ProgramId Boot;
static const ProgramId Usb;
static const ProgramId Tma;
static const ProgramId Boot2;
static const ProgramId Settings;
static const ProgramId Bus;
static const ProgramId Bluetooth;
static const ProgramId Bcat;
static const ProgramId Dmnt;
static const ProgramId Friends;
static const ProgramId Nifm;
static const ProgramId Ptm;
static const ProgramId Shell;
static const ProgramId BsdSockets;
static const ProgramId Hid;
static const ProgramId Audio;
static const ProgramId LogManager;
static const ProgramId Wlan;
static const ProgramId Cs;
static const ProgramId Ldn;
static const ProgramId NvServices;
static const ProgramId Pcv;
static const ProgramId Ppc;
static const ProgramId NvnFlinger;
static const ProgramId Pcie;
static const ProgramId Account;
static const ProgramId Ns;
static const ProgramId Nfc;
static const ProgramId Psc;
static const ProgramId CapSrv;
static const ProgramId Am;
static const ProgramId Ssl;
static const ProgramId Nim;
static const ProgramId Cec;
static const ProgramId Tspm;
static const ProgramId Spl;
static const ProgramId Lbl;
static const ProgramId Btm;
static const ProgramId Erpt;
static const ProgramId Time;
static const ProgramId Vi;
static const ProgramId Pctl;
static const ProgramId Npns;
static const ProgramId Eupld;
static const ProgramId Arp;
static const ProgramId Glue;
static const ProgramId Eclct;
static const ProgramId Es;
static const ProgramId Fatal;
static const ProgramId Grc;
static const ProgramId Creport;
static const ProgramId Ro;
static const ProgramId Profiler;
static const ProgramId Sdb;
static const ProgramId Migration;
static const ProgramId Jit;
static const ProgramId JpegDec;
static const ProgramId SafeMode;
static const ProgramId Olsc;
static const ProgramId Dt;
static const ProgramId Nd;
static const ProgramId Ngct;
static const TitleId SystemEnd;
static const ProgramId SystemEnd;
/* System Data Archives. */
static const TitleId ArchiveStart;
static const TitleId ArchiveCertStore;
static const TitleId ArchiveErrorMessage;
static const TitleId ArchiveMiiModel;
static const TitleId ArchiveBrowserDll;
static const TitleId ArchiveHelp;
static const TitleId ArchiveSharedFont;
static const TitleId ArchiveNgWord;
static const TitleId ArchiveSsidList;
static const TitleId ArchiveDictionary;
static const TitleId ArchiveSystemVersion;
static const TitleId ArchiveAvatarImage;
static const TitleId ArchiveLocalNews;
static const TitleId ArchiveEula;
static const TitleId ArchiveUrlBlackList;
static const TitleId ArchiveTimeZoneBinar;
static const TitleId ArchiveCertStoreCruiser;
static const TitleId ArchiveFontNintendoExtension;
static const TitleId ArchiveFontStandard;
static const TitleId ArchiveFontKorean;
static const TitleId ArchiveFontChineseTraditional;
static const TitleId ArchiveFontChineseSimple;
static const TitleId ArchiveFontBfcpx;
static const TitleId ArchiveSystemUpdate;
static const ProgramId ArchiveStart;
static const ProgramId ArchiveCertStore;
static const ProgramId ArchiveErrorMessage;
static const ProgramId ArchiveMiiModel;
static const ProgramId ArchiveBrowserDll;
static const ProgramId ArchiveHelp;
static const ProgramId ArchiveSharedFont;
static const ProgramId ArchiveNgWord;
static const ProgramId ArchiveSsidList;
static const ProgramId ArchiveDictionary;
static const ProgramId ArchiveSystemVersion;
static const ProgramId ArchiveAvatarImage;
static const ProgramId ArchiveLocalNews;
static const ProgramId ArchiveEula;
static const ProgramId ArchiveUrlBlackList;
static const ProgramId ArchiveTimeZoneBinar;
static const ProgramId ArchiveCertStoreCruiser;
static const ProgramId ArchiveFontNintendoExtension;
static const ProgramId ArchiveFontStandard;
static const ProgramId ArchiveFontKorean;
static const ProgramId ArchiveFontChineseTraditional;
static const ProgramId ArchiveFontChineseSimple;
static const ProgramId ArchiveFontBfcpx;
static const ProgramId ArchiveSystemUpdate;
static const TitleId ArchiveFirmwareDebugSettings;
static const TitleId ArchiveBootImagePackage;
static const TitleId ArchiveBootImagePackageSafe;
static const TitleId ArchiveBootImagePackageExFat;
static const TitleId ArchiveBootImagePackageExFatSafe;
static const TitleId ArchiveFatalMessage;
static const TitleId ArchiveControllerIcon;
static const TitleId ArchivePlatformConfigIcosa;
static const TitleId ArchivePlatformConfigCopper;
static const TitleId ArchivePlatformConfigHoag;
static const TitleId ArchiveControllerFirmware;
static const TitleId ArchiveNgWord2;
static const TitleId ArchivePlatformConfigIcosaMariko;
static const TitleId ArchiveApplicationBlackList;
static const TitleId ArchiveRebootlessSystemUpdateVersion;
static const TitleId ArchiveContentActionTable;
static const ProgramId ArchiveFirmwareDebugSettings;
static const ProgramId ArchiveBootImagePackage;
static const ProgramId ArchiveBootImagePackageSafe;
static const ProgramId ArchiveBootImagePackageExFat;
static const ProgramId ArchiveBootImagePackageExFatSafe;
static const ProgramId ArchiveFatalMessage;
static const ProgramId ArchiveControllerIcon;
static const ProgramId ArchivePlatformConfigIcosa;
static const ProgramId ArchivePlatformConfigCopper;
static const ProgramId ArchivePlatformConfigHoag;
static const ProgramId ArchiveControllerFirmware;
static const ProgramId ArchiveNgWord2;
static const ProgramId ArchivePlatformConfigIcosaMariko;
static const ProgramId ArchiveApplicationBlackList;
static const ProgramId ArchiveRebootlessSystemUpdateVersion;
static const ProgramId ArchiveContentActionTable;
static const TitleId ArchiveEnd;
static const ProgramId ArchiveEnd;
/* System Applets. */
static const TitleId AppletStart;
static const ProgramId AppletStart;
static const TitleId AppletQlaunch;
static const TitleId AppletAuth;
static const TitleId AppletCabinet;
static const TitleId AppletController;
static const TitleId AppletDataErase;
static const TitleId AppletError;
static const TitleId AppletNetConnect;
static const TitleId AppletPlayerSelect;
static const TitleId AppletSwkbd;
static const TitleId AppletMiiEdit;
static const TitleId AppletWeb;
static const TitleId AppletShop;
static const TitleId AppletOverlayDisp;
static const TitleId AppletPhotoViewer;
static const TitleId AppletSet;
static const TitleId AppletOfflineWeb;
static const TitleId AppletLoginShare;
static const TitleId AppletWifiWebAuth;
static const TitleId AppletStarter;
static const TitleId AppletMyPage;
static const TitleId AppletPlayReport;
static const TitleId AppletMaintenanceMenu;
static const ProgramId AppletQlaunch;
static const ProgramId AppletAuth;
static const ProgramId AppletCabinet;
static const ProgramId AppletController;
static const ProgramId AppletDataErase;
static const ProgramId AppletError;
static const ProgramId AppletNetConnect;
static const ProgramId AppletPlayerSelect;
static const ProgramId AppletSwkbd;
static const ProgramId AppletMiiEdit;
static const ProgramId AppletWeb;
static const ProgramId AppletShop;
static const ProgramId AppletOverlayDisp;
static const ProgramId AppletPhotoViewer;
static const ProgramId AppletSet;
static const ProgramId AppletOfflineWeb;
static const ProgramId AppletLoginShare;
static const ProgramId AppletWifiWebAuth;
static const ProgramId AppletStarter;
static const ProgramId AppletMyPage;
static const ProgramId AppletPlayReport;
static const ProgramId AppletMaintenanceMenu;
static const TitleId AppletGift;
static const TitleId AppletDummyShop;
static const TitleId AppletUserMigration;
static const TitleId AppletEncounter;
static const ProgramId AppletGift;
static const ProgramId AppletDummyShop;
static const ProgramId AppletUserMigration;
static const ProgramId AppletEncounter;
static const TitleId AppletStory;
static const ProgramId AppletStory;
static const TitleId AppletEnd;
static const ProgramId AppletEnd;
/* Debug Applets. */
@ -201,168 +201,170 @@ namespace ams::ncm {
/* Factory Setup. */
/* Applications. */
static const TitleId ApplicationStart;
static const TitleId ApplicationEnd;
static const ProgramId ApplicationStart;
static const ProgramId ApplicationEnd;
/* Atmosphere Extensions. */
static const TitleId AtmosphereMitm;
static const ProgramId AtmosphereMitm;
};
/* Invalid Title ID. */
inline constexpr const TitleId TitleId::Invalid = {};
/* Invalid Program ID. */
inline constexpr const ProgramId ProgramId::Invalid = {};
inline constexpr const ProgramId InvalidProgramId = ProgramId::Invalid;
/* System Modules. */
inline constexpr const TitleId TitleId::SystemStart = { 0x0100000000000000ul };
inline constexpr const ProgramId ProgramId::SystemStart = { 0x0100000000000000ul };
inline constexpr const TitleId TitleId::Fs = { 0x0100000000000000ul };
inline constexpr const TitleId TitleId::Loader = { 0x0100000000000001ul };
inline constexpr const TitleId TitleId::Ncm = { 0x0100000000000002ul };
inline constexpr const TitleId TitleId::Pm = { 0x0100000000000003ul };
inline constexpr const TitleId TitleId::Sm = { 0x0100000000000004ul };
inline constexpr const TitleId TitleId::Boot = { 0x0100000000000005ul };
inline constexpr const TitleId TitleId::Usb = { 0x0100000000000006ul };
inline constexpr const TitleId TitleId::Tma = { 0x0100000000000007ul };
inline constexpr const TitleId TitleId::Boot2 = { 0x0100000000000008ul };
inline constexpr const TitleId TitleId::Settings = { 0x0100000000000009ul };
inline constexpr const TitleId TitleId::Bus = { 0x010000000000000Aul };
inline constexpr const TitleId TitleId::Bluetooth = { 0x010000000000000Bul };
inline constexpr const TitleId TitleId::Bcat = { 0x010000000000000Cul };
inline constexpr const TitleId TitleId::Dmnt = { 0x010000000000000Dul };
inline constexpr const TitleId TitleId::Friends = { 0x010000000000000Eul };
inline constexpr const TitleId TitleId::Nifm = { 0x010000000000000Ful };
inline constexpr const TitleId TitleId::Ptm = { 0x0100000000000010ul };
inline constexpr const TitleId TitleId::Shell = { 0x0100000000000011ul };
inline constexpr const TitleId TitleId::BsdSockets = { 0x0100000000000012ul };
inline constexpr const TitleId TitleId::Hid = { 0x0100000000000013ul };
inline constexpr const TitleId TitleId::Audio = { 0x0100000000000014ul };
inline constexpr const TitleId TitleId::LogManager = { 0x0100000000000015ul };
inline constexpr const TitleId TitleId::Wlan = { 0x0100000000000016ul };
inline constexpr const TitleId TitleId::Cs = { 0x0100000000000017ul };
inline constexpr const TitleId TitleId::Ldn = { 0x0100000000000018ul };
inline constexpr const TitleId TitleId::NvServices = { 0x0100000000000019ul };
inline constexpr const TitleId TitleId::Pcv = { 0x010000000000001Aul };
inline constexpr const TitleId TitleId::Ppc = { 0x010000000000001Bul };
inline constexpr const TitleId TitleId::NvnFlinger = { 0x010000000000001Cul };
inline constexpr const TitleId TitleId::Pcie = { 0x010000000000001Dul };
inline constexpr const TitleId TitleId::Account = { 0x010000000000001Eul };
inline constexpr const TitleId TitleId::Ns = { 0x010000000000001Ful };
inline constexpr const TitleId TitleId::Nfc = { 0x0100000000000020ul };
inline constexpr const TitleId TitleId::Psc = { 0x0100000000000021ul };
inline constexpr const TitleId TitleId::CapSrv = { 0x0100000000000022ul };
inline constexpr const TitleId TitleId::Am = { 0x0100000000000023ul };
inline constexpr const TitleId TitleId::Ssl = { 0x0100000000000024ul };
inline constexpr const TitleId TitleId::Nim = { 0x0100000000000025ul };
inline constexpr const TitleId TitleId::Cec = { 0x0100000000000026ul };
inline constexpr const TitleId TitleId::Tspm = { 0x0100000000000027ul };
inline constexpr const TitleId TitleId::Spl = { 0x0100000000000028ul };
inline constexpr const TitleId TitleId::Lbl = { 0x0100000000000029ul };
inline constexpr const TitleId TitleId::Btm = { 0x010000000000002Aul };
inline constexpr const TitleId TitleId::Erpt = { 0x010000000000002Bul };
inline constexpr const TitleId TitleId::Time = { 0x010000000000002Cul };
inline constexpr const TitleId TitleId::Vi = { 0x010000000000002Dul };
inline constexpr const TitleId TitleId::Pctl = { 0x010000000000002Eul };
inline constexpr const TitleId TitleId::Npns = { 0x010000000000002Ful };
inline constexpr const TitleId TitleId::Eupld = { 0x0100000000000030ul };
inline constexpr const TitleId TitleId::Arp = { 0x0100000000000031ul };
inline constexpr const TitleId TitleId::Glue = { 0x0100000000000031ul };
inline constexpr const TitleId TitleId::Eclct = { 0x0100000000000032ul };
inline constexpr const TitleId TitleId::Es = { 0x0100000000000033ul };
inline constexpr const TitleId TitleId::Fatal = { 0x0100000000000034ul };
inline constexpr const TitleId TitleId::Grc = { 0x0100000000000035ul };
inline constexpr const TitleId TitleId::Creport = { 0x0100000000000036ul };
inline constexpr const TitleId TitleId::Ro = { 0x0100000000000037ul };
inline constexpr const TitleId TitleId::Profiler = { 0x0100000000000038ul };
inline constexpr const TitleId TitleId::Sdb = { 0x0100000000000039ul };
inline constexpr const TitleId TitleId::Migration = { 0x010000000000003Aul };
inline constexpr const TitleId TitleId::Jit = { 0x010000000000003Bul };
inline constexpr const TitleId TitleId::JpegDec = { 0x010000000000003Cul };
inline constexpr const TitleId TitleId::SafeMode = { 0x010000000000003Dul };
inline constexpr const TitleId TitleId::Olsc = { 0x010000000000003Eul };
inline constexpr const TitleId TitleId::Dt = { 0x010000000000003Ful };
inline constexpr const TitleId TitleId::Nd = { 0x0100000000000040ul };
inline constexpr const TitleId TitleId::Ngct = { 0x0100000000000041ul };
inline constexpr const ProgramId ProgramId::Fs = { 0x0100000000000000ul };
inline constexpr const ProgramId ProgramId::Loader = { 0x0100000000000001ul };
inline constexpr const ProgramId ProgramId::Ncm = { 0x0100000000000002ul };
inline constexpr const ProgramId ProgramId::Pm = { 0x0100000000000003ul };
inline constexpr const ProgramId ProgramId::Sm = { 0x0100000000000004ul };
inline constexpr const ProgramId ProgramId::Boot = { 0x0100000000000005ul };
inline constexpr const ProgramId ProgramId::Usb = { 0x0100000000000006ul };
inline constexpr const ProgramId ProgramId::Tma = { 0x0100000000000007ul };
inline constexpr const ProgramId ProgramId::Boot2 = { 0x0100000000000008ul };
inline constexpr const ProgramId ProgramId::Settings = { 0x0100000000000009ul };
inline constexpr const ProgramId ProgramId::Bus = { 0x010000000000000Aul };
inline constexpr const ProgramId ProgramId::Bluetooth = { 0x010000000000000Bul };
inline constexpr const ProgramId ProgramId::Bcat = { 0x010000000000000Cul };
inline constexpr const ProgramId ProgramId::Dmnt = { 0x010000000000000Dul };
inline constexpr const ProgramId ProgramId::Friends = { 0x010000000000000Eul };
inline constexpr const ProgramId ProgramId::Nifm = { 0x010000000000000Ful };
inline constexpr const ProgramId ProgramId::Ptm = { 0x0100000000000010ul };
inline constexpr const ProgramId ProgramId::Shell = { 0x0100000000000011ul };
inline constexpr const ProgramId ProgramId::BsdSockets = { 0x0100000000000012ul };
inline constexpr const ProgramId ProgramId::Hid = { 0x0100000000000013ul };
inline constexpr const ProgramId ProgramId::Audio = { 0x0100000000000014ul };
inline constexpr const ProgramId ProgramId::LogManager = { 0x0100000000000015ul };
inline constexpr const ProgramId ProgramId::Wlan = { 0x0100000000000016ul };
inline constexpr const ProgramId ProgramId::Cs = { 0x0100000000000017ul };
inline constexpr const ProgramId ProgramId::Ldn = { 0x0100000000000018ul };
inline constexpr const ProgramId ProgramId::NvServices = { 0x0100000000000019ul };
inline constexpr const ProgramId ProgramId::Pcv = { 0x010000000000001Aul };
inline constexpr const ProgramId ProgramId::Ppc = { 0x010000000000001Bul };
inline constexpr const ProgramId ProgramId::NvnFlinger = { 0x010000000000001Cul };
inline constexpr const ProgramId ProgramId::Pcie = { 0x010000000000001Dul };
inline constexpr const ProgramId ProgramId::Account = { 0x010000000000001Eul };
inline constexpr const ProgramId ProgramId::Ns = { 0x010000000000001Ful };
inline constexpr const ProgramId ProgramId::Nfc = { 0x0100000000000020ul };
inline constexpr const ProgramId ProgramId::Psc = { 0x0100000000000021ul };
inline constexpr const ProgramId ProgramId::CapSrv = { 0x0100000000000022ul };
inline constexpr const ProgramId ProgramId::Am = { 0x0100000000000023ul };
inline constexpr const ProgramId ProgramId::Ssl = { 0x0100000000000024ul };
inline constexpr const ProgramId ProgramId::Nim = { 0x0100000000000025ul };
inline constexpr const ProgramId ProgramId::Cec = { 0x0100000000000026ul };
inline constexpr const ProgramId ProgramId::Tspm = { 0x0100000000000027ul };
inline constexpr const ProgramId ProgramId::Spl = { 0x0100000000000028ul };
inline constexpr const ProgramId ProgramId::Lbl = { 0x0100000000000029ul };
inline constexpr const ProgramId ProgramId::Btm = { 0x010000000000002Aul };
inline constexpr const ProgramId ProgramId::Erpt = { 0x010000000000002Bul };
inline constexpr const ProgramId ProgramId::Time = { 0x010000000000002Cul };
inline constexpr const ProgramId ProgramId::Vi = { 0x010000000000002Dul };
inline constexpr const ProgramId ProgramId::Pctl = { 0x010000000000002Eul };
inline constexpr const ProgramId ProgramId::Npns = { 0x010000000000002Ful };
inline constexpr const ProgramId ProgramId::Eupld = { 0x0100000000000030ul };
inline constexpr const ProgramId ProgramId::Arp = { 0x0100000000000031ul };
inline constexpr const ProgramId ProgramId::Glue = { 0x0100000000000031ul };
inline constexpr const ProgramId ProgramId::Eclct = { 0x0100000000000032ul };
inline constexpr const ProgramId ProgramId::Es = { 0x0100000000000033ul };
inline constexpr const ProgramId ProgramId::Fatal = { 0x0100000000000034ul };
inline constexpr const ProgramId ProgramId::Grc = { 0x0100000000000035ul };
inline constexpr const ProgramId ProgramId::Creport = { 0x0100000000000036ul };
inline constexpr const ProgramId ProgramId::Ro = { 0x0100000000000037ul };
inline constexpr const ProgramId ProgramId::Profiler = { 0x0100000000000038ul };
inline constexpr const ProgramId ProgramId::Sdb = { 0x0100000000000039ul };
inline constexpr const ProgramId ProgramId::Migration = { 0x010000000000003Aul };
inline constexpr const ProgramId ProgramId::Jit = { 0x010000000000003Bul };
inline constexpr const ProgramId ProgramId::JpegDec = { 0x010000000000003Cul };
inline constexpr const ProgramId ProgramId::SafeMode = { 0x010000000000003Dul };
inline constexpr const ProgramId ProgramId::Olsc = { 0x010000000000003Eul };
inline constexpr const ProgramId ProgramId::Dt = { 0x010000000000003Ful };
inline constexpr const ProgramId ProgramId::Nd = { 0x0100000000000040ul };
inline constexpr const ProgramId ProgramId::Ngct = { 0x0100000000000041ul };
inline constexpr const TitleId TitleId::SystemEnd = { 0x01000000000007FFul };
inline constexpr const ProgramId ProgramId::SystemEnd = { 0x01000000000007FFul };
/* System Data Archives. */
inline constexpr const TitleId TitleId::ArchiveStart = { 0x0100000000000800ul };
inline constexpr const TitleId TitleId::ArchiveCertStore = { 0x0100000000000800ul };
inline constexpr const TitleId TitleId::ArchiveErrorMessage = { 0x0100000000000801ul };
inline constexpr const TitleId TitleId::ArchiveMiiModel = { 0x0100000000000802ul };
inline constexpr const TitleId TitleId::ArchiveBrowserDll = { 0x0100000000000803ul };
inline constexpr const TitleId TitleId::ArchiveHelp = { 0x0100000000000804ul };
inline constexpr const TitleId TitleId::ArchiveSharedFont = { 0x0100000000000805ul };
inline constexpr const TitleId TitleId::ArchiveNgWord = { 0x0100000000000806ul };
inline constexpr const TitleId TitleId::ArchiveSsidList = { 0x0100000000000807ul };
inline constexpr const TitleId TitleId::ArchiveDictionary = { 0x0100000000000808ul };
inline constexpr const TitleId TitleId::ArchiveSystemVersion = { 0x0100000000000809ul };
inline constexpr const TitleId TitleId::ArchiveAvatarImage = { 0x010000000000080Aul };
inline constexpr const TitleId TitleId::ArchiveLocalNews = { 0x010000000000080Bul };
inline constexpr const TitleId TitleId::ArchiveEula = { 0x010000000000080Cul };
inline constexpr const TitleId TitleId::ArchiveUrlBlackList = { 0x010000000000080Dul };
inline constexpr const TitleId TitleId::ArchiveTimeZoneBinar = { 0x010000000000080Eul };
inline constexpr const TitleId TitleId::ArchiveCertStoreCruiser = { 0x010000000000080Ful };
inline constexpr const TitleId TitleId::ArchiveFontNintendoExtension = { 0x0100000000000810ul };
inline constexpr const TitleId TitleId::ArchiveFontStandard = { 0x0100000000000811ul };
inline constexpr const TitleId TitleId::ArchiveFontKorean = { 0x0100000000000812ul };
inline constexpr const TitleId TitleId::ArchiveFontChineseTraditional = { 0x0100000000000813ul };
inline constexpr const TitleId TitleId::ArchiveFontChineseSimple = { 0x0100000000000814ul };
inline constexpr const TitleId TitleId::ArchiveFontBfcpx = { 0x0100000000000815ul };
inline constexpr const TitleId TitleId::ArchiveSystemUpdate = { 0x0100000000000816ul };
inline constexpr const ProgramId ProgramId::ArchiveStart = { 0x0100000000000800ul };
inline constexpr const ProgramId ProgramId::ArchiveCertStore = { 0x0100000000000800ul };
inline constexpr const ProgramId ProgramId::ArchiveErrorMessage = { 0x0100000000000801ul };
inline constexpr const ProgramId ProgramId::ArchiveMiiModel = { 0x0100000000000802ul };
inline constexpr const ProgramId ProgramId::ArchiveBrowserDll = { 0x0100000000000803ul };
inline constexpr const ProgramId ProgramId::ArchiveHelp = { 0x0100000000000804ul };
inline constexpr const ProgramId ProgramId::ArchiveSharedFont = { 0x0100000000000805ul };
inline constexpr const ProgramId ProgramId::ArchiveNgWord = { 0x0100000000000806ul };
inline constexpr const ProgramId ProgramId::ArchiveSsidList = { 0x0100000000000807ul };
inline constexpr const ProgramId ProgramId::ArchiveDictionary = { 0x0100000000000808ul };
inline constexpr const ProgramId ProgramId::ArchiveSystemVersion = { 0x0100000000000809ul };
inline constexpr const ProgramId ProgramId::ArchiveAvatarImage = { 0x010000000000080Aul };
inline constexpr const ProgramId ProgramId::ArchiveLocalNews = { 0x010000000000080Bul };
inline constexpr const ProgramId ProgramId::ArchiveEula = { 0x010000000000080Cul };
inline constexpr const ProgramId ProgramId::ArchiveUrlBlackList = { 0x010000000000080Dul };
inline constexpr const ProgramId ProgramId::ArchiveTimeZoneBinar = { 0x010000000000080Eul };
inline constexpr const ProgramId ProgramId::ArchiveCertStoreCruiser = { 0x010000000000080Ful };
inline constexpr const ProgramId ProgramId::ArchiveFontNintendoExtension = { 0x0100000000000810ul };
inline constexpr const ProgramId ProgramId::ArchiveFontStandard = { 0x0100000000000811ul };
inline constexpr const ProgramId ProgramId::ArchiveFontKorean = { 0x0100000000000812ul };
inline constexpr const ProgramId ProgramId::ArchiveFontChineseTraditional = { 0x0100000000000813ul };
inline constexpr const ProgramId ProgramId::ArchiveFontChineseSimple = { 0x0100000000000814ul };
inline constexpr const ProgramId ProgramId::ArchiveFontBfcpx = { 0x0100000000000815ul };
inline constexpr const ProgramId ProgramId::ArchiveSystemUpdate = { 0x0100000000000816ul };
inline constexpr const TitleId TitleId::ArchiveFirmwareDebugSettings = { 0x0100000000000818ul };
inline constexpr const TitleId TitleId::ArchiveBootImagePackage = { 0x0100000000000819ul };
inline constexpr const TitleId TitleId::ArchiveBootImagePackageSafe = { 0x010000000000081Aul };
inline constexpr const TitleId TitleId::ArchiveBootImagePackageExFat = { 0x010000000000081Bul };
inline constexpr const TitleId TitleId::ArchiveBootImagePackageExFatSafe = { 0x010000000000081Cul };
inline constexpr const TitleId TitleId::ArchiveFatalMessage = { 0x010000000000081Dul };
inline constexpr const TitleId TitleId::ArchiveControllerIcon = { 0x010000000000081Eul };
inline constexpr const TitleId TitleId::ArchivePlatformConfigIcosa = { 0x010000000000081Ful };
inline constexpr const TitleId TitleId::ArchivePlatformConfigCopper = { 0x0100000000000820ul };
inline constexpr const TitleId TitleId::ArchivePlatformConfigHoag = { 0x0100000000000821ul };
inline constexpr const TitleId TitleId::ArchiveControllerFirmware = { 0x0100000000000822ul };
inline constexpr const TitleId TitleId::ArchiveNgWord2 = { 0x0100000000000823ul };
inline constexpr const TitleId TitleId::ArchivePlatformConfigIcosaMariko = { 0x0100000000000824ul };
inline constexpr const TitleId TitleId::ArchiveApplicationBlackList = { 0x0100000000000825ul };
inline constexpr const TitleId TitleId::ArchiveRebootlessSystemUpdateVersion = { 0x0100000000000826ul };
inline constexpr const TitleId TitleId::ArchiveContentActionTable = { 0x0100000000000827ul };
inline constexpr const ProgramId ProgramId::ArchiveFirmwareDebugSettings = { 0x0100000000000818ul };
inline constexpr const ProgramId ProgramId::ArchiveBootImagePackage = { 0x0100000000000819ul };
inline constexpr const ProgramId ProgramId::ArchiveBootImagePackageSafe = { 0x010000000000081Aul };
inline constexpr const ProgramId ProgramId::ArchiveBootImagePackageExFat = { 0x010000000000081Bul };
inline constexpr const ProgramId ProgramId::ArchiveBootImagePackageExFatSafe = { 0x010000000000081Cul };
inline constexpr const ProgramId ProgramId::ArchiveFatalMessage = { 0x010000000000081Dul };
inline constexpr const ProgramId ProgramId::ArchiveControllerIcon = { 0x010000000000081Eul };
inline constexpr const ProgramId ProgramId::ArchivePlatformConfigIcosa = { 0x010000000000081Ful };
inline constexpr const ProgramId ProgramId::ArchivePlatformConfigCopper = { 0x0100000000000820ul };
inline constexpr const ProgramId ProgramId::ArchivePlatformConfigHoag = { 0x0100000000000821ul };
inline constexpr const ProgramId ProgramId::ArchiveControllerFirmware = { 0x0100000000000822ul };
inline constexpr const ProgramId ProgramId::ArchiveNgWord2 = { 0x0100000000000823ul };
inline constexpr const ProgramId ProgramId::ArchivePlatformConfigIcosaMariko = { 0x0100000000000824ul };
inline constexpr const ProgramId ProgramId::ArchiveApplicationBlackList = { 0x0100000000000825ul };
inline constexpr const ProgramId ProgramId::ArchiveRebootlessSystemUpdateVersion = { 0x0100000000000826ul };
inline constexpr const ProgramId ProgramId::ArchiveContentActionTable = { 0x0100000000000827ul };
inline constexpr const TitleId TitleId::ArchiveEnd = { 0x0100000000000FFFul };
inline constexpr const ProgramId ProgramId::ArchiveEnd = { 0x0100000000000FFFul };
/* System Applets. */
inline constexpr const TitleId TitleId::AppletStart = { 0x0100000000001000ul };
inline constexpr const ProgramId ProgramId::AppletStart = { 0x0100000000001000ul };
inline constexpr const TitleId TitleId::AppletQlaunch = { 0x0100000000001000ul };
inline constexpr const TitleId TitleId::AppletAuth = { 0x0100000000001001ul };
inline constexpr const TitleId TitleId::AppletCabinet = { 0x0100000000001002ul };
inline constexpr const TitleId TitleId::AppletController = { 0x0100000000001003ul };
inline constexpr const TitleId TitleId::AppletDataErase = { 0x0100000000001004ul };
inline constexpr const TitleId TitleId::AppletError = { 0x0100000000001005ul };
inline constexpr const TitleId TitleId::AppletNetConnect = { 0x0100000000001006ul };
inline constexpr const TitleId TitleId::AppletPlayerSelect = { 0x0100000000001007ul };
inline constexpr const TitleId TitleId::AppletSwkbd = { 0x0100000000001008ul };
inline constexpr const TitleId TitleId::AppletMiiEdit = { 0x0100000000001009ul };
inline constexpr const TitleId TitleId::AppletWeb = { 0x010000000000100Aul };
inline constexpr const TitleId TitleId::AppletShop = { 0x010000000000100Bul };
inline constexpr const TitleId TitleId::AppletOverlayDisp = { 0x010000000000100Cul };
inline constexpr const TitleId TitleId::AppletPhotoViewer = { 0x010000000000100Dul };
inline constexpr const TitleId TitleId::AppletSet = { 0x010000000000100Eul };
inline constexpr const TitleId TitleId::AppletOfflineWeb = { 0x010000000000100Ful };
inline constexpr const TitleId TitleId::AppletLoginShare = { 0x0100000000001010ul };
inline constexpr const TitleId TitleId::AppletWifiWebAuth = { 0x0100000000001011ul };
inline constexpr const TitleId TitleId::AppletStarter = { 0x0100000000001012ul };
inline constexpr const TitleId TitleId::AppletMyPage = { 0x0100000000001013ul };
inline constexpr const TitleId TitleId::AppletPlayReport = { 0x0100000000001014ul };
inline constexpr const TitleId TitleId::AppletMaintenanceMenu = { 0x0100000000001015ul };
inline constexpr const ProgramId ProgramId::AppletQlaunch = { 0x0100000000001000ul };
inline constexpr const ProgramId ProgramId::AppletAuth = { 0x0100000000001001ul };
inline constexpr const ProgramId ProgramId::AppletCabinet = { 0x0100000000001002ul };
inline constexpr const ProgramId ProgramId::AppletController = { 0x0100000000001003ul };
inline constexpr const ProgramId ProgramId::AppletDataErase = { 0x0100000000001004ul };
inline constexpr const ProgramId ProgramId::AppletError = { 0x0100000000001005ul };
inline constexpr const ProgramId ProgramId::AppletNetConnect = { 0x0100000000001006ul };
inline constexpr const ProgramId ProgramId::AppletPlayerSelect = { 0x0100000000001007ul };
inline constexpr const ProgramId ProgramId::AppletSwkbd = { 0x0100000000001008ul };
inline constexpr const ProgramId ProgramId::AppletMiiEdit = { 0x0100000000001009ul };
inline constexpr const ProgramId ProgramId::AppletWeb = { 0x010000000000100Aul };
inline constexpr const ProgramId ProgramId::AppletShop = { 0x010000000000100Bul };
inline constexpr const ProgramId ProgramId::AppletOverlayDisp = { 0x010000000000100Cul };
inline constexpr const ProgramId ProgramId::AppletPhotoViewer = { 0x010000000000100Dul };
inline constexpr const ProgramId ProgramId::AppletSet = { 0x010000000000100Eul };
inline constexpr const ProgramId ProgramId::AppletOfflineWeb = { 0x010000000000100Ful };
inline constexpr const ProgramId ProgramId::AppletLoginShare = { 0x0100000000001010ul };
inline constexpr const ProgramId ProgramId::AppletWifiWebAuth = { 0x0100000000001011ul };
inline constexpr const ProgramId ProgramId::AppletStarter = { 0x0100000000001012ul };
inline constexpr const ProgramId ProgramId::AppletMyPage = { 0x0100000000001013ul };
inline constexpr const ProgramId ProgramId::AppletPlayReport = { 0x0100000000001014ul };
inline constexpr const ProgramId ProgramId::AppletMaintenanceMenu = { 0x0100000000001015ul };
inline constexpr const TitleId TitleId::AppletGift = { 0x010000000000101Aul };
inline constexpr const TitleId TitleId::AppletDummyShop = { 0x010000000000101Bul };
inline constexpr const TitleId TitleId::AppletUserMigration = { 0x010000000000101Cul };
inline constexpr const TitleId TitleId::AppletEncounter = { 0x010000000000101Dul };
inline constexpr const ProgramId ProgramId::AppletGift = { 0x010000000000101Aul };
inline constexpr const ProgramId ProgramId::AppletDummyShop = { 0x010000000000101Bul };
inline constexpr const ProgramId ProgramId::AppletUserMigration = { 0x010000000000101Cul };
inline constexpr const ProgramId ProgramId::AppletEncounter = { 0x010000000000101Dul };
inline constexpr const TitleId TitleId::AppletStory = { 0x0100000000001020ul };
inline constexpr const ProgramId ProgramId::AppletStory = { 0x0100000000001020ul };
inline constexpr const TitleId TitleId::AppletEnd = { 0x0100000000001FFFul };
inline constexpr const ProgramId ProgramId::AppletEnd = { 0x0100000000001FFFul };
/* Debug Applets. */
@ -371,64 +373,65 @@ namespace ams::ncm {
/* Factory Setup. */
/* Applications. */
inline constexpr const TitleId TitleId::ApplicationStart = { 0x0100000000010000ul };
inline constexpr const TitleId TitleId::ApplicationEnd = { 0x01FFFFFFFFFFFFFFul };
inline constexpr const ProgramId ProgramId::ApplicationStart = { 0x0100000000010000ul };
inline constexpr const ProgramId ProgramId::ApplicationEnd = { 0x01FFFFFFFFFFFFFFul };
/* Atmosphere Extensions. */
inline constexpr const TitleId TitleId::AtmosphereMitm = { 0x010041544D530000ul };
inline constexpr const ProgramId ProgramId::AtmosphereMitm = { 0x010041544D530000ul };
inline constexpr bool operator==(const TitleId &lhs, const TitleId &rhs) {
inline constexpr bool operator==(const ProgramId &lhs, const ProgramId &rhs) {
return lhs.value == rhs.value;
}
inline constexpr bool operator!=(const TitleId &lhs, const TitleId &rhs) {
inline constexpr bool operator!=(const ProgramId &lhs, const ProgramId &rhs) {
return lhs.value != rhs.value;
}
inline constexpr bool operator<(const TitleId &lhs, const TitleId &rhs) {
inline constexpr bool operator<(const ProgramId &lhs, const ProgramId &rhs) {
return lhs.value < rhs.value;
}
inline constexpr bool operator<=(const TitleId &lhs, const TitleId &rhs) {
inline constexpr bool operator<=(const ProgramId &lhs, const ProgramId &rhs) {
return lhs.value <= rhs.value;
}
inline constexpr bool operator>(const TitleId &lhs, const TitleId &rhs) {
inline constexpr bool operator>(const ProgramId &lhs, const ProgramId &rhs) {
return lhs.value > rhs.value;
}
inline constexpr bool operator>=(const TitleId &lhs, const TitleId &rhs) {
inline constexpr bool operator>=(const ProgramId &lhs, const ProgramId &rhs) {
return lhs.value >= rhs.value;
}
inline constexpr bool IsSystemTitleId(const TitleId &title_id) {
return TitleId::SystemStart <= title_id && title_id <= TitleId::SystemEnd;
inline constexpr bool IsSystemProgramId(const ProgramId &program_id) {
return ProgramId::SystemStart <= program_id && program_id <= ProgramId::SystemEnd;
}
inline constexpr bool IsArchiveTitleId(const TitleId &title_id) {
return TitleId::ArchiveStart <= title_id && title_id <= TitleId::ArchiveEnd;
inline constexpr bool IsArchiveProgramId(const ProgramId &program_id) {
return ProgramId::ArchiveStart <= program_id && program_id <= ProgramId::ArchiveEnd;
}
inline constexpr bool IsAppletTitleId(const TitleId &title_id) {
return TitleId::AppletStart <= title_id && title_id <= TitleId::AppletEnd;
inline constexpr bool IsAppletProgramId(const ProgramId &program_id) {
return ProgramId::AppletStart <= program_id && program_id <= ProgramId::AppletEnd;
}
inline constexpr bool IsApplicationTitleId(const TitleId &title_id) {
return TitleId::ApplicationStart <= title_id && title_id <= TitleId::ApplicationEnd;
inline constexpr bool IsApplicationProgramId(const ProgramId &program_id) {
return ProgramId::ApplicationStart <= program_id && program_id <= ProgramId::ApplicationEnd;
}
static_assert(sizeof(TitleId) == sizeof(u64) && std::is_pod<TitleId>::value, "TitleId definition!");
static_assert(sizeof(ProgramId) == sizeof(u64) && std::is_pod<ProgramId>::value, "ProgramId definition!");
/* Title Location. */
struct TitleLocation {
TitleId title_id;
/* Program Location. */
struct ProgramLocation {
ProgramId program_id;
u8 storage_id;
static constexpr TitleLocation Make(TitleId title_id, StorageId storage_id) {
return { .title_id = title_id, .storage_id = static_cast<u8>(storage_id), };
static constexpr ProgramLocation Make(ProgramId program_id, StorageId storage_id) {
return { .program_id = program_id, .storage_id = static_cast<u8>(storage_id), };
}
};
static_assert(sizeof(TitleLocation) == 0x10 && std::is_pod<TitleLocation>::value, "TitleLocation definition!");
static_assert(sizeof(ProgramLocation) == 0x10 && std::is_pod<ProgramLocation>::value, "ProgramLocation definition!");
static_assert(sizeof(ProgramLocation) == sizeof(::NcmProgramLocation) && alignof(ProgramLocation) == alignof(::NcmProgramLocation), "ProgramLocation Libnx Compatibility");
}

View file

@ -23,10 +23,10 @@ namespace ams::pm::dmnt {
/* Debug Monitor API. */
Result StartProcess(os::ProcessId process_id);
Result GetProcessId(os::ProcessId *out_process_id, const ncm::TitleId title_id);
Result GetProcessId(os::ProcessId *out_process_id, const ncm::ProgramId program_id);
Result GetApplicationProcessId(os::ProcessId *out_process_id);
Result HookToCreateApplicationProcess(Handle *out_handle);
Result AtmosphereGetProcessInfo(Handle *out_handle, ncm::TitleLocation *out_loc, os::ProcessId process_id);
Result AtmosphereGetProcessInfo(Handle *out_handle, ncm::ProgramLocation *out_loc, os::ProcessId process_id);
Result AtmosphereGetCurrentLimitInfo(u64 *out_current_value, u64 *out_limit_value, ResourceLimitGroup group, LimitableResource resource);
}

View file

@ -22,11 +22,11 @@
namespace ams::pm::info {
/* Information API. */
Result GetTitleId(ncm::TitleId *out_title_id, os::ProcessId process_id);
Result GetProcessId(os::ProcessId *out_process_id, ncm::TitleId title_id);
Result HasLaunchedTitle(bool *out, ncm::TitleId title_id);
Result GetProgramId(ncm::ProgramId *out_program_id, os::ProcessId process_id);
Result GetProcessId(os::ProcessId *out_process_id, ncm::ProgramId program_id);
Result HasLaunchedProgram(bool *out, ncm::ProgramId program_id);
/* Information convenience API. */
bool HasLaunchedTitle(ncm::TitleId title_id);
bool HasLaunchedProgram(ncm::ProgramId program_id);
}

View file

@ -22,6 +22,6 @@
namespace ams::pm::shell {
/* Shell API. */
Result LaunchTitle(os::ProcessId *out_process_id, const ncm::TitleLocation &loc, u32 launch_flags);
Result LaunchProgram(os::ProcessId *out_process_id, const ncm::ProgramLocation &loc, u32 launch_flags);
}

View file

@ -37,13 +37,13 @@ namespace ams::ro {
private:
u32 magic;
u8 reserved_04[0xC];
u64 title_id_mask;
u64 title_id_pattern;
u64 program_id_mask;
u64 program_id_pattern;
u8 reserved_20[0x10];
u8 modulus[0x100];
u8 fixed_key_signature[0x100];
u8 nrr_signature[0x100];
ncm::TitleId title_id;
ncm::ProgramId program_id;
u32 size;
u8 type; /* 7.0.0+ */
u8 reserved_33D[3];
@ -55,8 +55,8 @@ namespace ams::ro {
return this->magic == Magic;
}
bool IsTitleIdValid() const {
return (static_cast<u64>(this->title_id) & this->title_id_mask) == this->title_id_pattern;
bool IsProgramIdValid() const {
return (static_cast<u64>(this->program_id) & this->program_id_mask) == this->program_id_pattern;
}
ModuleType GetType() const {
@ -65,8 +65,8 @@ namespace ams::ro {
return type;
}
ncm::TitleId GetTitleId() const {
return this->title_id;
ncm::ProgramId GetProgramId() const {
return this->program_id;
}
u32 GetSize() const {

View file

@ -104,9 +104,9 @@ namespace ams::sf::hipc {
std::shared_ptr<::Service> forward_service = std::move(ServerSession::CreateForwardService());
/* Get mitm forward session. */
os::ProcessId client_pid;
ncm::TitleId client_tid;
R_ASSERT(sm::mitm::AcknowledgeSession(forward_service.get(), &client_pid, &client_tid, this->service_name));
os::ProcessId client_process_id;
ncm::ProgramId client_program_id;
R_ASSERT(sm::mitm::AcknowledgeSession(forward_service.get(), &client_process_id, &client_program_id, this->service_name));
*out_obj = std::move(cmif::ServiceObjectHolder(std::move(MakeShared(forward_service))));
*out_fsrv = std::move(forward_service);

View file

@ -26,11 +26,11 @@ namespace ams::sf {
protected:
std::shared_ptr<::Service> forward_service;
os::ProcessId process_id;
ncm::TitleId title_id;
ncm::ProgramId program_id;
public:
IMitmServiceObject(std::shared_ptr<::Service> &&s, os::ProcessId p, ncm::TitleId t) : forward_service(std::move(s)), process_id(p), title_id(t) { /* ... */ }
IMitmServiceObject(std::shared_ptr<::Service> &&s, os::ProcessId p, ncm::ProgramId r) : forward_service(std::move(s)), process_id(p), program_id(r) { /* ... */ }
static bool ShouldMitm(os::ProcessId process_id, ncm::TitleId title_id);
static bool ShouldMitm(os::ProcessId process_id, ncm::ProgramId program_id);
};
template<typename T>

View file

@ -23,7 +23,7 @@
namespace ams::sm::manager {
/* Manager API. */
Result RegisterProcess(os::ProcessId process_id, ncm::TitleId title_id, const void *acid, size_t acid_size, const void *aci, size_t aci_size);
Result RegisterProcess(os::ProcessId process_id, ncm::ProgramId program_id, const void *acid, size_t acid_size, const void *aci, size_t aci_size);
Result UnregisterProcess(os::ProcessId process_id);
/* Atmosphere extensions. */

View file

@ -25,7 +25,7 @@ namespace ams::sm::mitm {
Result InstallMitm(Handle *out_port, Handle *out_query, ServiceName name);
Result UninstallMitm(ServiceName name);
Result DeclareFutureMitm(ServiceName name);
Result AcknowledgeSession(Service *out_service, os::ProcessId *out_pid, ncm::TitleId *out_tid, ServiceName name);
Result AcknowledgeSession(Service *out_service, os::ProcessId *out_process_id, ncm::ProgramId *out_program_id, ServiceName name);
Result HasMitm(bool *out, ServiceName name);
Result WaitMitm(ServiceName name);

View file

@ -56,10 +56,10 @@ namespace ams::sm {
/* For Debug Monitor extensions. */
struct ServiceRecord {
ServiceName service;
os::ProcessId owner_pid;
os::ProcessId owner_process_id;
u64 max_sessions;
os::ProcessId mitm_pid;
os::ProcessId mitm_waiting_ack_pid;
os::ProcessId mitm_process_id;
os::ProcessId mitm_waiting_ack_process_id;
bool is_light;
bool mitm_waiting_ack;
};

View file

@ -34,7 +34,7 @@ namespace ams {
}
extern ncm::TitleId CurrentTitleId;
extern ncm::ProgramId CurrentProgramId;
void WEAK ExceptionHandler(FatalErrorContext *ctx) {
R_ASSERT(amsBpcInitialize());
@ -49,7 +49,7 @@ namespace ams {
{
ams_ctx.magic = FatalErrorContext::Magic;
ams_ctx.error_desc = ctx->error_desc;
ams_ctx.title_id = static_cast<u64>(CurrentTitleId);
ams_ctx.program_id = static_cast<u64>(CurrentProgramId);
for (size_t i = 0; i < FatalErrorContext::NumGprs; i++) {
ams_ctx.gprs[i] = ctx->cpu_gprs[i].x;
}

View file

@ -22,101 +22,101 @@ namespace ams::boot2 {
/* Launch lists. */
/* psc, bus, pcv is the minimal set of required titles to get SD card. */
/* psc, bus, pcv is the minimal set of required programs to get SD card. */
/* bus depends on pcie, and pcv depends on settings. */
constexpr ncm::TitleId PreSdCardLaunchPrograms[] = {
ncm::TitleId::Psc, /* psc */
ncm::TitleId::Pcie, /* pcie */
ncm::TitleId::Bus, /* bus */
ncm::TitleId::Settings, /* settings */
ncm::TitleId::Pcv, /* pcv */
ncm::TitleId::Usb, /* usb */
constexpr ncm::ProgramId PreSdCardLaunchPrograms[] = {
ncm::ProgramId::Psc, /* psc */
ncm::ProgramId::Pcie, /* pcie */
ncm::ProgramId::Bus, /* bus */
ncm::ProgramId::Settings, /* settings */
ncm::ProgramId::Pcv, /* pcv */
ncm::ProgramId::Usb, /* usb */
};
constexpr size_t NumPreSdCardLaunchPrograms = util::size(PreSdCardLaunchPrograms);
constexpr ncm::TitleId AdditionalLaunchPrograms[] = {
ncm::TitleId::Tma, /* tma */
ncm::TitleId::Am, /* am */
ncm::TitleId::NvServices, /* nvservices */
ncm::TitleId::NvnFlinger, /* nvnflinger */
ncm::TitleId::Vi, /* vi */
ncm::TitleId::Ns, /* ns */
ncm::TitleId::LogManager, /* lm */
ncm::TitleId::Ppc, /* ppc */
ncm::TitleId::Ptm, /* ptm */
ncm::TitleId::Hid, /* hid */
ncm::TitleId::Audio, /* audio */
ncm::TitleId::Lbl, /* lbl */
ncm::TitleId::Wlan, /* wlan */
ncm::TitleId::Bluetooth, /* bluetooth */
ncm::TitleId::BsdSockets, /* bsdsockets */
ncm::TitleId::Nifm, /* nifm */
ncm::TitleId::Ldn, /* ldn */
ncm::TitleId::Account, /* account */
ncm::TitleId::Friends, /* friends */
ncm::TitleId::Nfc, /* nfc */
ncm::TitleId::JpegDec, /* jpegdec */
ncm::TitleId::CapSrv, /* capsrv */
ncm::TitleId::Ssl, /* ssl */
ncm::TitleId::Nim, /* nim */
ncm::TitleId::Bcat, /* bcat */
ncm::TitleId::Erpt, /* erpt */
ncm::TitleId::Es, /* es */
ncm::TitleId::Pctl, /* pctl */
ncm::TitleId::Btm, /* btm */
ncm::TitleId::Eupld, /* eupld */
ncm::TitleId::Glue, /* glue */
/* ncm::TitleId::Eclct, */ /* eclct */ /* Skip launching error collection in Atmosphere to lessen telemetry. */
ncm::TitleId::Npns, /* npns */
ncm::TitleId::Fatal, /* fatal */
ncm::TitleId::Ro, /* ro */
ncm::TitleId::Profiler, /* profiler */
ncm::TitleId::Sdb, /* sdb */
ncm::TitleId::Migration, /* migration */
ncm::TitleId::Grc, /* grc */
ncm::TitleId::Olsc, /* olsc */
ncm::TitleId::Ngct, /* ngct */
constexpr ncm::ProgramId AdditionalLaunchPrograms[] = {
ncm::ProgramId::Tma, /* tma */
ncm::ProgramId::Am, /* am */
ncm::ProgramId::NvServices, /* nvservices */
ncm::ProgramId::NvnFlinger, /* nvnflinger */
ncm::ProgramId::Vi, /* vi */
ncm::ProgramId::Ns, /* ns */
ncm::ProgramId::LogManager, /* lm */
ncm::ProgramId::Ppc, /* ppc */
ncm::ProgramId::Ptm, /* ptm */
ncm::ProgramId::Hid, /* hid */
ncm::ProgramId::Audio, /* audio */
ncm::ProgramId::Lbl, /* lbl */
ncm::ProgramId::Wlan, /* wlan */
ncm::ProgramId::Bluetooth, /* bluetooth */
ncm::ProgramId::BsdSockets, /* bsdsockets */
ncm::ProgramId::Nifm, /* nifm */
ncm::ProgramId::Ldn, /* ldn */
ncm::ProgramId::Account, /* account */
ncm::ProgramId::Friends, /* friends */
ncm::ProgramId::Nfc, /* nfc */
ncm::ProgramId::JpegDec, /* jpegdec */
ncm::ProgramId::CapSrv, /* capsrv */
ncm::ProgramId::Ssl, /* ssl */
ncm::ProgramId::Nim, /* nim */
ncm::ProgramId::Bcat, /* bcat */
ncm::ProgramId::Erpt, /* erpt */
ncm::ProgramId::Es, /* es */
ncm::ProgramId::Pctl, /* pctl */
ncm::ProgramId::Btm, /* btm */
ncm::ProgramId::Eupld, /* eupld */
ncm::ProgramId::Glue, /* glue */
/* ncm::ProgramId::Eclct, */ /* eclct */ /* Skip launching error collection in Atmosphere to lessen telemetry. */
ncm::ProgramId::Npns, /* npns */
ncm::ProgramId::Fatal, /* fatal */
ncm::ProgramId::Ro, /* ro */
ncm::ProgramId::Profiler, /* profiler */
ncm::ProgramId::Sdb, /* sdb */
ncm::ProgramId::Migration, /* migration */
ncm::ProgramId::Grc, /* grc */
ncm::ProgramId::Olsc, /* olsc */
ncm::ProgramId::Ngct, /* ngct */
};
constexpr size_t NumAdditionalLaunchPrograms = util::size(AdditionalLaunchPrograms);
constexpr ncm::TitleId AdditionalMaintenanceLaunchPrograms[] = {
ncm::TitleId::Tma, /* tma */
ncm::TitleId::Am, /* am */
ncm::TitleId::NvServices, /* nvservices */
ncm::TitleId::NvnFlinger, /* nvnflinger */
ncm::TitleId::Vi, /* vi */
ncm::TitleId::Ns, /* ns */
ncm::TitleId::LogManager, /* lm */
ncm::TitleId::Ppc, /* ppc */
ncm::TitleId::Ptm, /* ptm */
ncm::TitleId::Hid, /* hid */
ncm::TitleId::Audio, /* audio */
ncm::TitleId::Lbl, /* lbl */
ncm::TitleId::Wlan, /* wlan */
ncm::TitleId::Bluetooth, /* bluetooth */
ncm::TitleId::BsdSockets, /* bsdsockets */
ncm::TitleId::Nifm, /* nifm */
ncm::TitleId::Ldn, /* ldn */
ncm::TitleId::Account, /* account */
ncm::TitleId::Nfc, /* nfc */
ncm::TitleId::JpegDec, /* jpegdec */
ncm::TitleId::CapSrv, /* capsrv */
ncm::TitleId::Ssl, /* ssl */
ncm::TitleId::Nim, /* nim */
ncm::TitleId::Erpt, /* erpt */
ncm::TitleId::Es, /* es */
ncm::TitleId::Pctl, /* pctl */
ncm::TitleId::Btm, /* btm */
ncm::TitleId::Glue, /* glue */
/* ncm::TitleId::Eclct, */ /* eclct */ /* Skip launching error collection in Atmosphere to lessen telemetry. */
ncm::TitleId::Fatal, /* fatal */
ncm::TitleId::Ro, /* ro */
ncm::TitleId::Profiler, /* profiler */
ncm::TitleId::Sdb, /* sdb */
ncm::TitleId::Migration, /* migration */
ncm::TitleId::Grc, /* grc */
ncm::TitleId::Olsc, /* olsc */
ncm::TitleId::Ngct, /* ngct */
constexpr ncm::ProgramId AdditionalMaintenanceLaunchPrograms[] = {
ncm::ProgramId::Tma, /* tma */
ncm::ProgramId::Am, /* am */
ncm::ProgramId::NvServices, /* nvservices */
ncm::ProgramId::NvnFlinger, /* nvnflinger */
ncm::ProgramId::Vi, /* vi */
ncm::ProgramId::Ns, /* ns */
ncm::ProgramId::LogManager, /* lm */
ncm::ProgramId::Ppc, /* ppc */
ncm::ProgramId::Ptm, /* ptm */
ncm::ProgramId::Hid, /* hid */
ncm::ProgramId::Audio, /* audio */
ncm::ProgramId::Lbl, /* lbl */
ncm::ProgramId::Wlan, /* wlan */
ncm::ProgramId::Bluetooth, /* bluetooth */
ncm::ProgramId::BsdSockets, /* bsdsockets */
ncm::ProgramId::Nifm, /* nifm */
ncm::ProgramId::Ldn, /* ldn */
ncm::ProgramId::Account, /* account */
ncm::ProgramId::Nfc, /* nfc */
ncm::ProgramId::JpegDec, /* jpegdec */
ncm::ProgramId::CapSrv, /* capsrv */
ncm::ProgramId::Ssl, /* ssl */
ncm::ProgramId::Nim, /* nim */
ncm::ProgramId::Erpt, /* erpt */
ncm::ProgramId::Es, /* es */
ncm::ProgramId::Pctl, /* pctl */
ncm::ProgramId::Btm, /* btm */
ncm::ProgramId::Glue, /* glue */
/* ncm::ProgramId::Eclct, */ /* eclct */ /* Skip launching error collection in Atmosphere to lessen telemetry. */
ncm::ProgramId::Fatal, /* fatal */
ncm::ProgramId::Ro, /* ro */
ncm::ProgramId::Profiler, /* profiler */
ncm::ProgramId::Sdb, /* sdb */
ncm::ProgramId::Migration, /* migration */
ncm::ProgramId::Grc, /* grc */
ncm::ProgramId::Olsc, /* olsc */
ncm::ProgramId::Ngct, /* ngct */
};
constexpr size_t NumAdditionalMaintenanceLaunchPrograms = util::size(AdditionalMaintenanceLaunchPrograms);
@ -134,12 +134,12 @@ namespace ams::boot2 {
return c == '\r' || c == '\n';
}
void LaunchTitle(os::ProcessId *out_process_id, const ncm::TitleLocation &loc, u32 launch_flags) {
void LaunchProgram(os::ProcessId *out_process_id, const ncm::ProgramLocation &loc, u32 launch_flags) {
os::ProcessId process_id = os::InvalidProcessId;
/* Launch, lightly validate result. */
{
const auto launch_result = pm::shell::LaunchTitle(&process_id, loc, launch_flags);
const auto launch_result = pm::shell::LaunchProgram(&process_id, loc, launch_flags);
AMS_ASSERT(!(svc::ResultOutOfResource::Includes(launch_result)));
AMS_ASSERT(!(svc::ResultOutOfMemory::Includes(launch_result)));
AMS_ASSERT(!(svc::ResultLimitReached::Includes(launch_result)));
@ -150,9 +150,9 @@ namespace ams::boot2 {
}
}
void LaunchList(const ncm::TitleId *launch_list, size_t num_entries) {
void LaunchList(const ncm::ProgramId *launch_list, size_t num_entries) {
for (size_t i = 0; i < num_entries; i++) {
LaunchTitle(nullptr, ncm::TitleLocation::Make(launch_list[i], ncm::StorageId::NandSystem), 0);
LaunchProgram(nullptr, ncm::ProgramLocation::Make(launch_list[i], ncm::StorageId::NandSystem), 0);
}
}
@ -190,35 +190,35 @@ namespace ams::boot2 {
}
template<typename F>
void IterateOverFlaggedTitlesOnSdCard(F f) {
/* Validate that the titles directory exists. */
DIR *titles_dir = opendir("sdmc:/atmosphere/titles");
if (titles_dir == nullptr) {
void IterateOverFlaggedProgramsOnSdCard(F f) {
/* Validate that the contents directory exists. */
DIR *contents_dir = opendir("sdmc:/atmosphere/contents");
if (contents_dir == nullptr) {
return;
}
ON_SCOPE_EXIT { closedir(titles_dir); };
ON_SCOPE_EXIT { closedir(contents_dir); };
/* Iterate over entries in the titles directory */
/* Iterate over entries in the contents directory */
struct dirent *ent;
while ((ent = readdir(titles_dir)) != nullptr) {
/* Check that the subdirectory can be converted to a title id. */
if (std::strlen(ent->d_name) == 2 * sizeof(ncm::TitleId) && IsHexadecimal(ent->d_name)) {
/* Check if we've already launched the title. */
ncm::TitleId title_id{std::strtoul(ent->d_name, nullptr, 16)};
while ((ent = readdir(contents_dir)) != nullptr) {
/* Check that the subdirectory can be converted to a program id. */
if (std::strlen(ent->d_name) == 2 * sizeof(ncm::ProgramId) && IsHexadecimal(ent->d_name)) {
/* Check if we've already launched the program. */
ncm::ProgramId program_id{std::strtoul(ent->d_name, nullptr, 16)};
/* Check if the title is flagged. */
if (!cfg::HasTitleSpecificFlag(title_id, "boot2")) {
/* Check if the program is flagged. */
if (!cfg::HasContentSpecificFlag(program_id, "boot2")) {
continue;
}
/* Call the iteration callback. */
f(title_id);
f(program_id);
}
}
}
void DetectAndDeclareFutureMitms() {
IterateOverFlaggedTitlesOnSdCard([](ncm::TitleId title_id) {
IterateOverFlaggedProgramsOnSdCard([](ncm::ProgramId program_id) {
/* When we find a flagged program, check if it has a mitm list. */
char mitm_list[0x400];
size_t mitm_list_size = 0;
@ -226,7 +226,7 @@ namespace ams::boot2 {
/* Read the mitm list off the SD card. */
{
char path[FS_MAX_PATH];
std::snprintf(mitm_list, sizeof(mitm_list), "sdmc:/atmosphere/titles/%016lx/mitm.lst", static_cast<u64>(title_id));
std::snprintf(mitm_list, sizeof(mitm_list), "sdmc:/atmosphere/contents/%016lx/mitm.lst", static_cast<u64>(program_id));
FILE *f = fopen(path, "rb");
if (f == nullptr) {
return;
@ -278,14 +278,14 @@ namespace ams::boot2 {
}
void LaunchFlaggedProgramsOnSdCard() {
IterateOverFlaggedTitlesOnSdCard([](ncm::TitleId title_id) {
/* Check if we've already launched the title. */
if (pm::info::HasLaunchedTitle(title_id)) {
IterateOverFlaggedProgramsOnSdCard([](ncm::ProgramId program_id) {
/* Check if we've already launched the program. */
if (pm::info::HasLaunchedProgram(program_id)) {
return;
}
/* Launch the title. */
LaunchTitle(nullptr, ncm::TitleLocation::Make(title_id, ncm::StorageId::None), 0);
/* Launch the program. */
LaunchProgram(nullptr, ncm::ProgramLocation::Make(program_id, ncm::StorageId::None), 0);
});
}
@ -314,7 +314,7 @@ namespace ams::boot2 {
}
/* Launch Atmosphere boot2, using FsStorageId_None to force SD card boot. */
LaunchTitle(nullptr, ncm::TitleLocation::Make(ncm::TitleId::Boot2, ncm::StorageId::None), 0);
LaunchProgram(nullptr, ncm::ProgramLocation::Make(ncm::ProgramId::Boot2, ncm::StorageId::None), 0);
}
void LaunchPostSdCardBootPrograms() {
@ -327,7 +327,7 @@ namespace ams::boot2 {
}
/* Launch Atmosphere dmnt, using FsStorageId_None to force SD card boot. */
LaunchTitle(nullptr, ncm::TitleLocation::Make(ncm::TitleId::Dmnt, ncm::StorageId::None), 0);
LaunchProgram(nullptr, ncm::ProgramLocation::Make(ncm::ProgramId::Dmnt, ncm::StorageId::None), 0);
/* Check for and forward declare non-atmosphere mitm modules. */
DetectAndDeclareFutureMitms();
@ -337,7 +337,7 @@ namespace ams::boot2 {
LaunchList(AdditionalMaintenanceLaunchPrograms, NumAdditionalMaintenanceLaunchPrograms);
/* Starting in 7.0.0, npns is launched during maintenance boot. */
if (hos::GetVersion() >= hos::Version_700) {
LaunchTitle(nullptr, ncm::TitleLocation::Make(ncm::TitleId::Npns, ncm::StorageId::NandSystem), 0);
LaunchProgram(nullptr, ncm::ProgramLocation::Make(ncm::ProgramId::Npns, ncm::StorageId::NandSystem), 0);
}
} else {
LaunchList(AdditionalLaunchPrograms, NumAdditionalLaunchPrograms);

View file

@ -47,20 +47,20 @@ namespace ams::cfg {
}
/* Flag utilities. */
bool HasFlag(ncm::TitleId title_id, const char *flag) {
return HasTitleSpecificFlag(title_id, flag) || (IsHblTitleId(title_id) && HasHblFlag(flag));
bool HasFlag(ncm::ProgramId program_id, const char *flag) {
return HasContentSpecificFlag(program_id, flag) || (IsHblProgramId(program_id) && HasHblFlag(flag));
}
bool HasTitleSpecificFlag(ncm::TitleId title_id, const char *flag) {
char title_flag[FS_MAX_PATH];
std::snprintf(title_flag, sizeof(title_flag) - 1, "/atmosphere/titles/%016lx/flags/%s.flag", static_cast<u64>(title_id), flag);
return HasFlagFile(title_flag);
bool HasContentSpecificFlag(ncm::ProgramId program_id, const char *flag) {
char content_flag[FS_MAX_PATH];
std::snprintf(content_flag, sizeof(content_flag) - 1, "/atmosphere/contents/%016lx/flags/%s.flag", static_cast<u64>(program_id), flag);
return HasFlagFile(content_flag);
}
bool HasGlobalFlag(const char *flag) {
char title_flag[FS_MAX_PATH];
std::snprintf(title_flag, sizeof(title_flag) - 1, "/atmosphere/flags/%s.flag", flag);
return HasFlagFile(title_flag);
char global_flag[FS_MAX_PATH];
std::snprintf(global_flag, sizeof(global_flag) - 1, "/atmosphere/flags/%s.flag", flag);
return HasFlagFile(global_flag);
}
bool HasHblFlag(const char *flag) {

View file

@ -28,11 +28,11 @@ namespace ams::cfg {
struct HblOverrideConfig {
OverrideKey override_key;
ncm::TitleId title_id;
ncm::ProgramId program_id;
bool override_any_app;
};
struct TitleSpecificOverrideConfig {
struct ContentSpecificOverrideConfig {
OverrideKey override_key;
OverrideKey cheat_enable_key;
};
@ -53,7 +53,7 @@ namespace ams::cfg {
.key_combination = KEY_R,
.override_by_default = false,
},
.title_id = ncm::TitleId::AppletPhotoViewer,
.program_id = ncm::ProgramId::AppletPhotoViewer,
.override_any_app = true,
};
@ -114,10 +114,11 @@ namespace ams::cfg {
int LoaderIniHandler(void *user, const char *section, const char *name, const char *value) {
/* Taken and modified, with love, from Rajkosto's implementation. */
if (strcasecmp(section, "hbl_config") == 0) {
if (strcasecmp(name, "title_id") == 0) {
u64 override_tid = strtoul(value, NULL, 16);
if (override_tid != 0) {
g_hbl_override_config.title_id = {override_tid};
/* TODO: Consider deprecating "title_id" string in the future." */
if (strcasecmp(name, "program_id") == 0 || strcasecmp(name, "title_id") == 0) {
u64 override_program_id = strtoul(value, NULL, 16);
if (override_program_id != 0) {
g_hbl_override_config.program_id = {override_program_id};
}
} else if (strcasecmp(name, "path") == 0) {
while (*value == '/' || *value == '\\') {
@ -148,8 +149,8 @@ namespace ams::cfg {
return 1;
}
int TitleSpecificIniHandler(void *user, const char *section, const char *name, const char *value) {
TitleSpecificOverrideConfig *config = reinterpret_cast<TitleSpecificOverrideConfig *>(user);
int ContentSpecificIniHandler(void *user, const char *section, const char *name, const char *value) {
ContentSpecificOverrideConfig *config = reinterpret_cast<ContentSpecificOverrideConfig *>(user);
if (strcasecmp(section, "override_config") == 0) {
if (strcasecmp(name, "override_key") == 0) {
@ -163,7 +164,7 @@ namespace ams::cfg {
return 1;
}
bool IsOverrideKeyHeld(OverrideKey *cfg) {
bool IsOverrideKeyHeld(const OverrideKey *cfg) {
u64 kHeld = 0;
bool keys_triggered = (R_SUCCEEDED(hid::GetKeysHeld(&kHeld)) && ((kHeld & cfg->key_combination) != 0));
return IsSdCardInitialized() && (cfg->override_by_default ^ keys_triggered);
@ -192,28 +193,28 @@ namespace ams::cfg {
ParseIniFile(LoaderIniHandler, "/atmosphere/loader.ini", nullptr);
}
TitleSpecificOverrideConfig GetTitleOverrideConfig(ncm::TitleId title_id) {
ContentSpecificOverrideConfig GetContentOverrideConfig(ncm::ProgramId program_id) {
char path[FS_MAX_PATH];
std::snprintf(path, sizeof(path) - 1, "/atmosphere/titles/%016lx/config.ini", static_cast<u64>(title_id));
std::snprintf(path, sizeof(path) - 1, "/atmosphere/contents/%016lx/config.ini", static_cast<u64>(program_id));
TitleSpecificOverrideConfig config = {
ContentSpecificOverrideConfig config = {
.override_key = g_default_override_key,
.cheat_enable_key = g_default_cheat_enable_key,
};
ParseIniFile(TitleSpecificIniHandler, path, &config);
ParseIniFile(ContentSpecificIniHandler, path, &config);
return config;
}
}
bool IsHblOverrideKeyHeld(ncm::TitleId title_id) {
bool IsHblOverrideKeyHeld(ncm::ProgramId program_id) {
/* If the SD card isn't initialized, we can't override. */
if (!IsSdCardInitialized()) {
return false;
}
/* For system modules and anything launched before the home menu, always override. */
if (title_id < ncm::TitleId::AppletStart || !pm::info::HasLaunchedTitle(ncm::TitleId::AppletQlaunch)) {
if (program_id < ncm::ProgramId::AppletStart || !pm::info::HasLaunchedProgram(ncm::ProgramId::AppletQlaunch)) {
return true;
}
@ -221,40 +222,40 @@ namespace ams::cfg {
RefreshLoaderConfiguration();
/* Check HBL config. */
return IsHblTitleId(title_id) && IsOverrideKeyHeld(&g_hbl_override_config.override_key);
return IsHblProgramId(program_id) && IsOverrideKeyHeld(&g_hbl_override_config.override_key);
}
bool IsTitleOverrideKeyHeld(ncm::TitleId title_id) {
bool IsProgramOverrideKeyHeld(ncm::ProgramId program_id) {
/* If the SD card isn't initialized, we can't override. */
if (!IsSdCardInitialized()) {
return false;
}
/* For system modules and anything launched before the home menu, always override. */
if (title_id < ncm::TitleId::AppletStart || !pm::info::HasLaunchedTitle(ncm::TitleId::AppletQlaunch)) {
if (program_id < ncm::ProgramId::AppletStart || !pm::info::HasLaunchedProgram(ncm::ProgramId::AppletQlaunch)) {
return true;
}
/* Unconditionally refresh loader.ini contents. */
RefreshLoaderConfiguration();
TitleSpecificOverrideConfig title_cfg = GetTitleOverrideConfig(title_id);
return IsOverrideKeyHeld(&title_cfg.override_key);
const auto content_cfg = GetContentOverrideConfig(program_id);
return IsOverrideKeyHeld(&content_cfg.override_key);
}
void GetOverrideKeyHeldStatus(bool *out_hbl, bool *out_title, ncm::TitleId title_id) {
void GetOverrideKeyHeldStatus(bool *out_hbl, bool *out_program, ncm::ProgramId program_id) {
/* If the SD card isn't initialized, we can't override. */
if (!IsSdCardInitialized()) {
*out_hbl = false;
*out_title = false;
*out_program = false;
return;
}
/* For system modules and anything launched before the home menu, always override. */
if (title_id < ncm::TitleId::AppletStart || !pm::info::HasLaunchedTitle(ncm::TitleId::AppletQlaunch)) {
if (program_id < ncm::ProgramId::AppletStart || !pm::info::HasLaunchedProgram(ncm::ProgramId::AppletQlaunch)) {
*out_hbl = false;
*out_title = true;
*out_program = true;
return;
}
@ -262,31 +263,31 @@ namespace ams::cfg {
RefreshLoaderConfiguration();
/* Set HBL output. */
*out_hbl = IsHblTitleId(title_id) && IsOverrideKeyHeld(&g_hbl_override_config.override_key);
*out_hbl = IsHblProgramId(program_id) && IsOverrideKeyHeld(&g_hbl_override_config.override_key);
/* Set title specific output. */
TitleSpecificOverrideConfig title_cfg = GetTitleOverrideConfig(title_id);
*out_title = IsOverrideKeyHeld(&title_cfg.override_key);
/* Set content specific output. */
const auto content_cfg = GetContentOverrideConfig(program_id);
*out_program = IsOverrideKeyHeld(&content_cfg.override_key);
}
bool IsCheatEnableKeyHeld(ncm::TitleId title_id) {
bool IsCheatEnableKeyHeld(ncm::ProgramId program_id) {
/* If the SD card isn't initialized, don't apply cheats. */
if (!IsSdCardInitialized()) {
return false;
}
/* Don't apply cheats to HBL. */
if (IsHblOverrideKeyHeld(title_id)) {
if (IsHblOverrideKeyHeld(program_id)) {
return false;
}
TitleSpecificOverrideConfig title_cfg = GetTitleOverrideConfig(title_id);
return IsOverrideKeyHeld(&title_cfg.cheat_enable_key);
const auto content_cfg = GetContentOverrideConfig(program_id);
return IsOverrideKeyHeld(&content_cfg.cheat_enable_key);
}
/* HBL Configuration utilities. */
bool IsHblTitleId(ncm::TitleId title_id) {
return (g_hbl_override_config.override_any_app && ncm::IsApplicationTitleId(title_id)) || (title_id == g_hbl_override_config.title_id);
bool IsHblProgramId(ncm::ProgramId program_id) {
return (g_hbl_override_config.override_any_app && ncm::IsApplicationProgramId(program_id)) || (program_id == g_hbl_override_config.program_id);
}
const char *GetHblPath() {

View file

@ -35,7 +35,7 @@ namespace ams::hid {
Result EnsureHidInitialized() {
if (!g_initialized_hid) {
if (!serviceIsActive(hidGetServiceSession())) {
if (!pm::info::HasLaunchedTitle(ncm::TitleId::Hid)) {
if (!pm::info::HasLaunchedProgram(ncm::ProgramId::Hid)) {
return MAKERESULT(Module_Libnx, LibnxError_InitFail_HID);
}
InitializeHid();

View file

@ -17,17 +17,17 @@
#include <switch.h>
#include "ldr_ams.h"
static Result _ldrAtmosphereHasLaunchedTitle(Service *srv, bool *out, u64 tid) {
static Result _ldrAtmosphereHasLaunchedProgram(Service *srv, bool *out, u64 program_id) {
u8 tmp;
Result rc = serviceDispatchInOut(srv, 65000, tid, tmp);
Result rc = serviceDispatchInOut(srv, 65000, program_id, tmp);
if (R_SUCCEEDED(rc) && out) *out = tmp & 1;
return rc;
}
Result ldrDmntAtmosphereHasLaunchedTitle(bool *out, u64 tid) {
return _ldrAtmosphereHasLaunchedTitle(ldrDmntGetServiceSession(), out, tid);
Result ldrDmntAtmosphereHasLaunchedProgram(bool *out, u64 program_id) {
return _ldrAtmosphereHasLaunchedProgram(ldrDmntGetServiceSession(), out, program_id);
}
Result ldrPmAtmosphereHasLaunchedTitle(bool *out, u64 tid) {
return _ldrAtmosphereHasLaunchedTitle(ldrPmGetServiceSession(), out, tid);
Result ldrPmAtmosphereHasLaunchedProgram(bool *out, u64 program_id) {
return _ldrAtmosphereHasLaunchedProgram(ldrPmGetServiceSession(), out, program_id);
}

View file

@ -11,8 +11,8 @@
extern "C" {
#endif
Result ldrPmAtmosphereHasLaunchedTitle(bool *out, u64 tid);
Result ldrDmntAtmosphereHasLaunchedTitle(bool *out, u64 tid);
Result ldrPmAtmosphereHasLaunchedProgram(bool *out, u64 program_id);
Result ldrDmntAtmosphereHasLaunchedProgram(bool *out, u64 program_id);
#ifdef __cplusplus
}

View file

@ -20,24 +20,24 @@ namespace ams::ldr::pm {
/* Information API. */
Result CreateProcess(Handle *out, PinId pin_id, u32 flags, Handle reslimit) {
return ldrPmCreateProcess(flags, pin_id.value, reslimit, out);
return ldrPmCreateProcess(pin_id.value, flags, reslimit, out);
}
Result GetProgramInfo(ProgramInfo *out, const ncm::TitleLocation &loc) {
return ldrPmGetProgramInfo(static_cast<u64>(loc.title_id), static_cast<FsStorageId>(loc.storage_id), reinterpret_cast<LoaderProgramInfo *>(out));
Result GetProgramInfo(ProgramInfo *out, const ncm::ProgramLocation &loc) {
return ldrPmGetProgramInfo(reinterpret_cast<const NcmProgramLocation *>(&loc), reinterpret_cast<LoaderProgramInfo *>(out));
}
Result PinTitle(PinId *out, const ncm::TitleLocation &loc) {
Result PinProgram(PinId *out, const ncm::ProgramLocation &loc) {
static_assert(sizeof(*out) == sizeof(u64), "PinId definition!");
return ldrPmRegisterTitle(static_cast<u64>(loc.title_id), static_cast<FsStorageId>(loc.storage_id), reinterpret_cast<u64 *>(out));
return ldrPmPinProgram(reinterpret_cast<const NcmProgramLocation *>(&loc), reinterpret_cast<u64 *>(out));
}
Result UnpinTitle(PinId pin_id) {
return ldrPmUnregisterTitle(pin_id.value);
Result UnpinProgram(PinId pin_id) {
return ldrPmUnpinProgram(pin_id.value);
}
Result HasLaunchedTitle(bool *out, ncm::TitleId title_id) {
return ldrPmAtmosphereHasLaunchedTitle(out, static_cast<u64>(title_id));
Result HasLaunchedProgram(bool *out, ncm::ProgramId program_id) {
return ldrPmAtmosphereHasLaunchedProgram(out, static_cast<u64>(program_id));
}
}

View file

@ -17,32 +17,26 @@
#include <switch.h>
#include "pm_ams.h"
Result pminfoAtmosphereGetProcessId(u64 *out_pid, u64 tid) {
return serviceDispatchInOut(pminfoGetServiceSession(), 65000, tid, *out_pid);
Result pminfoAtmosphereGetProcessId(u64 *out_pid, u64 program_id) {
return serviceDispatchInOut(pminfoGetServiceSession(), 65000, program_id, *out_pid);
}
Result pminfoAtmosphereHasLaunchedTitle(bool *out, u64 tid) {
Result pminfoAtmosphereHasLaunchedProgram(bool *out, u64 program_id) {
u8 tmp;
Result rc = serviceDispatchInOut(pminfoGetServiceSession(), 65001, tid, tmp);
Result rc = serviceDispatchInOut(pminfoGetServiceSession(), 65001, program_id, tmp);
if (R_SUCCEEDED(rc) && out) *out = tmp & 1;
return rc;
}
Result pmdmntAtmosphereGetProcessInfo(Handle* handle_out, u64 *tid_out, u8 *sid_out, u64 pid) {
struct {
u64 title_id;
u8 storage_id;
} out;
Result pmdmntAtmosphereGetProcessInfo(Handle* handle_out, NcmProgramLocation *loc_out, u64 pid) {
Handle tmp_handle;
Result rc = serviceDispatchInOut(pmdmntGetServiceSession(), 65000, pid, out,
Result rc = serviceDispatchInOut(pmdmntGetServiceSession(), 65000, pid, *loc_out,
.out_handle_attrs = { SfOutHandleAttr_HipcCopy },
.out_handles = &tmp_handle,
);
if (R_SUCCEEDED(rc)) {
if (tid_out) *tid_out = out.title_id;
if (sid_out) *sid_out = out.storage_id;
if (handle_out) {
*handle_out = tmp_handle;
} else {

View file

@ -11,10 +11,10 @@
extern "C" {
#endif
Result pminfoAtmosphereGetProcessId(u64 *out_pid, u64 tid);
Result pminfoAtmosphereHasLaunchedTitle(bool *out, u64 tid);
Result pminfoAtmosphereGetProcessId(u64 *out_pid, u64 program_id);
Result pminfoAtmosphereHasLaunchedProgram(bool *out, u64 program_id);
Result pmdmntAtmosphereGetProcessInfo(Handle *out, u64 *tid_out, u8 *sid_out, u64 pid);
Result pmdmntAtmosphereGetProcessInfo(Handle *out, NcmProgramLocation *loc_out, u64 pid);
Result pmdmntAtmosphereGetCurrentLimitInfo(u64 *out_cur, u64 *out_lim, u32 group, u32 resource);
#ifdef __cplusplus

View file

@ -24,8 +24,8 @@ namespace ams::pm::dmnt {
return pmdmntStartProcess(static_cast<u64>(process_id));
}
Result GetProcessId(os::ProcessId *out_process_id, const ncm::TitleId title_id) {
return pmdmntGetProcessId(reinterpret_cast<u64 *>(out_process_id), static_cast<u64>(title_id));
Result GetProcessId(os::ProcessId *out_process_id, const ncm::ProgramId program_id) {
return pmdmntGetProcessId(reinterpret_cast<u64 *>(out_process_id), static_cast<u64>(program_id));
}
Result GetApplicationProcessId(os::ProcessId *out_process_id) {
@ -39,10 +39,10 @@ namespace ams::pm::dmnt {
return ResultSuccess();
}
Result AtmosphereGetProcessInfo(Handle *out_handle, ncm::TitleLocation *out_loc, os::ProcessId process_id) {
Result AtmosphereGetProcessInfo(Handle *out_handle, ncm::ProgramLocation *out_loc, os::ProcessId process_id) {
*out_handle = INVALID_HANDLE;
*out_loc = {};
return pmdmntAtmosphereGetProcessInfo(out_handle, reinterpret_cast<u64 *>(&out_loc->title_id), &out_loc->storage_id, static_cast<u64>(process_id));
return pmdmntAtmosphereGetProcessInfo(out_handle, reinterpret_cast<NcmProgramLocation *>(out_loc), static_cast<u64>(process_id));
}
Result AtmosphereGetCurrentLimitInfo(u64 *out_current_value, u64 *out_limit_value, ResourceLimitGroup group, LimitableResource resource) {

View file

@ -22,44 +22,45 @@ namespace ams::pm::info {
/* Global lock. */
os::Mutex g_info_lock;
std::set<u64> g_cached_launched_titles;
/* TODO: Less memory-intensive storage? */
std::set<u64> g_cached_launched_programs;
}
/* Information API. */
Result GetTitleId(ncm::TitleId *out_title_id, os::ProcessId process_id) {
Result GetProgramId(ncm::ProgramId *out_program_id, os::ProcessId process_id) {
std::scoped_lock lk(g_info_lock);
return pminfoGetProgramId(reinterpret_cast<u64 *>(out_title_id), static_cast<u64>(process_id));
return pminfoGetProgramId(reinterpret_cast<u64 *>(out_program_id), static_cast<u64>(process_id));
}
Result GetProcessId(os::ProcessId *out_process_id, ncm::TitleId title_id) {
Result GetProcessId(os::ProcessId *out_process_id, ncm::ProgramId program_id) {
std::scoped_lock lk(g_info_lock);
return pminfoAtmosphereGetProcessId(reinterpret_cast<u64 *>(out_process_id), static_cast<u64>(title_id));
return pminfoAtmosphereGetProcessId(reinterpret_cast<u64 *>(out_process_id), static_cast<u64>(program_id));
}
Result WEAK HasLaunchedTitle(bool *out, ncm::TitleId title_id) {
Result WEAK HasLaunchedProgram(bool *out, ncm::ProgramId program_id) {
std::scoped_lock lk(g_info_lock);
if (g_cached_launched_titles.find(static_cast<u64>(title_id)) != g_cached_launched_titles.end()) {
if (g_cached_launched_programs.find(static_cast<u64>(program_id)) != g_cached_launched_programs.end()) {
*out = true;
return ResultSuccess();
}
bool has_launched = false;
R_TRY(pminfoAtmosphereHasLaunchedTitle(&has_launched, static_cast<u64>(title_id)));
R_TRY(pminfoAtmosphereHasLaunchedProgram(&has_launched, static_cast<u64>(program_id)));
if (has_launched) {
g_cached_launched_titles.insert(static_cast<u64>(title_id));
g_cached_launched_programs.insert(static_cast<u64>(program_id));
}
*out = has_launched;
return ResultSuccess();
}
bool HasLaunchedTitle(ncm::TitleId title_id) {
bool HasLaunchedProgram(ncm::ProgramId program_id) {
bool has_launched = false;
R_ASSERT(HasLaunchedTitle(&has_launched, title_id));
R_ASSERT(HasLaunchedProgram(&has_launched, program_id));
return has_launched;
}

View file

@ -18,9 +18,9 @@
namespace ams::pm::shell {
/* Shell API. */
Result WEAK LaunchTitle(os::ProcessId *out_process_id, const ncm::TitleLocation &loc, u32 launch_flags) {
static_assert(sizeof(ncm::TitleLocation) == sizeof(NcmProgramLocation));
static_assert(alignof(ncm::TitleLocation) == alignof(NcmProgramLocation));
Result WEAK LaunchProgram(os::ProcessId *out_process_id, const ncm::ProgramLocation &loc, u32 launch_flags) {
static_assert(sizeof(ncm::ProgramLocation) == sizeof(NcmProgramLocation));
static_assert(alignof(ncm::ProgramLocation) == alignof(NcmProgramLocation));
return pmshellLaunchProgram(launch_flags, reinterpret_cast<const NcmProgramLocation *>(&loc), reinterpret_cast<u64 *>(out_process_id));
}

View file

@ -19,8 +19,8 @@
namespace ams::sm::manager {
/* Manager API. */
Result RegisterProcess(os::ProcessId process_id, ncm::TitleId title_id, const void *acid, size_t acid_size, const void *aci, size_t aci_size) {
return smManagerAtmosphereRegisterProcess(static_cast<u64>(process_id), static_cast<u64>(title_id), acid, acid_size, aci, aci_size);
Result RegisterProcess(os::ProcessId process_id, ncm::ProgramId program_id, const void *acid, size_t acid_size, const void *aci, size_t aci_size) {
return smManagerAtmosphereRegisterProcess(static_cast<u64>(process_id), static_cast<u64>(program_id), acid, acid_size, aci, aci_size);
}
Result UnregisterProcess(os::ProcessId process_id) {

View file

@ -36,9 +36,9 @@ namespace ams::sm::mitm {
});
}
Result AcknowledgeSession(Service *out_service, os::ProcessId *out_pid, ncm::TitleId *out_tid, ServiceName name) {
Result AcknowledgeSession(Service *out_service, os::ProcessId *out_process_id, ncm::ProgramId *out_program_id, ServiceName name) {
return impl::DoWithMitmSession([&]() {
return smAtmosphereMitmAcknowledgeSession(out_service, &out_pid->value, &out_tid->value, impl::ConvertName(name));
return smAtmosphereMitmAcknowledgeSession(out_service, &out_process_id->value, &out_program_id->value, impl::ConvertName(name));
});
}

View file

@ -148,10 +148,10 @@ namespace ams::updater {
NcmContentMetaKey *records = reinterpret_cast<NcmContentMetaKey *>(work_buffer);
const auto title_type = GetNcmContentMetaType(mode);
const auto content_meta_type = GetNcmContentMetaType(mode);
s32 written_entries;
s32 total_entries;
R_TRY(ncmContentMetaDatabaseList(&meta_db, &total_entries, &written_entries, records, MaxContentMetas * sizeof(*records), title_type, 0, 0, UINT64_MAX, NcmContentInstallType_Full));
R_TRY(ncmContentMetaDatabaseList(&meta_db, &total_entries, &written_entries, records, MaxContentMetas * sizeof(*records), content_meta_type, 0, 0, UINT64_MAX, NcmContentInstallType_Full));
if (total_entries <= 0) {
return ResultBootImagePackageNotFound();
}
@ -165,14 +165,14 @@ namespace ams::updater {
R_TRY(ncmContentMetaDatabaseGetAttributes(&meta_db, &records[i], &attr));
if (attr & NcmContentMetaAttribute_IncludesExFatDriver) {
*out_data_id = records[i].title_id;
*out_data_id = records[i].id;
return ResultSuccess();
}
}
}
/* If there's only one entry or no exfat entries, return that entry. */
*out_data_id = records[0].title_id;
*out_data_id = records[0].id;
return ResultSuccess();
}

View file

@ -20,16 +20,15 @@ namespace ams::ldr::args {
namespace {
/* Convenience definitions. */
constexpr ncm::TitleId FreeTitleId = {};
constexpr size_t MaxArgumentInfos = 10;
/* Global storage. */
ArgumentInfo g_argument_infos[MaxArgumentInfos];
/* Helpers. */
ArgumentInfo *FindArgumentInfo(ncm::TitleId title_id) {
ArgumentInfo *FindArgumentInfo(ncm::ProgramId program_id) {
for (size_t i = 0; i < MaxArgumentInfos; i++) {
if (g_argument_infos[i].title_id == title_id) {
if (g_argument_infos[i].program_id == program_id) {
return &g_argument_infos[i];
}
}
@ -37,34 +36,34 @@ namespace ams::ldr::args {
}
ArgumentInfo *FindFreeArgumentInfo() {
return FindArgumentInfo(FreeTitleId);
return FindArgumentInfo(ncm::InvalidProgramId);
}
}
/* API. */
const ArgumentInfo *Get(ncm::TitleId title_id) {
return FindArgumentInfo(title_id);
const ArgumentInfo *Get(ncm::ProgramId program_id) {
return FindArgumentInfo(program_id);
}
Result Set(ncm::TitleId title_id, const void *args, size_t args_size) {
Result Set(ncm::ProgramId program_id, const void *args, size_t args_size) {
R_UNLESS(args_size < ArgumentSizeMax, ldr::ResultTooLongArgument());
ArgumentInfo *arg_info = FindArgumentInfo(title_id);
ArgumentInfo *arg_info = FindArgumentInfo(program_id);
if (arg_info == nullptr) {
arg_info = FindFreeArgumentInfo();
}
R_UNLESS(arg_info != nullptr, ldr::ResultTooManyArguments());
arg_info->title_id = title_id;
arg_info->program_id = program_id;
arg_info->args_size = args_size;
std::memcpy(arg_info->args, args, args_size);
return ResultSuccess();
}
Result Clear() {
Result Flush() {
for (size_t i = 0; i < MaxArgumentInfos; i++) {
g_argument_infos[i].title_id = FreeTitleId;
g_argument_infos[i].program_id = ncm::InvalidProgramId;
}
return ResultSuccess();
}

View file

@ -21,14 +21,14 @@ namespace ams::ldr::args {
constexpr size_t ArgumentSizeMax = 0x8000;
struct ArgumentInfo {
ncm::TitleId title_id;
ncm::ProgramId program_id;
size_t args_size;
u8 args[ArgumentSizeMax];
};
/* API. */
const ArgumentInfo *Get(ncm::TitleId title_id);
Result Set(ncm::TitleId title_id, const void *args, size_t args_size);
Result Clear();
const ArgumentInfo *Get(ncm::ProgramId program_id);
Result Set(ncm::ProgramId program_id, const void *args, size_t args_size);
Result Flush();
}

View file

@ -31,7 +31,7 @@ namespace ams::ldr {
/* Globals. */
bool g_has_mounted_sd_card = false;
ncm::TitleId g_should_override_title_id;
ncm::ProgramId g_should_override_program_id;
bool g_should_override_hbl = false;
bool g_should_override_sd = false;
@ -53,24 +53,24 @@ namespace ams::ldr {
return relative_path;
}
void UpdateShouldOverrideCache(ncm::TitleId title_id) {
if (g_should_override_title_id != title_id) {
cfg::GetOverrideKeyHeldStatus(&g_should_override_hbl, &g_should_override_sd, title_id);
void UpdateShouldOverrideCache(ncm::ProgramId program_id) {
if (g_should_override_program_id != program_id) {
cfg::GetOverrideKeyHeldStatus(&g_should_override_hbl, &g_should_override_sd, program_id);
}
g_should_override_title_id = title_id;
g_should_override_program_id = program_id;
}
void InvalidateShouldOverrideCache() {
g_should_override_title_id = {};
g_should_override_program_id = {};
}
bool ShouldOverrideWithHbl(ncm::TitleId title_id) {
UpdateShouldOverrideCache(title_id);
bool ShouldOverrideWithHbl(ncm::ProgramId program_id) {
UpdateShouldOverrideCache(program_id);
return g_should_override_hbl;
}
bool ShouldOverrideWithSd(ncm::TitleId title_id) {
UpdateShouldOverrideCache(title_id);
bool ShouldOverrideWithSd(ncm::ProgramId program_id) {
UpdateShouldOverrideCache(program_id);
return g_should_override_sd;
}
@ -97,31 +97,31 @@ namespace ams::ldr {
return fopen(path, "rb");
}
FILE *OpenLooseSdFile(ncm::TitleId title_id, const char *relative_path) {
FILE *OpenLooseSdFile(ncm::ProgramId program_id, const char *relative_path) {
/* Allow nullptr relative path -- those are simply not openable. */
if (relative_path == nullptr) {
return nullptr;
}
char path[FS_MAX_PATH];
std::snprintf(path, FS_MAX_PATH, "/atmosphere/titles/%016lx/exefs/%s", static_cast<u64>(title_id), GetRelativePathStart(relative_path));
std::snprintf(path, FS_MAX_PATH, "/atmosphere/contents/%016lx/exefs/%s", static_cast<u64>(program_id), GetRelativePathStart(relative_path));
FixFileSystemPath(path);
return OpenFile(SdCardFileSystemDeviceName, path);
}
bool IsFileStubbed(ncm::TitleId title_id, const char *relative_path) {
bool IsFileStubbed(ncm::ProgramId program_id, const char *relative_path) {
/* Allow nullptr relative path -- those are simply not openable. */
if (relative_path == nullptr) {
return true;
}
/* Only allow stubbing in the case where we're considering SD card content. */
if (!ShouldOverrideWithSd(title_id)) {
if (!ShouldOverrideWithSd(program_id)) {
return false;
}
char path[FS_MAX_PATH];
std::snprintf(path, FS_MAX_PATH, "/atmosphere/titles/%016lx/exefs/%s.stub", static_cast<u64>(title_id), GetRelativePathStart(relative_path));
std::snprintf(path, FS_MAX_PATH, "/atmosphere/contents/%016lx/exefs/%s.stub", static_cast<u64>(program_id), GetRelativePathStart(relative_path));
FixFileSystemPath(path);
FILE *f = OpenFile(SdCardFileSystemDeviceName, path);
if (f == nullptr) {
@ -131,14 +131,14 @@ namespace ams::ldr {
return true;
}
FILE *OpenBaseExefsFile(ncm::TitleId title_id, const char *relative_path) {
FILE *OpenBaseExefsFile(ncm::ProgramId program_id, const char *relative_path) {
/* Allow nullptr relative path -- those are simply not openable. */
if (relative_path == nullptr) {
return nullptr;
}
/* Check if stubbed. */
if (IsFileStubbed(title_id, relative_path)) {
if (IsFileStubbed(program_id, relative_path)) {
return nullptr;
}
@ -148,7 +148,7 @@ namespace ams::ldr {
}
/* ScopedCodeMount functionality. */
ScopedCodeMount::ScopedCodeMount(const ncm::TitleLocation &loc) : is_code_mounted(false), is_hbl_mounted(false) {
ScopedCodeMount::ScopedCodeMount(const ncm::ProgramLocation &loc) : is_code_mounted(false), is_hbl_mounted(false) {
this->result = this->Initialize(loc);
}
@ -165,7 +165,7 @@ namespace ams::ldr {
InvalidateShouldOverrideCache();
}
Result ScopedCodeMount::MountCodeFileSystem(const ncm::TitleLocation &loc) {
Result ScopedCodeMount::MountCodeFileSystem(const ncm::ProgramLocation &loc) {
char path[FS_MAX_PATH];
/* Try to get the content path. */
@ -173,7 +173,7 @@ namespace ams::ldr {
/* Try to mount the content path. */
FsFileSystem fs;
R_TRY(fsldrOpenCodeFileSystem(static_cast<u64>(loc.title_id), path, &fs));
R_TRY(fsldrOpenCodeFileSystem(static_cast<u64>(loc.program_id), path, &fs));
AMS_ASSERT(fsdevMountDevice(CodeFileSystemDeviceName, fs) != -1);
/* Note that we mounted code. */
@ -181,11 +181,11 @@ namespace ams::ldr {
return ResultSuccess();
}
Result ScopedCodeMount::MountSdCardCodeFileSystem(const ncm::TitleLocation &loc) {
Result ScopedCodeMount::MountSdCardCodeFileSystem(const ncm::ProgramLocation &loc) {
char path[FS_MAX_PATH];
/* Print and fix path. */
std::snprintf(path, FS_MAX_PATH, "%s:/atmosphere/titles/%016lx/exefs.nsp", SdCardStorageMountPoint, static_cast<u64>(loc.title_id));
std::snprintf(path, FS_MAX_PATH, "%s:/atmosphere/contents/%016lx/exefs.nsp", SdCardStorageMountPoint, static_cast<u64>(loc.program_id));
FixFileSystemPath(path);
R_TRY(MountNspFileSystem(CodeFileSystemDeviceName, path));
@ -208,7 +208,7 @@ namespace ams::ldr {
}
Result ScopedCodeMount::Initialize(const ncm::TitleLocation &loc) {
Result ScopedCodeMount::Initialize(const ncm::ProgramLocation &loc) {
bool is_sd_initialized = cfg::IsSdCardInitialized();
/* Check if we're ready to mount the SD card. */
@ -220,11 +220,11 @@ namespace ams::ldr {
}
/* Check if we should override contents. */
if (ShouldOverrideWithHbl(loc.title_id)) {
if (ShouldOverrideWithHbl(loc.program_id)) {
/* Try to mount HBL. */
this->MountHblFileSystem();
}
if (ShouldOverrideWithSd(loc.title_id)) {
if (ShouldOverrideWithSd(loc.program_id)) {
/* Try to mount Code NSP on SD. */
this->MountSdCardCodeFileSystem(loc);
}
@ -237,25 +237,25 @@ namespace ams::ldr {
return ResultSuccess();
}
Result OpenCodeFile(FILE *&out, ncm::TitleId title_id, const char *relative_path) {
Result OpenCodeFile(FILE *&out, ncm::ProgramId program_id, const char *relative_path) {
FILE *f = nullptr;
const char *ecs_device_name = ecs::Get(title_id);
const char *ecs_device_name = ecs::Get(program_id);
if (ecs_device_name != nullptr) {
/* First priority: Open from external content. */
f = OpenFile(ecs_device_name, relative_path);
} else if (ShouldOverrideWithHbl(title_id)) {
} else if (ShouldOverrideWithHbl(program_id)) {
/* Next, try to open from HBL. */
f = OpenFile(HblFileSystemDeviceName, relative_path);
} else {
/* If not ECS or HBL, try a loose file on the SD. */
if (ShouldOverrideWithSd(title_id)) {
f = OpenLooseSdFile(title_id, relative_path);
if (ShouldOverrideWithSd(program_id)) {
f = OpenLooseSdFile(program_id, relative_path);
}
/* If we fail, try the original exefs. */
if (f == nullptr) {
f = OpenBaseExefsFile(title_id, relative_path);
f = OpenBaseExefsFile(program_id, relative_path);
}
}
@ -266,9 +266,9 @@ namespace ams::ldr {
return ResultSuccess();
}
Result OpenCodeFileFromBaseExefs(FILE *&out, ncm::TitleId title_id, const char *relative_path) {
Result OpenCodeFileFromBaseExefs(FILE *&out, ncm::ProgramId program_id, const char *relative_path) {
/* Open the file. */
FILE *f = OpenBaseExefsFile(title_id, relative_path);
FILE *f = OpenBaseExefsFile(program_id, relative_path);
R_UNLESS(f != nullptr, fs::ResultPathNotFound());
out = f;
@ -276,7 +276,7 @@ namespace ams::ldr {
}
/* Redirection API. */
Result ResolveContentPath(char *out_path, const ncm::TitleLocation &loc) {
Result ResolveContentPath(char *out_path, const ncm::ProgramLocation &loc) {
char path[FS_MAX_PATH];
/* Try to get the path from the registered resolver. */
@ -284,14 +284,14 @@ namespace ams::ldr {
R_TRY(lrOpenRegisteredLocationResolver(&reg));
ON_SCOPE_EXIT { serviceClose(&reg.s); };
R_TRY_CATCH(lrRegLrResolveProgramPath(&reg, static_cast<u64>(loc.title_id), path)) {
R_TRY_CATCH(lrRegLrResolveProgramPath(&reg, static_cast<u64>(loc.program_id), path)) {
R_CATCH(lr::ResultProgramNotFound) {
/* Program wasn't found via registered resolver, fall back to the normal resolver. */
LrLocationResolver lr;
R_TRY(lrOpenLocationResolver(static_cast<FsStorageId>(loc.storage_id), &lr));
ON_SCOPE_EXIT { serviceClose(&lr.s); };
R_TRY(lrLrResolveProgramPath(&lr, static_cast<u64>(loc.title_id), path));
R_TRY(lrLrResolveProgramPath(&lr, static_cast<u64>(loc.program_id), path));
}
} R_END_TRY_CATCH;
@ -301,15 +301,15 @@ namespace ams::ldr {
return ResultSuccess();
}
Result RedirectContentPath(const char *path, const ncm::TitleLocation &loc) {
Result RedirectContentPath(const char *path, const ncm::ProgramLocation &loc) {
LrLocationResolver lr;
R_TRY(lrOpenLocationResolver(static_cast<FsStorageId>(loc.storage_id), &lr));
ON_SCOPE_EXIT { serviceClose(&lr.s); };
return lrLrRedirectProgramPath(&lr, static_cast<u64>(loc.title_id), path);
return lrLrRedirectProgramPath(&lr, static_cast<u64>(loc.program_id), path);
}
Result RedirectHtmlDocumentPathForHbl(const ncm::TitleLocation &loc) {
Result RedirectHtmlDocumentPathForHbl(const ncm::ProgramLocation &loc) {
char path[FS_MAX_PATH];
/* Open a location resolver. */
@ -318,11 +318,11 @@ namespace ams::ldr {
ON_SCOPE_EXIT { serviceClose(&lr.s); };
/* If there's already a Html Document path, we don't need to set one. */
R_UNLESS(R_FAILED(lrLrResolveApplicationHtmlDocumentPath(&lr, static_cast<u64>(loc.title_id), path)), ResultSuccess());
R_UNLESS(R_FAILED(lrLrResolveApplicationHtmlDocumentPath(&lr, static_cast<u64>(loc.program_id), path)), ResultSuccess());
/* We just need to set this to any valid NCA path. Let's use the executable path. */
R_TRY(lrLrResolveProgramPath(&lr, static_cast<u64>(loc.title_id), path));
R_TRY(lrLrRedirectApplicationHtmlDocumentPath(&lr, static_cast<u64>(loc.title_id), static_cast<u64>(loc.title_id), path));
R_TRY(lrLrResolveProgramPath(&lr, static_cast<u64>(loc.program_id), path));
R_TRY(lrLrRedirectApplicationHtmlDocumentPath(&lr, static_cast<u64>(loc.program_id), static_cast<u64>(loc.program_id), path));
return ResultSuccess();
}

View file

@ -26,7 +26,7 @@ namespace ams::ldr {
bool is_code_mounted;
bool is_hbl_mounted;
public:
ScopedCodeMount(const ncm::TitleLocation &loc);
ScopedCodeMount(const ncm::ProgramLocation &loc);
~ScopedCodeMount();
Result GetResult() const {
@ -42,20 +42,20 @@ namespace ams::ldr {
}
private:
Result Initialize(const ncm::TitleLocation &loc);
Result Initialize(const ncm::ProgramLocation &loc);
Result MountCodeFileSystem(const ncm::TitleLocation &loc);
Result MountSdCardCodeFileSystem(const ncm::TitleLocation &loc);
Result MountCodeFileSystem(const ncm::ProgramLocation &loc);
Result MountSdCardCodeFileSystem(const ncm::ProgramLocation &loc);
Result MountHblFileSystem();
};
/* Content Management API. */
Result OpenCodeFile(FILE *&out, ncm::TitleId title_id, const char *relative_path);
Result OpenCodeFileFromBaseExefs(FILE *&out, ncm::TitleId title_id, const char *relative_path);
Result OpenCodeFile(FILE *&out, ncm::ProgramId program_id, const char *relative_path);
Result OpenCodeFileFromBaseExefs(FILE *&out, ncm::ProgramId program_id, const char *relative_path);
/* Redirection API. */
Result ResolveContentPath(char *out_path, const ncm::TitleLocation &loc);
Result RedirectContentPath(const char *path, const ncm::TitleLocation &loc);
Result RedirectHtmlDocumentPathForHbl(const ncm::TitleLocation &loc);
Result ResolveContentPath(char *out_path, const ncm::ProgramLocation &loc);
Result RedirectContentPath(const char *path, const ncm::ProgramLocation &loc);
Result RedirectHtmlDocumentPathForHbl(const ncm::ProgramLocation &loc);
}

View file

@ -49,24 +49,24 @@ namespace ams::ldr::ecs {
}
/* API. */
const char *Get(ncm::TitleId title_id) {
auto it = g_map.find(static_cast<u64>(title_id));
const char *Get(ncm::ProgramId program_id) {
auto it = g_map.find(static_cast<u64>(program_id));
if (it == g_map.end()) {
return nullptr;
}
return it->second.GetDeviceName();
}
Result Set(Handle *out, ncm::TitleId title_id) {
Result Set(Handle *out, ncm::ProgramId program_id) {
/* TODO: Is this an appropriate error? */
R_UNLESS(g_map.size() < MaxExternalContentSourceCount, ldr::ResultTooManyArguments());
/* Clear any sources. */
R_ASSERT(Clear(title_id));
R_ASSERT(Clear(program_id));
/* Generate mountpoint. */
char device_name[DeviceNameSizeMax];
std::snprintf(device_name, DeviceNameSizeMax, "ecs-%016lx", static_cast<u64>(title_id));
std::snprintf(device_name, DeviceNameSizeMax, "ecs-%016lx", static_cast<u64>(program_id));
/* Create session. */
os::ManagedHandle server, client;
@ -83,14 +83,14 @@ namespace ams::ldr::ecs {
fs_guard.Cancel();
/* Add to map. */
g_map.emplace(static_cast<u64>(title_id), device_name);
g_map.emplace(static_cast<u64>(program_id), device_name);
*out = server.Move();
return ResultSuccess();
}
Result Clear(ncm::TitleId title_id) {
Result Clear(ncm::ProgramId program_id) {
/* Delete if present. */
g_map.erase(static_cast<u64>(title_id));
g_map.erase(static_cast<u64>(program_id));
return ResultSuccess();
}

View file

@ -19,8 +19,8 @@
namespace ams::ldr::ecs {
/* External Content Source API. */
const char *Get(ncm::TitleId title_id);
Result Set(Handle *out, ncm::TitleId title_id);
Result Clear(ncm::TitleId title_id);
const char *Get(ncm::ProgramId program_id);
Result Set(Handle *out, ncm::ProgramId program_id);
Result Clear(ncm::ProgramId program_id);
}

View file

@ -20,17 +20,17 @@ namespace ams::ldr {
namespace {
/* Global cache. */
std::set<u64> g_launched_titles;
std::set<u64> g_launched_programs;
}
/* Launch Record API. */
bool HasLaunchedTitle(ncm::TitleId title_id) {
return g_launched_titles.find(static_cast<u64>(title_id)) != g_launched_titles.end();
bool HasLaunchedProgram(ncm::ProgramId program_id) {
return g_launched_programs.find(static_cast<u64>(program_id)) != g_launched_programs.end();
}
void SetLaunchedTitle(ncm::TitleId title_id) {
g_launched_titles.insert(static_cast<u64>(title_id));
void SetLaunchedProgram(ncm::ProgramId program_id) {
g_launched_programs.insert(static_cast<u64>(program_id));
}
}
@ -39,8 +39,8 @@ namespace ams::ldr {
/* This is necessary to prevent circular dependencies. */
namespace ams::pm::info {
Result HasLaunchedTitle(bool *out, ncm::TitleId title_id) {
*out = ldr::HasLaunchedTitle(title_id);
Result HasLaunchedProgram(bool *out, ncm::ProgramId program_id) {
*out = ldr::HasLaunchedProgram(program_id);
return ResultSuccess();
}

View file

@ -19,7 +19,7 @@
namespace ams::ldr {
/* Launch Record API. */
bool HasLaunchedTitle(ncm::TitleId title_id);
void SetLaunchedTitle(ncm::TitleId title_id);
bool HasLaunchedProgram(ncm::ProgramId program_id);
void SetLaunchedProgram(ncm::ProgramId program_id);
}

View file

@ -26,11 +26,11 @@ namespace ams::ldr {
/* Official commands. */
Result LoaderService::CreateProcess(sf::OutMoveHandle proc_h, PinId id, u32 flags, sf::CopyHandle reslimit_h) {
os::ManagedHandle reslimit_holder(reslimit_h.GetValue());
ncm::TitleLocation loc;
ncm::ProgramLocation loc;
char path[FS_MAX_PATH];
/* Get location. */
R_TRY(ldr::ro::GetTitleLocation(&loc, id));
R_TRY(ldr::ro::GetProgramLocation(&loc, id));
if (loc.storage_id != static_cast<u8>(ncm::StorageId::None)) {
R_TRY(ResolveContentPath(path, loc));
@ -39,42 +39,42 @@ namespace ams::ldr {
return ldr::CreateProcess(proc_h.GetHandlePointer(), id, loc, path, flags, reslimit_holder.Get());
}
Result LoaderService::GetProgramInfo(sf::Out<ProgramInfo> out, const ncm::TitleLocation &loc) {
Result LoaderService::GetProgramInfo(sf::Out<ProgramInfo> out, const ncm::ProgramLocation &loc) {
/* Zero output. */
std::memset(out.GetPointer(), 0, sizeof(*out.GetPointer()));
R_TRY(ldr::GetProgramInfo(out.GetPointer(), loc));
if (loc.storage_id != static_cast<u8>(ncm::StorageId::None) && loc.title_id != out->title_id) {
if (loc.storage_id != static_cast<u8>(ncm::StorageId::None) && loc.program_id != out->program_id) {
char path[FS_MAX_PATH];
const ncm::TitleLocation new_loc = ncm::TitleLocation::Make(out->title_id, static_cast<ncm::StorageId>(loc.storage_id));
const ncm::ProgramLocation new_loc = ncm::ProgramLocation::Make(out->program_id, static_cast<ncm::StorageId>(loc.storage_id));
R_TRY(ResolveContentPath(path, loc));
R_TRY(RedirectContentPath(path, new_loc));
const auto arg_info = args::Get(loc.title_id);
const auto arg_info = args::Get(loc.program_id);
if (arg_info != nullptr) {
R_TRY(args::Set(new_loc.title_id, arg_info->args, arg_info->args_size));
R_TRY(args::Set(new_loc.program_id, arg_info->args, arg_info->args_size));
}
}
return ResultSuccess();
}
Result LoaderService::PinTitle(sf::Out<PinId> out_id, const ncm::TitleLocation &loc) {
return ldr::ro::PinTitle(out_id.GetPointer(), loc);
Result LoaderService::PinProgram(sf::Out<PinId> out_id, const ncm::ProgramLocation &loc) {
return ldr::ro::PinProgram(out_id.GetPointer(), loc);
}
Result LoaderService::UnpinTitle(PinId id) {
return ldr::ro::UnpinTitle(id);
Result LoaderService::UnpinProgram(PinId id) {
return ldr::ro::UnpinProgram(id);
}
Result LoaderService::SetTitleArguments(ncm::TitleId title_id, const sf::InPointerBuffer &args, u32 args_size) {
return args::Set(title_id, args.GetPointer(), std::min(args.GetSize(), size_t(args_size)));
Result LoaderService::SetProgramArguments(ncm::ProgramId program_id, const sf::InPointerBuffer &args, u32 args_size) {
return args::Set(program_id, args.GetPointer(), std::min(args.GetSize(), size_t(args_size)));
}
Result LoaderService::ClearArguments() {
return args::Clear();
Result LoaderService::FlushArguments() {
return args::Flush();
}
Result LoaderService::GetProcessModuleInfo(sf::Out<u32> count, const sf::OutPointerArray<ModuleInfo> &out, os::ProcessId process_id) {
@ -83,16 +83,16 @@ namespace ams::ldr {
}
/* Atmosphere commands. */
Result LoaderService::AtmosphereSetExternalContentSource(sf::OutMoveHandle out, ncm::TitleId title_id) {
return ecs::Set(out.GetHandlePointer(), title_id);
Result LoaderService::AtmosphereSetExternalContentSource(sf::OutMoveHandle out, ncm::ProgramId program_id) {
return ecs::Set(out.GetHandlePointer(), program_id);
}
void LoaderService::AtmosphereClearExternalContentSource(ncm::TitleId title_id) {
R_ASSERT(ecs::Clear(title_id));
void LoaderService::AtmosphereClearExternalContentSource(ncm::ProgramId program_id) {
R_ASSERT(ecs::Clear(program_id));
}
void LoaderService::AtmosphereHasLaunchedTitle(sf::Out<bool> out, ncm::TitleId title_id) {
out.SetValue(ldr::HasLaunchedTitle(title_id));
void LoaderService::AtmosphereHasLaunchedProgram(sf::Out<bool> out, ncm::ProgramId program_id) {
out.SetValue(ldr::HasLaunchedProgram(program_id));
}
}

View file

@ -22,17 +22,17 @@ namespace ams::ldr {
protected:
/* Official commands. */
virtual Result CreateProcess(sf::OutMoveHandle proc_h, PinId id, u32 flags, sf::CopyHandle reslimit_h);
virtual Result GetProgramInfo(sf::Out<ProgramInfo> out_program_info, const ncm::TitleLocation &loc);
virtual Result PinTitle(sf::Out<PinId> out_id, const ncm::TitleLocation &loc);
virtual Result UnpinTitle(PinId id);
virtual Result SetTitleArguments(ncm::TitleId title_id, const sf::InPointerBuffer &args, u32 args_size);
virtual Result ClearArguments();
virtual Result GetProgramInfo(sf::Out<ProgramInfo> out_program_info, const ncm::ProgramLocation &loc);
virtual Result PinProgram(sf::Out<PinId> out_id, const ncm::ProgramLocation &loc);
virtual Result UnpinProgram(PinId id);
virtual Result SetProgramArguments(ncm::ProgramId program_id, const sf::InPointerBuffer &args, u32 args_size);
virtual Result FlushArguments();
virtual Result GetProcessModuleInfo(sf::Out<u32> count, const sf::OutPointerArray<ModuleInfo> &out, os::ProcessId process_id);
/* Atmosphere commands. */
virtual Result AtmosphereSetExternalContentSource(sf::OutMoveHandle out, ncm::TitleId title_id);
virtual void AtmosphereClearExternalContentSource(ncm::TitleId title_id);
virtual void AtmosphereHasLaunchedTitle(sf::Out<bool> out, ncm::TitleId title_id);
virtual Result AtmosphereSetExternalContentSource(sf::OutMoveHandle out, ncm::ProgramId program_id);
virtual void AtmosphereClearExternalContentSource(ncm::ProgramId program_id);
virtual void AtmosphereHasLaunchedProgram(sf::Out<bool> out, ncm::ProgramId program_id);
};
namespace pm {
@ -42,19 +42,19 @@ namespace ams::ldr {
enum class CommandId {
CreateProcess = 0,
GetProgramInfo = 1,
PinTitle = 2,
UnpinTitle = 3,
PinProgram = 2,
UnpinProgram = 3,
AtmosphereHasLaunchedTitle = 65000,
AtmosphereHasLaunchedProgram = 65000,
};
public:
DEFINE_SERVICE_DISPATCH_TABLE {
MAKE_SERVICE_COMMAND_META(CreateProcess),
MAKE_SERVICE_COMMAND_META(GetProgramInfo),
MAKE_SERVICE_COMMAND_META(PinTitle),
MAKE_SERVICE_COMMAND_META(UnpinTitle),
MAKE_SERVICE_COMMAND_META(PinProgram),
MAKE_SERVICE_COMMAND_META(UnpinProgram),
MAKE_SERVICE_COMMAND_META(AtmosphereHasLaunchedTitle),
MAKE_SERVICE_COMMAND_META(AtmosphereHasLaunchedProgram),
};
};
@ -65,19 +65,19 @@ namespace ams::ldr {
class DebugMonitorInterface final : public LoaderService {
protected:
enum class CommandId {
SetTitleArguments = 0,
ClearArguments = 1,
SetProgramArguments = 0,
FlushArguments = 1,
GetProcessModuleInfo = 2,
AtmosphereHasLaunchedTitle = 65000,
AtmosphereHasLaunchedProgram = 65000,
};
public:
DEFINE_SERVICE_DISPATCH_TABLE {
MAKE_SERVICE_COMMAND_META(SetTitleArguments),
MAKE_SERVICE_COMMAND_META(ClearArguments),
MAKE_SERVICE_COMMAND_META(SetProgramArguments),
MAKE_SERVICE_COMMAND_META(FlushArguments),
MAKE_SERVICE_COMMAND_META(GetProcessModuleInfo),
MAKE_SERVICE_COMMAND_META(AtmosphereHasLaunchedTitle),
MAKE_SERVICE_COMMAND_META(AtmosphereHasLaunchedProgram),
};
};
@ -88,16 +88,16 @@ namespace ams::ldr {
class ShellInterface final : public LoaderService {
protected:
enum class CommandId {
SetTitleArguments = 0,
ClearArguments = 1,
SetProgramArguments = 0,
FlushArguments = 1,
AtmosphereSetExternalContentSource = 65000,
AtmosphereClearExternalContentSource = 65001,
};
public:
DEFINE_SERVICE_DISPATCH_TABLE {
MAKE_SERVICE_COMMAND_META(SetTitleArguments),
MAKE_SERVICE_COMMAND_META(ClearArguments),
MAKE_SERVICE_COMMAND_META(SetProgramArguments),
MAKE_SERVICE_COMMAND_META(FlushArguments),
MAKE_SERVICE_COMMAND_META(AtmosphereSetExternalContentSource),
MAKE_SERVICE_COMMAND_META(AtmosphereClearExternalContentSource),

View file

@ -23,7 +23,7 @@ extern "C" {
u32 __nx_fs_num_sessions = 1;
u32 __nx_fsdev_direntry_cache_size = 1;
#define INNER_HEAP_SIZE 0x4000
#define INNER_HEAP_SIZE 0x8000
size_t nx_inner_heap_size = INNER_HEAP_SIZE;
char nx_inner_heap[INNER_HEAP_SIZE];
@ -39,7 +39,7 @@ extern "C" {
namespace ams {
ncm::TitleId CurrentTitleId = ncm::TitleId::Loader;
ncm::ProgramId CurrentProgramId = ncm::ProgramId::Loader;
namespace result {

View file

@ -32,7 +32,7 @@ namespace ams::ldr {
};
/* Global storage. */
ncm::TitleId g_cached_title_id;
ncm::ProgramId g_cached_program_id;
MetaCache g_meta_cache;
MetaCache g_original_meta_cache;
@ -144,25 +144,25 @@ namespace ams::ldr {
}
/* API. */
Result LoadMeta(Meta *out_meta, ncm::TitleId title_id) {
Result LoadMeta(Meta *out_meta, ncm::ProgramId program_id) {
FILE *f = nullptr;
/* Try to load meta from file. */
R_TRY(OpenCodeFile(f, title_id, MetaFilePath));
R_TRY(OpenCodeFile(f, program_id, MetaFilePath));
{
ON_SCOPE_EXIT { fclose(f); };
R_TRY(LoadMetaFromFile(f, &g_meta_cache));
}
/* Patch meta. Start by setting all title ids to the current title id. */
/* Patch meta. Start by setting all program ids to the current program id. */
Meta *meta = &g_meta_cache.meta;
meta->acid->title_id_min = title_id;
meta->acid->title_id_max = title_id;
meta->aci->title_id = title_id;
meta->acid->program_id_min = program_id;
meta->acid->program_id_max = program_id;
meta->aci->program_id = program_id;
/* For HBL, we need to copy some information from the base meta. */
if (cfg::IsHblOverrideKeyHeld(title_id)) {
if (R_SUCCEEDED(OpenCodeFileFromBaseExefs(f, title_id, MetaFilePath))) {
if (cfg::IsHblOverrideKeyHeld(program_id)) {
if (R_SUCCEEDED(OpenCodeFileFromBaseExefs(f, program_id, MetaFilePath))) {
ON_SCOPE_EXIT { fclose(f); };
if (R_SUCCEEDED(LoadMetaFromFile(f, &g_original_meta_cache))) {
Meta *o_meta = &g_original_meta_cache.meta;
@ -181,23 +181,23 @@ namespace ams::ldr {
}
/* Set output. */
g_cached_title_id = title_id;
g_cached_program_id = program_id;
*out_meta = *meta;
return ResultSuccess();
}
Result LoadMetaFromCache(Meta *out_meta, ncm::TitleId title_id) {
if (g_cached_title_id != title_id) {
return LoadMeta(out_meta, title_id);
Result LoadMetaFromCache(Meta *out_meta, ncm::ProgramId program_id) {
if (g_cached_program_id != program_id) {
return LoadMeta(out_meta, program_id);
}
*out_meta = g_meta_cache.meta;
return ResultSuccess();
}
void InvalidateMetaCache() {
/* Set the cached title id back to zero. */
g_cached_title_id = {};
/* Set the cached program id back to zero. */
g_cached_program_id = {};
}
}

View file

@ -33,8 +33,8 @@ namespace ams::ldr {
};
/* Meta API. */
Result LoadMeta(Meta *out_meta, ncm::TitleId title_id);
Result LoadMetaFromCache(Meta *out_meta, ncm::TitleId title_id);
Result LoadMeta(Meta *out_meta, ncm::ProgramId program_id);
Result LoadMetaFromCache(Meta *out_meta, ncm::ProgramId program_id);
void InvalidateMetaCache();
}

View file

@ -73,7 +73,7 @@ namespace ams::ldr {
struct CreateProcessInfo {
char name[12];
u32 version;
ncm::TitleId title_id;
ncm::ProgramId program_id;
u64 code_address;
u32 code_num_pages;
u32 flags;
@ -95,8 +95,8 @@ namespace ams::ldr {
NsoHeader g_nso_headers[Nso_Count];
/* Anti-downgrade. */
struct MinimumTitleVersion {
ncm::TitleId title_id;
struct MinimumProgramVersion {
ncm::ProgramId program_id;
u32 version;
};
@ -104,104 +104,104 @@ namespace ams::ldr {
return (major << 26) | (minor << 20) | (micro << 16);
}
constexpr MinimumTitleVersion g_MinimumTitleVersions810[] = {
{ncm::TitleId::Settings, 1},
{ncm::TitleId::Bus, 1},
{ncm::TitleId::Audio, 1},
{ncm::TitleId::NvServices, 1},
{ncm::TitleId::Ns, 1},
{ncm::TitleId::Ssl, 1},
{ncm::TitleId::Es, 1},
{ncm::TitleId::Creport, 1},
{ncm::TitleId::Ro, 1},
constexpr MinimumProgramVersion g_MinimumProgramVersions810[] = {
{ncm::ProgramId::Settings, 1},
{ncm::ProgramId::Bus, 1},
{ncm::ProgramId::Audio, 1},
{ncm::ProgramId::NvServices, 1},
{ncm::ProgramId::Ns, 1},
{ncm::ProgramId::Ssl, 1},
{ncm::ProgramId::Es, 1},
{ncm::ProgramId::Creport, 1},
{ncm::ProgramId::Ro, 1},
};
constexpr size_t g_MinimumTitleVersionsCount810 = util::size(g_MinimumTitleVersions810);
constexpr size_t g_MinimumProgramVersionsCount810 = util::size(g_MinimumProgramVersions810);
constexpr MinimumTitleVersion g_MinimumTitleVersions900[] = {
constexpr MinimumProgramVersion g_MinimumProgramVersions900[] = {
/* All non-Development System Modules. */
{ncm::TitleId::Usb, MakeSystemVersion(9, 0, 0)},
{ncm::TitleId::Tma, MakeSystemVersion(9, 0, 0)},
{ncm::TitleId::Boot2, MakeSystemVersion(9, 0, 0)},
{ncm::TitleId::Settings, MakeSystemVersion(9, 0, 0)},
{ncm::TitleId::Bus, MakeSystemVersion(9, 0, 0)},
{ncm::TitleId::Bluetooth, MakeSystemVersion(9, 0, 0)},
{ncm::TitleId::Bcat, MakeSystemVersion(9, 0, 0)},
/* {ncm::TitleId::Dmnt, MakeSystemVersion(9, 0, 0)}, */
{ncm::TitleId::Friends, MakeSystemVersion(9, 0, 0)},
{ncm::TitleId::Nifm, MakeSystemVersion(9, 0, 0)},
{ncm::TitleId::Ptm, MakeSystemVersion(9, 0, 0)},
/* {ncm::TitleId::Shell, MakeSystemVersion(9, 0, 0)}, */
{ncm::TitleId::BsdSockets, MakeSystemVersion(9, 0, 0)},
{ncm::TitleId::Hid, MakeSystemVersion(9, 0, 0)},
{ncm::TitleId::Audio, MakeSystemVersion(9, 0, 0)},
{ncm::TitleId::LogManager, MakeSystemVersion(9, 0, 0)},
{ncm::TitleId::Wlan, MakeSystemVersion(9, 0, 0)},
/* {ncm::TitleId::Cs, MakeSystemVersion(9, 0, 0)}, */
{ncm::TitleId::Ldn, MakeSystemVersion(9, 0, 0)},
{ncm::TitleId::NvServices, MakeSystemVersion(9, 0, 0)},
{ncm::TitleId::Pcv, MakeSystemVersion(9, 0, 0)},
{ncm::TitleId::Ppc, MakeSystemVersion(9, 0, 0)},
{ncm::TitleId::NvnFlinger, MakeSystemVersion(9, 0, 0)},
{ncm::TitleId::Pcie, MakeSystemVersion(9, 0, 0)},
{ncm::TitleId::Account, MakeSystemVersion(9, 0, 0)},
{ncm::TitleId::Ns, MakeSystemVersion(9, 0, 0)},
{ncm::TitleId::Nfc, MakeSystemVersion(9, 0, 0)},
{ncm::TitleId::Psc, MakeSystemVersion(9, 0, 0)},
{ncm::TitleId::CapSrv, MakeSystemVersion(9, 0, 0)},
{ncm::TitleId::Am, MakeSystemVersion(9, 0, 0)},
{ncm::TitleId::Ssl, MakeSystemVersion(9, 0, 0)},
{ncm::TitleId::Nim, MakeSystemVersion(9, 0, 0)},
/* {ncm::TitleId::Cec, MakeSystemVersion(9, 0, 0)}, */
/* {ncm::TitleId::Tspm, MakeSystemVersion(9, 0, 0)}, */
/* {ncm::TitleId::Spl, MakeSystemVersion(9, 0, 0)}, */
{ncm::TitleId::Lbl, MakeSystemVersion(9, 0, 0)},
{ncm::TitleId::Btm, MakeSystemVersion(9, 0, 0)},
{ncm::TitleId::Erpt, MakeSystemVersion(9, 0, 0)},
/* {ncm::TitleId::Time, MakeSystemVersion(9, 0, 0)}, */
{ncm::TitleId::Vi, MakeSystemVersion(9, 0, 0)},
{ncm::TitleId::Pctl, MakeSystemVersion(9, 0, 0)},
{ncm::TitleId::Npns, MakeSystemVersion(9, 0, 0)},
{ncm::TitleId::Eupld, MakeSystemVersion(9, 0, 0)},
{ncm::TitleId::Glue, MakeSystemVersion(9, 0, 0)},
{ncm::TitleId::Eclct, MakeSystemVersion(9, 0, 0)},
{ncm::TitleId::Es, MakeSystemVersion(9, 0, 0)},
{ncm::TitleId::Fatal, MakeSystemVersion(9, 0, 0)},
{ncm::TitleId::Grc, MakeSystemVersion(9, 0, 0)},
{ncm::TitleId::Creport, MakeSystemVersion(9, 0, 0)},
{ncm::TitleId::Ro, MakeSystemVersion(9, 0, 0)},
/* {ncm::TitleId::Profiler, MakeSystemVersion(9, 0, 0)}, */
{ncm::TitleId::Sdb, MakeSystemVersion(9, 0, 0)},
{ncm::TitleId::Migration, MakeSystemVersion(9, 0, 0)},
/* {ncm::TitleId::Jit, MakeSystemVersion(9, 0, 0)}, */
{ncm::TitleId::JpegDec, MakeSystemVersion(9, 0, 0)},
{ncm::TitleId::SafeMode, MakeSystemVersion(9, 0, 0)},
{ncm::TitleId::Olsc, MakeSystemVersion(9, 0, 0)},
/* {ncm::TitleId::Dt, MakeSystemVersion(9, 0, 0)}, */
/* {ncm::TitleId::Nd, MakeSystemVersion(9, 0, 0)}, */
{ncm::TitleId::Ngct, MakeSystemVersion(9, 0, 0)},
{ncm::ProgramId::Usb, MakeSystemVersion(9, 0, 0)},
{ncm::ProgramId::Tma, MakeSystemVersion(9, 0, 0)},
{ncm::ProgramId::Boot2, MakeSystemVersion(9, 0, 0)},
{ncm::ProgramId::Settings, MakeSystemVersion(9, 0, 0)},
{ncm::ProgramId::Bus, MakeSystemVersion(9, 0, 0)},
{ncm::ProgramId::Bluetooth, MakeSystemVersion(9, 0, 0)},
{ncm::ProgramId::Bcat, MakeSystemVersion(9, 0, 0)},
/* {ncm::ProgramId::Dmnt, MakeSystemVersion(9, 0, 0)}, */
{ncm::ProgramId::Friends, MakeSystemVersion(9, 0, 0)},
{ncm::ProgramId::Nifm, MakeSystemVersion(9, 0, 0)},
{ncm::ProgramId::Ptm, MakeSystemVersion(9, 0, 0)},
/* {ncm::ProgramId::Shell, MakeSystemVersion(9, 0, 0)}, */
{ncm::ProgramId::BsdSockets, MakeSystemVersion(9, 0, 0)},
{ncm::ProgramId::Hid, MakeSystemVersion(9, 0, 0)},
{ncm::ProgramId::Audio, MakeSystemVersion(9, 0, 0)},
{ncm::ProgramId::LogManager, MakeSystemVersion(9, 0, 0)},
{ncm::ProgramId::Wlan, MakeSystemVersion(9, 0, 0)},
/* {ncm::ProgramId::Cs, MakeSystemVersion(9, 0, 0)}, */
{ncm::ProgramId::Ldn, MakeSystemVersion(9, 0, 0)},
{ncm::ProgramId::NvServices, MakeSystemVersion(9, 0, 0)},
{ncm::ProgramId::Pcv, MakeSystemVersion(9, 0, 0)},
{ncm::ProgramId::Ppc, MakeSystemVersion(9, 0, 0)},
{ncm::ProgramId::NvnFlinger, MakeSystemVersion(9, 0, 0)},
{ncm::ProgramId::Pcie, MakeSystemVersion(9, 0, 0)},
{ncm::ProgramId::Account, MakeSystemVersion(9, 0, 0)},
{ncm::ProgramId::Ns, MakeSystemVersion(9, 0, 0)},
{ncm::ProgramId::Nfc, MakeSystemVersion(9, 0, 0)},
{ncm::ProgramId::Psc, MakeSystemVersion(9, 0, 0)},
{ncm::ProgramId::CapSrv, MakeSystemVersion(9, 0, 0)},
{ncm::ProgramId::Am, MakeSystemVersion(9, 0, 0)},
{ncm::ProgramId::Ssl, MakeSystemVersion(9, 0, 0)},
{ncm::ProgramId::Nim, MakeSystemVersion(9, 0, 0)},
/* {ncm::ProgramId::Cec, MakeSystemVersion(9, 0, 0)}, */
/* {ncm::ProgramId::Tspm, MakeSystemVersion(9, 0, 0)}, */
/* {ncm::ProgramId::Spl, MakeSystemVersion(9, 0, 0)}, */
{ncm::ProgramId::Lbl, MakeSystemVersion(9, 0, 0)},
{ncm::ProgramId::Btm, MakeSystemVersion(9, 0, 0)},
{ncm::ProgramId::Erpt, MakeSystemVersion(9, 0, 0)},
/* {ncm::ProgramId::Time, MakeSystemVersion(9, 0, 0)}, */
{ncm::ProgramId::Vi, MakeSystemVersion(9, 0, 0)},
{ncm::ProgramId::Pctl, MakeSystemVersion(9, 0, 0)},
{ncm::ProgramId::Npns, MakeSystemVersion(9, 0, 0)},
{ncm::ProgramId::Eupld, MakeSystemVersion(9, 0, 0)},
{ncm::ProgramId::Glue, MakeSystemVersion(9, 0, 0)},
{ncm::ProgramId::Eclct, MakeSystemVersion(9, 0, 0)},
{ncm::ProgramId::Es, MakeSystemVersion(9, 0, 0)},
{ncm::ProgramId::Fatal, MakeSystemVersion(9, 0, 0)},
{ncm::ProgramId::Grc, MakeSystemVersion(9, 0, 0)},
{ncm::ProgramId::Creport, MakeSystemVersion(9, 0, 0)},
{ncm::ProgramId::Ro, MakeSystemVersion(9, 0, 0)},
/* {ncm::ProgramId::Profiler, MakeSystemVersion(9, 0, 0)}, */
{ncm::ProgramId::Sdb, MakeSystemVersion(9, 0, 0)},
{ncm::ProgramId::Migration, MakeSystemVersion(9, 0, 0)},
/* {ncm::ProgramId::Jit, MakeSystemVersion(9, 0, 0)}, */
{ncm::ProgramId::JpegDec, MakeSystemVersion(9, 0, 0)},
{ncm::ProgramId::SafeMode, MakeSystemVersion(9, 0, 0)},
{ncm::ProgramId::Olsc, MakeSystemVersion(9, 0, 0)},
/* {ncm::ProgramId::Dt, MakeSystemVersion(9, 0, 0)}, */
/* {ncm::ProgramId::Nd, MakeSystemVersion(9, 0, 0)}, */
{ncm::ProgramId::Ngct, MakeSystemVersion(9, 0, 0)},
/* All Web Applets. */
{ncm::TitleId::AppletWeb, MakeSystemVersion(9, 0, 0)},
{ncm::TitleId::AppletShop, MakeSystemVersion(9, 0, 0)},
{ncm::TitleId::AppletOfflineWeb, MakeSystemVersion(9, 0, 0)},
{ncm::TitleId::AppletLoginShare, MakeSystemVersion(9, 0, 0)},
{ncm::TitleId::AppletWifiWebAuth, MakeSystemVersion(9, 0, 0)},
{ncm::ProgramId::AppletWeb, MakeSystemVersion(9, 0, 0)},
{ncm::ProgramId::AppletShop, MakeSystemVersion(9, 0, 0)},
{ncm::ProgramId::AppletOfflineWeb, MakeSystemVersion(9, 0, 0)},
{ncm::ProgramId::AppletLoginShare, MakeSystemVersion(9, 0, 0)},
{ncm::ProgramId::AppletWifiWebAuth, MakeSystemVersion(9, 0, 0)},
};
constexpr size_t g_MinimumTitleVersionsCount900 = util::size(g_MinimumTitleVersions900);
constexpr size_t g_MinimumProgramVersionsCount900 = util::size(g_MinimumProgramVersions900);
Result ValidateTitleVersion(ncm::TitleId title_id, u32 version) {
Result ValidateProgramVersion(ncm::ProgramId program_id, u32 version) {
R_UNLESS(hos::GetVersion() >= hos::Version_810, ResultSuccess());
#ifdef LDR_VALIDATE_PROCESS_VERSION
const MinimumTitleVersion *entries = nullptr;
const MinimumProgramVersion *entries = nullptr;
size_t num_entries = 0;
switch (hos::GetVersion()) {
case hos::Version_810:
entries = g_MinimumTitleVersions810;
num_entries = g_MinimumTitleVersionsCount810;
entries = g_MinimumProgramVersions810;
num_entries = g_MinimumProgramVersionsCount810;
break;
case hos::Version_900:
entries = g_MinimumTitleVersions900;
num_entries = g_MinimumTitleVersionsCount900;
entries = g_MinimumProgramVersions900;
num_entries = g_MinimumProgramVersionsCount900;
break;
default:
entries = nullptr;
@ -210,7 +210,7 @@ namespace ams::ldr {
}
for (size_t i = 0; i < num_entries; i++) {
if (entries[i].title_id == title_id) {
if (entries[i].program_id == program_id) {
R_UNLESS(entries[i].version <= version, ResultInvalidVersion());
}
}
@ -224,7 +224,7 @@ namespace ams::ldr {
out->main_thread_priority = meta->npdm->main_thread_priority;
out->default_cpu_id = meta->npdm->default_cpu_id;
out->main_thread_stack_size = meta->npdm->main_thread_stack_size;
out->title_id = meta->aci->title_id;
out->program_id = meta->aci->program_id;
/* Copy access controls. */
size_t offset = 0;
@ -265,14 +265,14 @@ namespace ams::ldr {
return static_cast<Acid::PoolPartition>((meta->acid->flags & Acid::AcidFlag_PoolPartitionMask) >> Acid::AcidFlag_PoolPartitionShift);
}
Result LoadNsoHeaders(ncm::TitleId title_id, NsoHeader *nso_headers, bool *has_nso) {
Result LoadNsoHeaders(ncm::ProgramId program_id, NsoHeader *nso_headers, bool *has_nso) {
/* Clear NSOs. */
std::memset(nso_headers, 0, sizeof(*nso_headers) * Nso_Count);
std::memset(has_nso, 0, sizeof(*has_nso) * Nso_Count);
for (size_t i = 0; i < Nso_Count; i++) {
FILE *f = nullptr;
if (R_SUCCEEDED(OpenCodeFile(f, title_id, GetNsoName(i)))) {
if (R_SUCCEEDED(OpenCodeFile(f, program_id, GetNsoName(i)))) {
ON_SCOPE_EXIT { fclose(f); };
/* Read NSO header. */
R_UNLESS(fread(nso_headers + i, sizeof(*nso_headers), 1, f) == 1, ResultInvalidNso());
@ -302,13 +302,13 @@ namespace ams::ldr {
return ResultSuccess();
}
Result ValidateMeta(const Meta *meta, const ncm::TitleLocation &loc) {
Result ValidateMeta(const Meta *meta, const ncm::ProgramLocation &loc) {
/* Validate version. */
R_TRY(ValidateTitleVersion(loc.title_id, meta->npdm->version));
R_TRY(ValidateProgramVersion(loc.program_id, meta->npdm->version));
/* Validate title id. */
R_UNLESS(meta->aci->title_id >= meta->acid->title_id_min, ResultInvalidProgramId());
R_UNLESS(meta->aci->title_id <= meta->acid->title_id_max, ResultInvalidProgramId());
/* Validate program id. */
R_UNLESS(meta->aci->program_id >= meta->acid->program_id_min, ResultInvalidProgramId());
R_UNLESS(meta->aci->program_id <= meta->acid->program_id_max, ResultInvalidProgramId());
/* Validate the kernel capabilities. */
R_TRY(caps::ValidateCapabilities(meta->acid_kac, meta->acid->kac_size, meta->aci_kac, meta->aci->kac_size));
@ -404,10 +404,10 @@ namespace ams::ldr {
/* Clear output. */
std::memset(out, 0, sizeof(*out));
/* Set name, version, title id, resource limit handle. */
std::memcpy(out->name, meta->npdm->title_name, sizeof(out->name) - 1);
/* Set name, version, program id, resource limit handle. */
std::memcpy(out->name, meta->npdm->program_name, sizeof(out->name) - 1);
out->version = meta->npdm->version;
out->title_id = meta->aci->title_id;
out->program_id = meta->aci->program_id;
out->reslimit = reslimit_h;
/* Set flags. */
@ -611,14 +611,14 @@ namespace ams::ldr {
return ResultSuccess();
}
Result LoadNsosIntoProcessMemory(const ProcessInfo *process_info, const ncm::TitleId title_id, const NsoHeader *nso_headers, const bool *has_nso, const args::ArgumentInfo *arg_info) {
Result LoadNsosIntoProcessMemory(const ProcessInfo *process_info, const ncm::ProgramId program_id, const NsoHeader *nso_headers, const bool *has_nso, const args::ArgumentInfo *arg_info) {
const Handle process_handle = process_info->process_handle.Get();
/* Load each NSO. */
for (size_t i = 0; i < Nso_Count; i++) {
if (has_nso[i]) {
FILE *f = nullptr;
R_TRY(OpenCodeFile(f, title_id, GetNsoName(i)));
R_TRY(OpenCodeFile(f, program_id, GetNsoName(i)));
ON_SCOPE_EXIT { fclose(f); };
uintptr_t map_address = 0;
@ -655,11 +655,11 @@ namespace ams::ldr {
}
/* Process Creation API. */
Result CreateProcess(Handle *out, PinId pin_id, const ncm::TitleLocation &loc, const char *path, u32 flags, Handle reslimit_h) {
Result CreateProcess(Handle *out, PinId pin_id, const ncm::ProgramLocation &loc, const char *path, u32 flags, Handle reslimit_h) {
/* Use global storage for NSOs. */
NsoHeader *nso_headers = g_nso_headers;
bool *has_nso = g_has_nso;
const auto arg_info = args::Get(loc.title_id);
const auto arg_info = args::Get(loc.program_id);
{
/* Mount code. */
@ -668,13 +668,13 @@ namespace ams::ldr {
/* Load meta, possibly from cache. */
Meta meta;
R_TRY(LoadMetaFromCache(&meta, loc.title_id));
R_TRY(LoadMetaFromCache(&meta, loc.program_id));
/* Validate meta. */
R_TRY(ValidateMeta(&meta, loc));
/* Load, validate NSOs. */
R_TRY(LoadNsoHeaders(loc.title_id, nso_headers, has_nso));
R_TRY(LoadNsoHeaders(loc.program_id, nso_headers, has_nso));
R_TRY(ValidateNsoHeaders(nso_headers, has_nso));
/* Actually create process. */
@ -682,7 +682,7 @@ namespace ams::ldr {
R_TRY(CreateProcessImpl(&info, &meta, nso_headers, has_nso, arg_info, flags, reslimit_h));
/* Load NSOs into process memory. */
R_TRY(LoadNsosIntoProcessMemory(&info, loc.title_id, nso_headers, has_nso, arg_info));
R_TRY(LoadNsosIntoProcessMemory(&info, loc.program_id, nso_headers, has_nso, arg_info));
/* Register NSOs with ro manager. */
{
@ -690,7 +690,7 @@ namespace ams::ldr {
os::ProcessId process_id = os::GetProcessId(info.process_handle.Get());
/* Register new process. */
ldr::ro::RegisterProcess(pin_id, process_id, loc.title_id);
ldr::ro::RegisterProcess(pin_id, process_id, loc.program_id);
/* Register all NSOs. */
for (size_t i = 0; i < Nso_Count; i++) {
@ -706,11 +706,11 @@ namespace ams::ldr {
RedirectHtmlDocumentPathForHbl(loc);
}
/* Clear the ECS entry for the title. */
R_ASSERT(ecs::Clear(loc.title_id));
/* Clear the ECS entry for the program. */
R_ASSERT(ecs::Clear(loc.program_id));
/* Note that we've created the title. */
SetLaunchedTitle(loc.title_id);
/* Note that we've created the program. */
SetLaunchedProgram(loc.program_id);
/* Move the process handle to output. */
*out = info.process_handle.Move();
@ -719,14 +719,14 @@ namespace ams::ldr {
return ResultSuccess();
}
Result GetProgramInfo(ProgramInfo *out, const ncm::TitleLocation &loc) {
Result GetProgramInfo(ProgramInfo *out, const ncm::ProgramLocation &loc) {
Meta meta;
/* Load Meta. */
{
ScopedCodeMount mount(loc);
R_TRY(mount.GetResult());
R_TRY(LoadMeta(&meta, loc.title_id));
R_TRY(LoadMeta(&meta, loc.program_id));
}
return GetProgramInfoFromMeta(out, &meta);

View file

@ -19,7 +19,7 @@
namespace ams::ldr {
/* Process Creation API. */
Result CreateProcess(Handle *out, PinId pin_id, const ncm::TitleLocation &loc, const char *path, u32 flags, Handle reslimit_h);
Result GetProgramInfo(ProgramInfo *out, const ncm::TitleLocation &loc);
Result CreateProcess(Handle *out, PinId pin_id, const ncm::ProgramLocation &loc, const char *path, u32 flags, Handle reslimit_h);
Result GetProgramInfo(ProgramInfo *out, const ncm::ProgramLocation &loc);
}

View file

@ -33,8 +33,8 @@ namespace ams::ldr::ro {
struct ProcessInfo {
PinId pin_id;
os::ProcessId process_id;
ncm::TitleId title_id;
ncm::TitleLocation loc;
ncm::ProgramId program_id;
ncm::ProgramLocation loc;
ModuleInfo modules[ModuleCountMax];
bool in_use;
};
@ -76,7 +76,7 @@ namespace ams::ldr::ro {
}
/* RO Manager API. */
Result PinTitle(PinId *out, const ncm::TitleLocation &loc) {
Result PinProgram(PinId *out, const ncm::ProgramLocation &loc) {
*out = InvalidPinId;
ProcessInfo *info = GetFreeProcessInfo();
R_UNLESS(info != nullptr, ldr::ResultTooManyProcesses());
@ -91,7 +91,7 @@ namespace ams::ldr::ro {
return ResultSuccess();
}
Result UnpinTitle(PinId id) {
Result UnpinProgram(PinId id) {
ProcessInfo *info = GetProcessInfo(id);
R_UNLESS(info != nullptr, ldr::ResultNotPinned());
@ -100,7 +100,7 @@ namespace ams::ldr::ro {
}
Result GetTitleLocation(ncm::TitleLocation *out, PinId id) {
Result GetProgramLocation(ncm::ProgramLocation *out, PinId id) {
ProcessInfo *info = GetProcessInfo(id);
R_UNLESS(info != nullptr, ldr::ResultNotPinned());
@ -108,11 +108,11 @@ namespace ams::ldr::ro {
return ResultSuccess();
}
Result RegisterProcess(PinId id, os::ProcessId process_id, ncm::TitleId title_id) {
Result RegisterProcess(PinId id, os::ProcessId process_id, ncm::ProgramId program_id) {
ProcessInfo *info = GetProcessInfo(id);
R_UNLESS(info != nullptr, ldr::ResultNotPinned());
info->title_id = title_id;
info->program_id = program_id;
info->process_id = process_id;
return ResultSuccess();
}

View file

@ -19,10 +19,10 @@
namespace ams::ldr::ro {
/* RO Manager API. */
Result PinTitle(PinId *out, const ncm::TitleLocation &loc);
Result UnpinTitle(PinId id);
Result GetTitleLocation(ncm::TitleLocation *out, PinId id);
Result RegisterProcess(PinId id, os::ProcessId process_id, ncm::TitleId title_id);
Result PinProgram(PinId *out, const ncm::ProgramLocation &loc);
Result UnpinProgram(PinId id);
Result GetProgramLocation(ncm::ProgramLocation *out, PinId id);
Result RegisterProcess(PinId id, os::ProcessId process_id, ncm::ProgramId program_id);
Result RegisterModule(PinId id, const u8 *build_id, uintptr_t address, size_t size);
Result GetProcessModuleInfo(u32 *out_count, ModuleInfo *out, size_t max_out_count, os::ProcessId process_id);

View file

@ -17,7 +17,7 @@
namespace ams::pm::impl {
ProcessInfo::ProcessInfo(Handle h, os::ProcessId pid, ldr::PinId pin, const ncm::TitleLocation &l) : process_id(pid), pin_id(pin), loc(l), handle(h), state(ProcessState_Created), flags(0), waitable_holder(h) {
ProcessInfo::ProcessInfo(Handle h, os::ProcessId pid, ldr::PinId pin, const ncm::ProgramLocation &l) : process_id(pid), pin_id(pin), loc(l), handle(h), state(ProcessState_Created), flags(0), waitable_holder(h) {
this->waitable_holder.SetUserData(reinterpret_cast<uintptr_t>(this));
}
@ -30,7 +30,7 @@ namespace ams::pm::impl {
/* Unregister the process. */
fsprUnregisterProgram(static_cast<u64>(this->process_id));
sm::manager::UnregisterProcess(this->process_id);
ldr::pm::UnpinTitle(this->pin_id);
ldr::pm::UnpinProgram(this->pin_id);
/* Close the process's handle. */
svcCloseHandle(this->handle);

View file

@ -40,7 +40,7 @@ namespace ams::pm::impl {
util::IntrusiveListNode list_node;
const os::ProcessId process_id;
const ldr::PinId pin_id;
const ncm::TitleLocation loc;
const ncm::ProgramLocation loc;
Handle handle;
ProcessState state;
u32 flags;
@ -58,7 +58,7 @@ namespace ams::pm::impl {
return (this->flags & flag);
}
public:
ProcessInfo(Handle h, os::ProcessId pid, ldr::PinId pin, const ncm::TitleLocation &l);
ProcessInfo(Handle h, os::ProcessId pid, ldr::PinId pin, const ncm::ProgramLocation &l);
~ProcessInfo();
void Cleanup();
@ -78,7 +78,7 @@ namespace ams::pm::impl {
return this->pin_id;
}
const ncm::TitleLocation &GetTitleLocation() {
const ncm::ProgramLocation &GetProgramLocation() {
return this->loc;
}
@ -179,9 +179,9 @@ namespace ams::pm::impl {
return nullptr;
}
ProcessInfo *Find(ncm::TitleId title_id) {
ProcessInfo *Find(ncm::ProgramId program_id) {
for (auto it = this->begin(); it != this->end(); it++) {
if ((*it).GetTitleLocation().title_id == title_id) {
if ((*it).GetProgramLocation().program_id == program_id) {
return &*it;
}
}

View file

@ -24,13 +24,13 @@ namespace ams::pm::impl {
/* Types. */
enum HookType {
HookType_TitleId = (1 << 0),
HookType_ProgramId = (1 << 0),
HookType_Application = (1 << 1),
};
struct LaunchProcessArgs {
os::ProcessId *out_process_id;
ncm::TitleLocation location;
ncm::ProgramLocation location;
u32 flags;
};
@ -202,7 +202,7 @@ namespace ams::pm::impl {
LaunchProcessArgs g_process_launch_args = {};
/* Hook globals. */
std::atomic<ncm::TitleId> g_title_id_hook;
std::atomic<ncm::ProgramId> g_program_id_hook;
std::atomic<bool> g_application_hook;
/* Forward declarations. */
@ -284,12 +284,12 @@ namespace ams::pm::impl {
/* Ensure we only try to run one application. */
R_UNLESS(!is_application || !HasApplicationProcess(), pm::ResultApplicationRunning());
/* Fix the title location to use the right title id. */
const ncm::TitleLocation location = ncm::TitleLocation::Make(program_info.title_id, static_cast<ncm::StorageId>(args.location.storage_id));
/* Fix the program location to use the right program id. */
const ncm::ProgramLocation location = ncm::ProgramLocation::Make(program_info.program_id, static_cast<ncm::StorageId>(args.location.storage_id));
/* Pin the program with loader. */
ldr::PinId pin_id;
R_TRY(ldr::pm::PinTitle(&pin_id, location));
R_TRY(ldr::pm::PinProgram(&pin_id, location));
/* Ensure resources are available. */
@ -298,7 +298,7 @@ namespace ams::pm::impl {
/* Actually create the process. */
Handle process_handle;
{
auto pin_guard = SCOPE_GUARD { ldr::pm::UnpinTitle(pin_id); };
auto pin_guard = SCOPE_GUARD { ldr::pm::UnpinProgram(pin_id); };
R_TRY(ldr::pm::CreateProcess(&process_handle, pin_id, GetLoaderCreateProcessFlags(args.flags), resource::GetResourceLimitHandle(&program_info)));
pin_guard.Cancel();
}
@ -331,8 +331,8 @@ namespace ams::pm::impl {
const u8 *aci_fah = acid_fac + program_info.acid_fac_size;
/* Register with FS and SM. */
R_TRY(fsprRegisterProgram(static_cast<u64>(process_id), static_cast<u64>(location.title_id), static_cast<FsStorageId>(location.storage_id), aci_fah, program_info.aci_fah_size, acid_fac, program_info.acid_fac_size));
R_TRY(sm::manager::RegisterProcess(process_id, location.title_id, acid_sac, program_info.acid_sac_size, aci_sac, program_info.aci_sac_size));
R_TRY(fsprRegisterProgram(static_cast<u64>(process_id), static_cast<u64>(location.program_id), static_cast<FsStorageId>(location.storage_id), aci_fah, program_info.aci_fah_size, acid_fac, program_info.acid_fac_size));
R_TRY(sm::manager::RegisterProcess(process_id, location.program_id, acid_sac, program_info.acid_sac_size, aci_sac, program_info.aci_sac_size));
/* Set flags. */
if (is_application) {
@ -349,9 +349,9 @@ namespace ams::pm::impl {
}
/* Process hooks/signaling. */
if (location.title_id == g_title_id_hook) {
if (location.program_id == g_program_id_hook) {
g_hook_to_create_process_event.Signal();
g_title_id_hook = ncm::TitleId::Invalid;
g_program_id_hook = ncm::ProgramId::Invalid;
} else if (is_application && g_application_hook) {
g_hook_to_create_application_process_event.Signal();
g_application_hook = false;
@ -466,8 +466,8 @@ namespace ams::pm::impl {
}
/* Process Management. */
Result LaunchTitle(os::ProcessId *out_process_id, const ncm::TitleLocation &loc, u32 flags) {
/* Ensure we only try to launch one title at a time. */
Result LaunchProgram(os::ProcessId *out_process_id, const ncm::ProgramLocation &loc, u32 flags) {
/* Ensure we only try to launch one program at a time. */
static os::Mutex s_lock;
std::scoped_lock lk(s_lock);
@ -491,7 +491,7 @@ namespace ams::pm::impl {
R_UNLESS(!process_info->HasStarted(), pm::ResultAlreadyStarted());
ldr::ProgramInfo program_info;
R_TRY(ldr::pm::GetProgramInfo(&program_info, process_info->GetTitleLocation()));
R_TRY(ldr::pm::GetProgramInfo(&program_info, process_info->GetProgramLocation()));
return StartProcess(process_info, &program_info);
}
@ -504,10 +504,10 @@ namespace ams::pm::impl {
return svcTerminateProcess(process_info->GetHandle());
}
Result TerminateTitle(ncm::TitleId title_id) {
Result TerminateProgram(ncm::ProgramId program_id) {
ProcessListAccessor list(g_process_list);
auto process_info = list->Find(title_id);
auto process_info = list->Find(program_id);
R_UNLESS(process_info != nullptr, pm::ResultProcessNotFound());
return svcTerminateProcess(process_info->GetHandle());
@ -615,23 +615,23 @@ namespace ams::pm::impl {
return ResultSuccess();
}
Result GetProcessId(os::ProcessId *out, ncm::TitleId title_id) {
Result GetProcessId(os::ProcessId *out, ncm::ProgramId program_id) {
ProcessListAccessor list(g_process_list);
auto process_info = list->Find(title_id);
auto process_info = list->Find(program_id);
R_UNLESS(process_info != nullptr, pm::ResultProcessNotFound());
*out = process_info->GetProcessId();
return ResultSuccess();
}
Result GetTitleId(ncm::TitleId *out, os::ProcessId process_id) {
Result GetProgramId(ncm::ProgramId *out, os::ProcessId process_id) {
ProcessListAccessor list(g_process_list);
auto process_info = list->Find(process_id);
R_UNLESS(process_info != nullptr, pm::ResultProcessNotFound());
*out = process_info->GetTitleLocation().title_id;
*out = process_info->GetProgramLocation().program_id;
return ResultSuccess();
}
@ -648,24 +648,24 @@ namespace ams::pm::impl {
return pm::ResultProcessNotFound();
}
Result AtmosphereGetProcessInfo(Handle *out_process_handle, ncm::TitleLocation *out_loc, os::ProcessId process_id) {
Result AtmosphereGetProcessInfo(Handle *out_process_handle, ncm::ProgramLocation *out_loc, os::ProcessId process_id) {
ProcessListAccessor list(g_process_list);
auto process_info = list->Find(process_id);
R_UNLESS(process_info != nullptr, pm::ResultProcessNotFound());
*out_process_handle = process_info->GetHandle();
*out_loc = process_info->GetTitleLocation();
*out_loc = process_info->GetProgramLocation();
return ResultSuccess();
}
/* Hook API. */
Result HookToCreateProcess(Handle *out_hook, ncm::TitleId title_id) {
Result HookToCreateProcess(Handle *out_hook, ncm::ProgramId program_id) {
*out_hook = INVALID_HANDLE;
{
ncm::TitleId old_value = ncm::TitleId::Invalid;
R_UNLESS(g_title_id_hook.compare_exchange_strong(old_value, title_id), pm::ResultDebugHookInUse());
ncm::ProgramId old_value = ncm::ProgramId::Invalid;
R_UNLESS(g_program_id_hook.compare_exchange_strong(old_value, program_id), pm::ResultDebugHookInUse());
}
*out_hook = g_hook_to_create_process_event.GetReadableHandle();
@ -685,8 +685,8 @@ namespace ams::pm::impl {
}
Result ClearHook(u32 which) {
if (which & HookType_TitleId) {
g_title_id_hook = ncm::TitleId::Invalid;
if (which & HookType_ProgramId) {
g_program_id_hook = ncm::ProgramId::Invalid;
}
if (which & HookType_Application) {
g_application_hook = false;

View file

@ -22,10 +22,10 @@ namespace ams::pm::impl {
Result InitializeProcessManager();
/* Process Management. */
Result LaunchTitle(os::ProcessId *out_process_id, const ncm::TitleLocation &loc, u32 flags);
Result LaunchProgram(os::ProcessId *out_process_id, const ncm::ProgramLocation &loc, u32 flags);
Result StartProcess(os::ProcessId process_id);
Result TerminateProcess(os::ProcessId process_id);
Result TerminateTitle(ncm::TitleId title_id);
Result TerminateProgram(ncm::ProgramId program_id);
Result GetProcessEventHandle(Handle *out);
Result GetProcessEventInfo(ProcessEventInfo *out);
Result CleanupProcess(os::ProcessId process_id);
@ -34,13 +34,13 @@ namespace ams::pm::impl {
/* Information Getters. */
Result GetModuleIdList(u32 *out_count, u8 *out_buf, size_t max_out_count, u64 unused);
Result GetExceptionProcessIdList(u32 *out_count, os::ProcessId *out_process_ids, size_t max_out_count);
Result GetProcessId(os::ProcessId *out, ncm::TitleId title_id);
Result GetTitleId(ncm::TitleId *out, os::ProcessId process_id);
Result GetProcessId(os::ProcessId *out, ncm::ProgramId program_id);
Result GetProgramId(ncm::ProgramId *out, os::ProcessId process_id);
Result GetApplicationProcessId(os::ProcessId *out_process_id);
Result AtmosphereGetProcessInfo(Handle *out_process_handle, ncm::TitleLocation *out_loc, os::ProcessId process_id);
Result AtmosphereGetProcessInfo(Handle *out_process_handle, ncm::ProgramLocation *out_loc, os::ProcessId process_id);
/* Hook API. */
Result HookToCreateProcess(Handle *out_hook, ncm::TitleId title_id);
Result HookToCreateProcess(Handle *out_hook, ncm::ProgramId program_id);
Result HookToCreateApplicationProcess(Handle *out_hook);
Result ClearHook(u32 which);

View file

@ -33,12 +33,12 @@ namespace ams::pm::dmnt {
return impl::StartProcess(process_id);
}
Result DebugMonitorServiceBase::GetProcessId(sf::Out<os::ProcessId> out, ncm::TitleId title_id) {
return impl::GetProcessId(out.GetPointer(), title_id);
Result DebugMonitorServiceBase::GetProcessId(sf::Out<os::ProcessId> out, ncm::ProgramId program_id) {
return impl::GetProcessId(out.GetPointer(), program_id);
}
Result DebugMonitorServiceBase::HookToCreateProcess(sf::OutCopyHandle out_hook, ncm::TitleId title_id) {
return impl::HookToCreateProcess(out_hook.GetHandlePointer(), title_id);
Result DebugMonitorServiceBase::HookToCreateProcess(sf::OutCopyHandle out_hook, ncm::ProgramId program_id) {
return impl::HookToCreateProcess(out_hook.GetHandlePointer(), program_id);
}
Result DebugMonitorServiceBase::GetApplicationProcessId(sf::Out<os::ProcessId> out) {
@ -54,7 +54,7 @@ namespace ams::pm::dmnt {
}
/* Atmosphere extension commands. */
Result DebugMonitorServiceBase::AtmosphereGetProcessInfo(sf::OutCopyHandle out_process_handle, sf::Out<ncm::TitleLocation> out_loc, os::ProcessId process_id) {
Result DebugMonitorServiceBase::AtmosphereGetProcessInfo(sf::OutCopyHandle out_process_handle, sf::Out<ncm::ProgramLocation> out_loc, os::ProcessId process_id) {
return impl::AtmosphereGetProcessInfo(out_process_handle.GetHandlePointer(), out_loc.GetPointer(), process_id);
}

View file

@ -24,14 +24,14 @@ namespace ams::pm::dmnt {
virtual Result GetModuleIdList(sf::Out<u32> out_count, const sf::OutBuffer &out_buf, u64 unused);
virtual Result GetExceptionProcessIdList(sf::Out<u32> out_count, const sf::OutArray<os::ProcessId> &out_process_ids);
virtual Result StartProcess(os::ProcessId process_id);
virtual Result GetProcessId(sf::Out<os::ProcessId> out, ncm::TitleId title_id);
virtual Result HookToCreateProcess(sf::OutCopyHandle out_hook, ncm::TitleId title_id);
virtual Result GetProcessId(sf::Out<os::ProcessId> out, ncm::ProgramId program_id);
virtual Result HookToCreateProcess(sf::OutCopyHandle out_hook, ncm::ProgramId program_id);
virtual Result GetApplicationProcessId(sf::Out<os::ProcessId> out);
virtual Result HookToCreateApplicationProcess(sf::OutCopyHandle out_hook);
virtual Result ClearHook(u32 which);
/* Atmosphere extension commands. */
virtual Result AtmosphereGetProcessInfo(sf::OutCopyHandle out_process_handle, sf::Out<ncm::TitleLocation> out_loc, os::ProcessId process_id);
virtual Result AtmosphereGetProcessInfo(sf::OutCopyHandle out_process_handle, sf::Out<ncm::ProgramLocation> out_loc, os::ProcessId process_id);
virtual Result AtmosphereGetCurrentLimitInfo(sf::Out<u64> out_cur_val, sf::Out<u64> out_lim_val, u32 group, u32 resource);
};

View file

@ -19,22 +19,22 @@
namespace ams::pm::info {
/* Overrides for libstratosphere pm::info commands. */
Result HasLaunchedTitle(bool *out, ncm::TitleId title_id) {
return ldr::pm::HasLaunchedTitle(out, title_id);
Result HasLaunchedProgram(bool *out, ncm::ProgramId program_id) {
return ldr::pm::HasLaunchedProgram(out, program_id);
}
/* Actual command implementations. */
Result InformationService::GetTitleId(sf::Out<ncm::TitleId> out, os::ProcessId process_id) {
return impl::GetTitleId(out.GetPointer(), process_id);
Result InformationService::GetProgramId(sf::Out<ncm::ProgramId> out, os::ProcessId process_id) {
return impl::GetProgramId(out.GetPointer(), process_id);
}
/* Atmosphere extension commands. */
Result InformationService::AtmosphereGetProcessId(sf::Out<os::ProcessId> out, ncm::TitleId title_id) {
return impl::GetProcessId(out.GetPointer(), title_id);
Result InformationService::AtmosphereGetProcessId(sf::Out<os::ProcessId> out, ncm::ProgramId program_id) {
return impl::GetProcessId(out.GetPointer(), program_id);
}
Result InformationService::AtmosphereHasLaunchedTitle(sf::Out<bool> out, ncm::TitleId title_id) {
return pm::info::HasLaunchedTitle(out.GetPointer(), title_id);
Result InformationService::AtmosphereHasLaunchedProgram(sf::Out<bool> out, ncm::ProgramId program_id) {
return pm::info::HasLaunchedProgram(out.GetPointer(), program_id);
}
}

View file

@ -21,24 +21,24 @@ namespace ams::pm::info {
class InformationService final : public sf::IServiceObject {
private:
enum class CommandId {
GetTitleId = 0,
GetProgramId = 0,
AtmosphereGetProcessId = 65000,
AtmosphereHasLaunchedTitle = 65001,
AtmosphereHasLaunchedProgram = 65001,
};
private:
/* Actual command implementations. */
Result GetTitleId(sf::Out<ncm::TitleId> out, os::ProcessId process_id);
Result GetProgramId(sf::Out<ncm::ProgramId> out, os::ProcessId process_id);
/* Atmosphere extension commands. */
Result AtmosphereGetProcessId(sf::Out<os::ProcessId> out, ncm::TitleId title_id);
Result AtmosphereHasLaunchedTitle(sf::Out<bool> out, ncm::TitleId title_id);
Result AtmosphereGetProcessId(sf::Out<os::ProcessId> out, ncm::ProgramId program_id);
Result AtmosphereHasLaunchedProgram(sf::Out<bool> out, ncm::ProgramId program_id);
public:
DEFINE_SERVICE_DISPATCH_TABLE {
MAKE_SERVICE_COMMAND_META(GetTitleId),
MAKE_SERVICE_COMMAND_META(GetProgramId),
MAKE_SERVICE_COMMAND_META(AtmosphereGetProcessId),
MAKE_SERVICE_COMMAND_META(AtmosphereHasLaunchedTitle),
MAKE_SERVICE_COMMAND_META(AtmosphereHasLaunchedProgram),
};
};

View file

@ -41,7 +41,7 @@ extern "C" {
namespace ams {
ncm::TitleId CurrentTitleId = ncm::TitleId::Pm;
ncm::ProgramId CurrentProgramId = ncm::ProgramId::Pm;
namespace result {
@ -76,13 +76,13 @@ namespace {
constexpr u8 PrivilegedServiceAccessControl[] = {0x80, '*', 0x00, '*'};
constexpr size_t ProcessCountMax = 0x40;
/* This uses debugging SVCs to retrieve a process's title id. */
ncm::TitleId GetProcessTitleId(os::ProcessId process_id) {
/* Check if we should return our title id. */
/* This uses debugging SVCs to retrieve a process's program id. */
ncm::ProgramId GetProcessProgramId(os::ProcessId process_id) {
/* Check if we should return our program id. */
/* Doing this here works around a bug fixed in 6.0.0. */
/* Not doing so will cause svcDebugActiveProcess to deadlock on lower firmwares if called for it's own process. */
if (process_id == os::GetCurrentProcessId()) {
return ams::CurrentTitleId;
return ams::CurrentProgramId;
}
/* Get a debug handle. */
@ -94,19 +94,19 @@ namespace {
while (true) {
R_ASSERT(svcGetDebugEvent(reinterpret_cast<u8 *>(&d), debug_handle.Get()));
if (d.type == svc::DebugEventType::AttachProcess) {
return ncm::TitleId{d.info.attach_process.title_id};
return ncm::ProgramId{d.info.attach_process.program_id};
}
}
}
/* This works around a bug fixed by FS in 4.0.0. */
/* Not doing so will cause KIPs with higher process IDs than 7 to be unable to use filesystem services. */
/* It also registers privileged processes with SM, so that their title IDs can be known. */
/* It also registers privileged processes with SM, so that their program ids can be known. */
void RegisterPrivilegedProcess(os::ProcessId process_id) {
fsprUnregisterProgram(static_cast<u64>(process_id));
fsprRegisterProgram(static_cast<u64>(process_id), static_cast<u64>(process_id), FsStorageId_NandSystem, PrivilegedFileAccessHeader, sizeof(PrivilegedFileAccessHeader), PrivilegedFileAccessControl, sizeof(PrivilegedFileAccessControl));
sm::manager::UnregisterProcess(process_id);
sm::manager::RegisterProcess(process_id, GetProcessTitleId(process_id), PrivilegedServiceAccessControl, sizeof(PrivilegedServiceAccessControl), PrivilegedServiceAccessControl, sizeof(PrivilegedServiceAccessControl));
sm::manager::RegisterProcess(process_id, GetProcessProgramId(process_id), PrivilegedServiceAccessControl, sizeof(PrivilegedServiceAccessControl), PrivilegedServiceAccessControl, sizeof(PrivilegedServiceAccessControl));
}
void RegisterPrivilegedProcesses() {

View file

@ -19,21 +19,21 @@
namespace ams::pm::shell {
/* Overrides for libstratosphere pm::shell commands. */
Result LaunchTitle(os::ProcessId *out_process_id, const ncm::TitleLocation &loc, u32 launch_flags) {
return impl::LaunchTitle(out_process_id, loc, launch_flags);
Result LaunchProgram(os::ProcessId *out_process_id, const ncm::ProgramLocation &loc, u32 launch_flags) {
return impl::LaunchProgram(out_process_id, loc, launch_flags);
}
/* Service command implementations. */
Result ShellServiceBase::LaunchTitle(sf::Out<os::ProcessId> out_process_id, const ncm::TitleLocation &loc, u32 flags) {
return pm::shell::LaunchTitle(out_process_id.GetPointer(), loc, flags);
Result ShellServiceBase::LaunchProgram(sf::Out<os::ProcessId> out_process_id, const ncm::ProgramLocation &loc, u32 flags) {
return pm::shell::LaunchProgram(out_process_id.GetPointer(), loc, flags);
}
Result ShellServiceBase::TerminateProcess(os::ProcessId process_id) {
return impl::TerminateProcess(process_id);
}
Result ShellServiceBase::TerminateTitle(ncm::TitleId title_id) {
return impl::TerminateTitle(title_id);
Result ShellServiceBase::TerminateProgram(ncm::ProgramId program_id) {
return impl::TerminateProgram(program_id);
}
void ShellServiceBase::GetProcessEventHandle(sf::OutCopyHandle out) {

View file

@ -21,9 +21,9 @@ namespace ams::pm::shell {
class ShellServiceBase : public sf::IServiceObject {
protected:
/* Actual command implementations. */
virtual Result LaunchTitle(sf::Out<os::ProcessId> out_process_id, const ncm::TitleLocation &loc, u32 flags);
virtual Result LaunchProgram(sf::Out<os::ProcessId> out_process_id, const ncm::ProgramLocation &loc, u32 flags);
virtual Result TerminateProcess(os::ProcessId process_id);
virtual Result TerminateTitle(ncm::TitleId title_id);
virtual Result TerminateProgram(ncm::ProgramId program_id);
virtual void GetProcessEventHandle(sf::OutCopyHandle out);
virtual void GetProcessEventInfo(sf::Out<ProcessEventInfo> out);
virtual Result CleanupProcess(os::ProcessId process_id);
@ -39,9 +39,9 @@ namespace ams::pm::shell {
class ShellService final : public ShellServiceBase {
private:
enum class CommandId {
LaunchTitle = 0,
LaunchProgram = 0,
TerminateProcess = 1,
TerminateTitle = 2,
TerminateProgram = 2,
GetProcessEventHandle = 3,
GetProcessEventInfo = 4,
NotifyBootFinished = 5,
@ -53,9 +53,9 @@ namespace ams::pm::shell {
public:
DEFINE_SERVICE_DISPATCH_TABLE {
/* 5.0.0-* */
MAKE_SERVICE_COMMAND_META(LaunchTitle),
MAKE_SERVICE_COMMAND_META(LaunchProgram),
MAKE_SERVICE_COMMAND_META(TerminateProcess),
MAKE_SERVICE_COMMAND_META(TerminateTitle),
MAKE_SERVICE_COMMAND_META(TerminateProgram),
MAKE_SERVICE_COMMAND_META(GetProcessEventHandle),
MAKE_SERVICE_COMMAND_META(GetProcessEventInfo),
MAKE_SERVICE_COMMAND_META(NotifyBootFinished),
@ -74,9 +74,9 @@ namespace ams::pm::shell {
class ShellServiceDeprecated final : public ShellServiceBase {
private:
enum class CommandId {
LaunchTitle = 0,
LaunchProgram = 0,
TerminateProcess = 1,
TerminateTitle = 2,
TerminateProgram = 2,
GetProcessEventHandle = 3,
GetProcessEventInfo = 4,
CleanupProcess = 5,
@ -88,9 +88,9 @@ namespace ams::pm::shell {
public:
DEFINE_SERVICE_DISPATCH_TABLE {
/* 1.0.0-4.1.0 */
MAKE_SERVICE_COMMAND_META(LaunchTitle),
MAKE_SERVICE_COMMAND_META(LaunchProgram),
MAKE_SERVICE_COMMAND_META(TerminateProcess),
MAKE_SERVICE_COMMAND_META(TerminateTitle),
MAKE_SERVICE_COMMAND_META(TerminateProgram),
MAKE_SERVICE_COMMAND_META(GetProcessEventHandle),
MAKE_SERVICE_COMMAND_META(GetProcessEventInfo),
MAKE_SERVICE_COMMAND_META(CleanupProcess),

View file

@ -27,8 +27,8 @@ namespace ams::ro::impl {
/* TODO: Check PSS fixed-key signature. */
R_UNLESS(true, ResultNotAuthorized());
/* Check TitleID pattern is valid. */
R_UNLESS(header->IsTitleIdValid(), ResultNotAuthorized());
/* Check ProgramId pattern is valid. */
R_UNLESS(header->IsProgramIdValid(), ResultNotAuthorized());
/* TODO: Check PSS signature over hashes. */
R_UNLESS(true, ResultNotAuthorized());
@ -36,7 +36,7 @@ namespace ams::ro::impl {
return ResultSuccess();
}
Result ValidateNrr(const NrrHeader *header, u64 size, ncm::TitleId title_id, ModuleType expected_type, bool enforce_type) {
Result ValidateNrr(const NrrHeader *header, u64 size, ncm::ProgramId program_id, ModuleType expected_type, bool enforce_type) {
/* Check magic. */
R_UNLESS(header->IsMagicValid(), ResultInvalidNrr());
@ -49,8 +49,8 @@ namespace ams::ro::impl {
/* Check signature. */
R_TRY(ValidateNrrSignature(header));
/* Check title id. */
R_UNLESS(header->GetTitleId() == title_id, ResultInvalidNrr());
/* Check program id. */
R_UNLESS(header->GetProgramId() == program_id, ResultInvalidNrr());
/* Check type. */
if (hos::GetVersion() >= hos::Version_700 && enforce_type) {
@ -64,7 +64,7 @@ namespace ams::ro::impl {
}
/* Utilities for working with NRRs. */
Result MapAndValidateNrr(NrrHeader **out_header, u64 *out_mapped_code_address, Handle process_handle, ncm::TitleId title_id, u64 nrr_heap_address, u64 nrr_heap_size, ModuleType expected_type, bool enforce_type) {
Result MapAndValidateNrr(NrrHeader **out_header, u64 *out_mapped_code_address, Handle process_handle, ncm::ProgramId program_id, u64 nrr_heap_address, u64 nrr_heap_size, ModuleType expected_type, bool enforce_type) {
map::MappedCodeMemory nrr_mcm(ResultInternalError{});
/* First, map the NRR. */
@ -79,7 +79,7 @@ namespace ams::ro::impl {
R_TRY(nrr_map.GetResult());
NrrHeader *nrr_header = reinterpret_cast<NrrHeader *>(map_address);
R_TRY(ValidateNrr(nrr_header, nrr_heap_size, title_id, expected_type, enforce_type));
R_TRY(ValidateNrr(nrr_header, nrr_heap_size, program_id, expected_type, enforce_type));
/* Invalidation here actually prevents them from unmapping at scope exit. */
nrr_map.Invalidate();

View file

@ -20,7 +20,7 @@
namespace ams::ro::impl {
/* Utilities for working with NRRs. */
Result MapAndValidateNrr(NrrHeader **out_header, u64 *out_mapped_code_address, Handle process_handle, ncm::TitleId title_id, u64 nrr_heap_address, u64 nrr_heap_size, ModuleType expected_type, bool enforce_type);
Result MapAndValidateNrr(NrrHeader **out_header, u64 *out_mapped_code_address, Handle process_handle, ncm::ProgramId program_id, u64 nrr_heap_address, u64 nrr_heap_size, ModuleType expected_type, bool enforce_type);
Result UnmapNrr(Handle process_handle, const NrrHeader *header, u64 nrr_heap_address, u64 nrr_heap_size, u64 mapped_code_address);
}

View file

@ -73,22 +73,22 @@ namespace ams::ro::impl {
os::ProcessId process_id;
bool in_use;
ncm::TitleId GetTitleId(Handle other_process_h) const {
ncm::ProgramId GetProgramId(Handle other_process_h) const {
/* Automatically select a handle, allowing for override. */
Handle process_h = this->process_handle;
if (other_process_h != INVALID_HANDLE) {
process_h = other_process_h;
}
ncm::TitleId title_id = ncm::TitleId::Invalid;
ncm::ProgramId program_id = ncm::ProgramId::Invalid;
if (hos::GetVersion() >= hos::Version_300) {
/* 3.0.0+: Use svcGetInfo. */
R_ASSERT(svcGetInfo(&title_id.value, InfoType_TitleId, process_h, 0));
R_ASSERT(svcGetInfo(&program_id.value, InfoType_ProgramId, process_h, 0));
} else {
/* 1.0.0-2.3.0: We're not inside loader, so ask pm. */
R_ASSERT(pm::info::GetTitleId(&title_id, os::GetProcessId(process_h)));
R_ASSERT(pm::info::GetProgramId(&program_id, os::GetProcessId(process_h)));
}
return title_id;
return program_id;
}
Result GetNrrInfoByAddress(NrrInfo **out, u64 nrr_heap_address) {
@ -363,8 +363,8 @@ namespace ams::ro::impl {
ProcessContext *context = GetContextById(context_id);
AMS_ASSERT(context != nullptr);
/* Get title id. */
const ncm::TitleId title_id = context->GetTitleId(process_h);
/* Get program id. */
const ncm::ProgramId program_id = context->GetProgramId(process_h);
/* Validate address/size. */
R_TRY(ValidateAddressAndSize(nrr_address, nrr_size));
@ -376,7 +376,7 @@ namespace ams::ro::impl {
/* Map. */
NrrHeader *header = nullptr;
u64 mapped_code_address = 0;
R_TRY(MapAndValidateNrr(&header, &mapped_code_address, context->process_handle, title_id, nrr_address, nrr_size, expected_type, enforce_type));
R_TRY(MapAndValidateNrr(&header, &mapped_code_address, context->process_handle, program_id, nrr_address, nrr_size, expected_type, enforce_type));
/* Set NRR info. */
nrr_info->in_use = true;

View file

@ -34,7 +34,7 @@ extern "C" {
namespace ams {
ncm::TitleId CurrentTitleId = ncm::TitleId::Ro;
ncm::ProgramId CurrentProgramId = ncm::ProgramId::Ro;
namespace result {

View file

@ -27,8 +27,8 @@ namespace ams::sm::impl {
/* Types. */
struct ProcessInfo {
os::ProcessId pid;
ncm::TitleId tid;
os::ProcessId process_id;
ncm::ProgramId program_id;
size_t access_control_size;
u8 access_control[AccessControlSizeMax];
@ -37,19 +37,19 @@ namespace ams::sm::impl {
}
void Free() {
this->pid = os::InvalidProcessId;
this->tid = ncm::TitleId::Invalid;
this->process_id = os::InvalidProcessId;
this->program_id = ncm::InvalidProgramId;
this->access_control_size = 0;
std::memset(this->access_control, 0, sizeof(this->access_control));
}
};
/* Forward declaration, for use in ServiceInfo. */
ncm::TitleId GetTitleIdForMitm(os::ProcessId pid);
ncm::ProgramId GetProgramIdForMitm(os::ProcessId process_id);
struct ServiceInfo {
ServiceName name;
os::ProcessId owner_pid;
os::ProcessId owner_process_id;
os::ManagedHandle port_h;
/* Debug. */
@ -57,13 +57,13 @@ namespace ams::sm::impl {
bool is_light;
/* Mitm Extension. */
os::ProcessId mitm_pid;
os::ProcessId mitm_process_id;
os::ManagedHandle mitm_port_h;
os::ManagedHandle mitm_query_h;
/* Acknowledgement members. */
bool mitm_waiting_ack;
os::ProcessId mitm_waiting_ack_pid;
os::ProcessId mitm_waiting_ack_process_id;
os::ManagedHandle mitm_fwd_sess_h;
ServiceInfo() {
@ -79,12 +79,12 @@ namespace ams::sm::impl {
/* Reset all other members. */
this->name = InvalidServiceName;
this->owner_pid = os::InvalidProcessId;
this->owner_process_id = os::InvalidProcessId;
this->max_sessions = 0;
this->is_light = false;
this->mitm_pid = os::InvalidProcessId;
this->mitm_process_id = os::InvalidProcessId;
this->mitm_waiting_ack = false;
this->mitm_waiting_ack_pid = os::InvalidProcessId;
this->mitm_waiting_ack_process_id = os::InvalidProcessId;
}
void FreeMitm() {
@ -93,16 +93,16 @@ namespace ams::sm::impl {
this->mitm_query_h.Clear();
/* Reset mitm members. */
this->mitm_pid = os::InvalidProcessId;
this->mitm_process_id = os::InvalidProcessId;
}
void AcknowledgeMitmSession(os::ProcessId *out_pid, ncm::TitleId *out_tid, Handle *out_hnd) {
void AcknowledgeMitmSession(os::ProcessId *out_process_id, ncm::ProgramId *out_program_id, Handle *out_hnd) {
/* Copy to output. */
*out_pid = this->mitm_waiting_ack_pid;
*out_tid = GetTitleIdForMitm(this->mitm_waiting_ack_pid);
*out_process_id = this->mitm_waiting_ack_process_id;
*out_program_id = GetProgramIdForMitm(this->mitm_waiting_ack_process_id);
*out_hnd = this->mitm_fwd_sess_h.Move();
this->mitm_waiting_ack = false;
this->mitm_waiting_ack_pid = os::InvalidProcessId;
this->mitm_waiting_ack_process_id = os::InvalidProcessId;
}
};
@ -163,9 +163,9 @@ namespace ams::sm::impl {
AMS_ASSERT(this->min <= this->max);
}
bool IsInitialProcess(os::ProcessId pid) const {
AMS_ASSERT(pid != os::InvalidProcessId);
return this->min <= pid && pid <= this->max;
bool IsInitialProcess(os::ProcessId process_id) const {
AMS_ASSERT(process_id != os::InvalidProcessId);
return this->min <= process_id && process_id <= this->max;
}
};
@ -177,9 +177,9 @@ namespace ams::sm::impl {
bool g_ended_initial_defers;
/* Helper functions for interacting with processes/services. */
ProcessInfo *GetProcessInfo(os::ProcessId pid) {
ProcessInfo *GetProcessInfo(os::ProcessId process_id) {
for (size_t i = 0; i < ProcessCountMax; i++) {
if (g_process_list[i].pid == pid) {
if (g_process_list[i].process_id == process_id) {
return &g_process_list[i];
}
}
@ -190,16 +190,16 @@ namespace ams::sm::impl {
return GetProcessInfo(os::InvalidProcessId);
}
bool HasProcessInfo(os::ProcessId pid) {
return GetProcessInfo(pid) != nullptr;
bool HasProcessInfo(os::ProcessId process_id) {
return GetProcessInfo(process_id) != nullptr;
}
bool IsInitialProcess(os::ProcessId pid) {
return g_initial_process_id_limits.IsInitialProcess(pid);
bool IsInitialProcess(os::ProcessId process_id) {
return g_initial_process_id_limits.IsInitialProcess(process_id);
}
constexpr inline bool IsValidProcessId(os::ProcessId pid) {
return pid != os::InvalidProcessId;
constexpr inline bool IsValidProcessId(os::ProcessId process_id) {
return process_id != os::InvalidProcessId;
}
ServiceInfo *GetServiceInfo(ServiceName service_name) {
@ -221,23 +221,23 @@ namespace ams::sm::impl {
bool HasMitm(ServiceName service) {
const ServiceInfo *service_info = GetServiceInfo(service);
return service_info != nullptr && IsValidProcessId(service_info->mitm_pid);
return service_info != nullptr && IsValidProcessId(service_info->mitm_process_id);
}
ncm::TitleId GetTitleIdForMitm(os::ProcessId pid) {
ncm::ProgramId GetProgramIdForMitm(os::ProcessId process_id) {
/* Anything that can request a mitm session must have a process info. */
const auto process_info = GetProcessInfo(pid);
const auto process_info = GetProcessInfo(process_id);
AMS_ASSERT(process_info != nullptr);
return process_info->tid;
return process_info->program_id;
}
bool IsMitmDisallowed(ncm::TitleId title_id) {
/* Mitm used on certain titles can prevent the boot process from completing. */
bool IsMitmDisallowed(ncm::ProgramId program_id) {
/* Mitm used on certain programs can prevent the boot process from completing. */
/* TODO: Is there a way to do this that's less hardcoded? Needs design thought. */
return title_id == ncm::TitleId::Loader ||
title_id == ncm::TitleId::Boot ||
title_id == ncm::TitleId::AtmosphereMitm ||
title_id == ncm::TitleId::Creport;
return program_id == ncm::ProgramId::Loader ||
program_id == ncm::ProgramId::Boot ||
program_id == ncm::ProgramId::AtmosphereMitm ||
program_id == ncm::ProgramId::Creport;
}
Result AddFutureMitmDeclaration(ServiceName service) {
@ -269,10 +269,10 @@ namespace ams::sm::impl {
void GetServiceInfoRecord(ServiceRecord *out_record, const ServiceInfo *service_info) {
out_record->service = service_info->name;
out_record->owner_pid = service_info->owner_pid;
out_record->owner_process_id = service_info->owner_process_id;
out_record->max_sessions = service_info->max_sessions;
out_record->mitm_pid = service_info->mitm_pid;
out_record->mitm_waiting_ack_pid = service_info->mitm_waiting_ack_pid;
out_record->mitm_process_id = service_info->mitm_process_id;
out_record->mitm_waiting_ack_process_id = service_info->mitm_waiting_ack_process_id;
out_record->is_light = service_info->is_light;
out_record->mitm_waiting_ack = service_info->mitm_waiting_ack;
}
@ -341,15 +341,15 @@ namespace ams::sm::impl {
return service == ServiceName::Encode("fsp-srv");
}
Result GetMitmServiceHandleImpl(Handle *out, ServiceInfo *service_info, os::ProcessId process_id, ncm::TitleId title_id) {
Result GetMitmServiceHandleImpl(Handle *out, ServiceInfo *service_info, os::ProcessId process_id, ncm::ProgramId program_id) {
/* Send command to query if we should mitm. */
bool should_mitm;
{
Service srv { .session = service_info->mitm_query_h.Get() };
const struct {
os::ProcessId process_id;
ncm::TitleId title_id;
} in = { process_id, title_id };
ncm::ProgramId program_id;
} in = { process_id, program_id };
R_TRY(serviceDispatchInOut(&srv, 65000, in, should_mitm));
}
@ -365,23 +365,23 @@ namespace ams::sm::impl {
*out = hnd.Move();
}
service_info->mitm_waiting_ack_pid = process_id;
service_info->mitm_waiting_ack_process_id = process_id;
service_info->mitm_waiting_ack = true;
return ResultSuccess();
}
Result GetServiceHandleImpl(Handle *out, ServiceInfo *service_info, os::ProcessId pid) {
Result GetServiceHandleImpl(Handle *out, ServiceInfo *service_info, os::ProcessId process_id) {
/* Clear handle output. */
*out = INVALID_HANDLE;
/* Check if we should return a mitm handle. */
if (IsValidProcessId(service_info->mitm_pid) && service_info->mitm_pid != pid) {
/* Get title id, ensure that we're allowed to mitm the given title. */
const ncm::TitleId title_id = GetTitleIdForMitm(pid);
if (!IsMitmDisallowed(title_id)) {
if (IsValidProcessId(service_info->mitm_process_id) && service_info->mitm_process_id != process_id) {
/* Get program id, ensure that we're allowed to mitm the given program. */
const ncm::ProgramId program_id = GetProgramIdForMitm(process_id);
if (!IsMitmDisallowed(program_id)) {
/* We're mitm'd. Assert, because mitm service host dead is an error state. */
R_ASSERT(GetMitmServiceHandleImpl(out, service_info, pid, title_id));
R_ASSERT(GetMitmServiceHandleImpl(out, service_info, process_id, program_id));
return ResultSuccess();
}
}
@ -390,7 +390,7 @@ namespace ams::sm::impl {
return svcConnectToPort(out, service_info->port_h.Get());
}
Result RegisterServiceImpl(Handle *out, os::ProcessId pid, ServiceName service, size_t max_sessions, bool is_light) {
Result RegisterServiceImpl(Handle *out, os::ProcessId process_id, ServiceName service, size_t max_sessions, bool is_light) {
/* Validate service name. */
R_TRY(ValidateServiceName(service));
@ -414,7 +414,7 @@ namespace ams::sm::impl {
/* Save info. */
free_service->name = service;
free_service->owner_pid = pid;
free_service->owner_process_id = process_id;
free_service->max_sessions = max_sessions;
free_service->is_light = is_light;
@ -423,7 +423,7 @@ namespace ams::sm::impl {
}
/* Process management. */
Result RegisterProcess(os::ProcessId pid, ncm::TitleId tid, const void *acid_sac, size_t acid_sac_size, const void *aci_sac, size_t aci_sac_size) {
Result RegisterProcess(os::ProcessId process_id, ncm::ProgramId program_id, const void *acid_sac, size_t acid_sac_size, const void *aci_sac, size_t aci_sac_size) {
/* Check that access control will fit in the ServiceInfo. */
R_UNLESS(aci_sac_size <= AccessControlSizeMax, sm::ResultTooLargeAccessControl());
@ -436,16 +436,16 @@ namespace ams::sm::impl {
R_TRY(ValidateAccessControl(AccessControlEntry(acid_sac, acid_sac_size), AccessControlEntry(aci_sac, aci_sac_size)));
/* Save info. */
proc->pid = pid;
proc->tid = tid;
proc->process_id = process_id;
proc->program_id = program_id;
proc->access_control_size = aci_sac_size;
std::memcpy(proc->access_control, aci_sac, proc->access_control_size);
return ResultSuccess();
}
Result UnregisterProcess(os::ProcessId pid) {
Result UnregisterProcess(os::ProcessId process_id) {
/* Find the process. */
ProcessInfo *proc = GetProcessInfo(pid);
ProcessInfo *proc = GetProcessInfo(process_id);
R_UNLESS(proc != nullptr, sm::ResultInvalidClient());
proc->Free();
@ -470,7 +470,7 @@ namespace ams::sm::impl {
return ResultSuccess();
}
Result GetServiceHandle(Handle *out, os::ProcessId pid, ServiceName service) {
Result GetServiceHandle(Handle *out, os::ProcessId process_id, ServiceName service) {
/* Validate service name. */
R_TRY(ValidateServiceName(service));
@ -483,8 +483,8 @@ namespace ams::sm::impl {
R_UNLESS((hos::GetVersion() < hos::Version_800) || (service != ApmP), sm::ResultNotAllowed());
/* Check that the process is registered and allowed to get the service. */
if (!IsInitialProcess(pid)) {
ProcessInfo *proc = GetProcessInfo(pid);
if (!IsInitialProcess(process_id)) {
ProcessInfo *proc = GetProcessInfo(process_id);
R_UNLESS(proc != nullptr, sm::ResultInvalidClient());
R_TRY(ValidateAccessControl(AccessControlEntry(proc->access_control, proc->access_control_size), service, false, false));
}
@ -497,40 +497,40 @@ namespace ams::sm::impl {
R_UNLESS(!service_info->mitm_waiting_ack, sf::ResultRequestDeferredByUser());
/* Get a handle from the service info. */
R_TRY_CATCH(GetServiceHandleImpl(out, service_info, pid)) {
R_TRY_CATCH(GetServiceHandleImpl(out, service_info, process_id)) {
R_CONVERT(svc::ResultOutOfSessions, sm::ResultOutOfSessions())
} R_END_TRY_CATCH;
return ResultSuccess();
}
Result RegisterService(Handle *out, os::ProcessId pid, ServiceName service, size_t max_sessions, bool is_light) {
Result RegisterService(Handle *out, os::ProcessId process_id, ServiceName service, size_t max_sessions, bool is_light) {
/* Validate service name. */
R_TRY(ValidateServiceName(service));
/* Check that the process is registered and allowed to register the service. */
if (!IsInitialProcess(pid)) {
ProcessInfo *proc = GetProcessInfo(pid);
if (!IsInitialProcess(process_id)) {
ProcessInfo *proc = GetProcessInfo(process_id);
R_UNLESS(proc != nullptr, sm::ResultInvalidClient());
R_TRY(ValidateAccessControl(AccessControlEntry(proc->access_control, proc->access_control_size), service, true, false));
}
R_UNLESS(!HasServiceInfo(service), sm::ResultAlreadyRegistered());
return RegisterServiceImpl(out, pid, service, max_sessions, is_light);
return RegisterServiceImpl(out, process_id, service, max_sessions, is_light);
}
Result RegisterServiceForSelf(Handle *out, ServiceName service, size_t max_sessions) {
return RegisterServiceImpl(out, os::GetCurrentProcessId(), service, max_sessions, false);
}
Result UnregisterService(os::ProcessId pid, ServiceName service) {
Result UnregisterService(os::ProcessId process_id, ServiceName service) {
/* Validate service name. */
R_TRY(ValidateServiceName(service));
/* Check that the process is registered. */
if (!IsInitialProcess(pid)) {
R_UNLESS(HasProcessInfo(pid), sm::ResultInvalidClient());
if (!IsInitialProcess(process_id)) {
R_UNLESS(HasProcessInfo(process_id), sm::ResultInvalidClient());
}
/* Ensure that the service is actually registered. */
@ -538,7 +538,7 @@ namespace ams::sm::impl {
R_UNLESS(service_info != nullptr, sm::ResultNotRegistered());
/* Check if we have permission to do this. */
R_UNLESS(service_info->owner_pid == pid, sm::ResultNotAllowed());
R_UNLESS(service_info->owner_process_id == process_id, sm::ResultNotAllowed());
/* Unregister the service. */
service_info->Free();
@ -551,7 +551,7 @@ namespace ams::sm::impl {
R_TRY(ValidateServiceName(service));
const ServiceInfo *service_info = GetServiceInfo(service);
*out = service_info != nullptr && IsValidProcessId(service_info->mitm_pid);
*out = service_info != nullptr && IsValidProcessId(service_info->mitm_process_id);
return ResultSuccess();
}
@ -564,13 +564,13 @@ namespace ams::sm::impl {
return ResultSuccess();
}
Result InstallMitm(Handle *out, Handle *out_query, os::ProcessId pid, ServiceName service) {
Result InstallMitm(Handle *out, Handle *out_query, os::ProcessId process_id, ServiceName service) {
/* Validate service name. */
R_TRY(ValidateServiceName(service));
/* Check that the process is registered and allowed to register the service. */
if (!IsInitialProcess(pid)) {
ProcessInfo *proc = GetProcessInfo(pid);
if (!IsInitialProcess(process_id)) {
ProcessInfo *proc = GetProcessInfo(process_id);
R_UNLESS(proc != nullptr, sm::ResultInvalidClient());
R_TRY(ValidateAccessControl(AccessControlEntry(proc->access_control, proc->access_control_size), service, true, false));
}
@ -582,7 +582,7 @@ namespace ams::sm::impl {
R_UNLESS(service_info != nullptr, sf::ResultRequestDeferredByUser());
/* Validate that the service isn't already being mitm'd. */
R_UNLESS(!IsValidProcessId(service_info->mitm_pid), sm::ResultAlreadyRegistered());
R_UNLESS(!IsValidProcessId(service_info->mitm_process_id), sm::ResultAlreadyRegistered());
/* Always clear output. */
*out = INVALID_HANDLE;
@ -596,7 +596,7 @@ namespace ams::sm::impl {
R_TRY(svcCreateSession(qry_hnd.GetPointer(), mitm_qry_hnd.GetPointer(), 0, 0));
/* Copy to output. */
service_info->mitm_pid = pid;
service_info->mitm_process_id = process_id;
service_info->mitm_port_h = std::move(port_hnd);
service_info->mitm_query_h = std::move(mitm_qry_hnd);
*out = hnd.Move();
@ -609,13 +609,13 @@ namespace ams::sm::impl {
return ResultSuccess();
}
Result UninstallMitm(os::ProcessId pid, ServiceName service) {
Result UninstallMitm(os::ProcessId process_id, ServiceName service) {
/* Validate service name. */
R_TRY(ValidateServiceName(service));
/* Check that the process is registered. */
if (!IsInitialProcess(pid)) {
ProcessInfo *proc = GetProcessInfo(pid);
if (!IsInitialProcess(process_id)) {
ProcessInfo *proc = GetProcessInfo(process_id);
R_UNLESS(proc != nullptr, sm::ResultInvalidClient());
}
@ -623,21 +623,21 @@ namespace ams::sm::impl {
ServiceInfo *service_info = GetServiceInfo(service);
R_UNLESS(service_info != nullptr, sm::ResultNotRegistered());
/* Validate that the client pid is the mitm process. */
R_UNLESS(service_info->mitm_pid == pid, sm::ResultNotAllowed());
/* Validate that the client process_id is the mitm process. */
R_UNLESS(service_info->mitm_process_id == process_id, sm::ResultNotAllowed());
/* Free Mitm session info. */
service_info->FreeMitm();
return ResultSuccess();
}
Result DeclareFutureMitm(os::ProcessId pid, ServiceName service) {
Result DeclareFutureMitm(os::ProcessId process_id, ServiceName service) {
/* Validate service name. */
R_TRY(ValidateServiceName(service));
/* Check that the process is registered and allowed to register the service. */
if (!IsInitialProcess(pid)) {
ProcessInfo *proc = GetProcessInfo(pid);
if (!IsInitialProcess(process_id)) {
ProcessInfo *proc = GetProcessInfo(process_id);
R_UNLESS(proc != nullptr, sm::ResultInvalidClient());
R_TRY(ValidateAccessControl(AccessControlEntry(proc->access_control, proc->access_control_size), service, true, false));
}
@ -651,13 +651,13 @@ namespace ams::sm::impl {
return ResultSuccess();
}
Result AcknowledgeMitmSession(os::ProcessId *out_pid, ncm::TitleId *out_tid, Handle *out_hnd, os::ProcessId pid, ServiceName service) {
Result AcknowledgeMitmSession(os::ProcessId *out_process_id, ncm::ProgramId *out_program_id, Handle *out_hnd, os::ProcessId process_id, ServiceName service) {
/* Validate service name. */
R_TRY(ValidateServiceName(service));
/* Check that the process is registered. */
if (!IsInitialProcess(pid)) {
ProcessInfo *proc = GetProcessInfo(pid);
if (!IsInitialProcess(process_id)) {
ProcessInfo *proc = GetProcessInfo(process_id);
R_UNLESS(proc != nullptr, sm::ResultInvalidClient());
}
@ -665,12 +665,12 @@ namespace ams::sm::impl {
ServiceInfo *service_info = GetServiceInfo(service);
R_UNLESS(service_info != nullptr, sm::ResultNotRegistered());
/* Validate that the client pid is the mitm process, and that an acknowledgement is waiting. */
R_UNLESS(service_info->mitm_pid == pid, sm::ResultNotAllowed());
/* Validate that the client process_id is the mitm process, and that an acknowledgement is waiting. */
R_UNLESS(service_info->mitm_process_id == process_id, sm::ResultNotAllowed());
R_UNLESS(service_info->mitm_waiting_ack, sm::ResultNotAllowed());
/* Acknowledge. */
service_info->AcknowledgeMitmSession(out_pid, out_tid, out_hnd);
service_info->AcknowledgeMitmSession(out_process_id, out_program_id, out_hnd);
return ResultSuccess();
}

View file

@ -20,24 +20,24 @@
namespace ams::sm::impl {
/* Process management. */
Result RegisterProcess(os::ProcessId pid, ncm::TitleId tid, const void *acid_sac, size_t acid_sac_size, const void *aci_sac, size_t aci_sac_size);
Result UnregisterProcess(os::ProcessId pid);
Result RegisterProcess(os::ProcessId process_id, ncm::ProgramId program_id, const void *acid_sac, size_t acid_sac_size, const void *aci_sac, size_t aci_sac_size);
Result UnregisterProcess(os::ProcessId process_id);
/* Service management. */
Result HasService(bool *out, ServiceName service);
Result WaitService(ServiceName service);
Result GetServiceHandle(Handle *out, os::ProcessId pid, ServiceName service);
Result RegisterService(Handle *out, os::ProcessId pid, ServiceName service, size_t max_sessions, bool is_light);
Result GetServiceHandle(Handle *out, os::ProcessId process_id, ServiceName service);
Result RegisterService(Handle *out, os::ProcessId process_id, ServiceName service, size_t max_sessions, bool is_light);
Result RegisterServiceForSelf(Handle *out, ServiceName service, size_t max_sessions);
Result UnregisterService(os::ProcessId pid, ServiceName service);
Result UnregisterService(os::ProcessId process_id, ServiceName service);
/* Mitm extensions. */
Result HasMitm(bool *out, ServiceName service);
Result WaitMitm(ServiceName service);
Result InstallMitm(Handle *out, Handle *out_query, os::ProcessId pid, ServiceName service);
Result UninstallMitm(os::ProcessId pid, ServiceName service);
Result DeclareFutureMitm(os::ProcessId pid, ServiceName service);
Result AcknowledgeMitmSession(os::ProcessId *out_pid, ncm::TitleId *out_tid, Handle *out_hnd, os::ProcessId pid, ServiceName service);
Result InstallMitm(Handle *out, Handle *out_query, os::ProcessId process_id, ServiceName service);
Result UninstallMitm(os::ProcessId process_id, ServiceName service);
Result DeclareFutureMitm(os::ProcessId process_id, ServiceName service);
Result AcknowledgeMitmSession(os::ProcessId *out_process_id, ncm::ProgramId *out_program_id, Handle *out_hnd, os::ProcessId process_id, ServiceName service);
/* Dmnt record extensions. */
Result GetServiceRecord(ServiceRecord *out, ServiceName service);

View file

@ -40,7 +40,7 @@ extern "C" {
namespace ams {
ncm::TitleId CurrentTitleId = ncm::TitleId::Sm;
ncm::ProgramId CurrentProgramId = ncm::ProgramId::Sm;
namespace result {

View file

@ -19,7 +19,7 @@
namespace ams::sm {
Result ManagerService::RegisterProcess(os::ProcessId process_id, const sf::InBuffer &acid_sac, const sf::InBuffer &aci_sac) {
return impl::RegisterProcess(process_id, ncm::TitleId::Invalid, acid_sac.GetPointer(), acid_sac.GetSize(), aci_sac.GetPointer(), aci_sac.GetSize());
return impl::RegisterProcess(process_id, ncm::ProgramId::Invalid, acid_sac.GetPointer(), acid_sac.GetSize(), aci_sac.GetPointer(), aci_sac.GetSize());
}
Result ManagerService::UnregisterProcess(os::ProcessId process_id) {
@ -34,9 +34,9 @@ namespace ams::sm {
R_ASSERT(impl::HasMitm(out.GetPointer(), service));
}
Result ManagerService::AtmosphereRegisterProcess(os::ProcessId process_id, ncm::TitleId title_id, const sf::InBuffer &acid_sac, const sf::InBuffer &aci_sac) {
/* This takes in a title id, unlike RegisterProcess. */
return impl::RegisterProcess(process_id, title_id, acid_sac.GetPointer(), acid_sac.GetSize(), aci_sac.GetPointer(), aci_sac.GetSize());
Result ManagerService::AtmosphereRegisterProcess(os::ProcessId process_id, ncm::ProgramId program_id, const sf::InBuffer &acid_sac, const sf::InBuffer &aci_sac) {
/* This takes in a program id, unlike RegisterProcess. */
return impl::RegisterProcess(process_id, program_id, acid_sac.GetPointer(), acid_sac.GetSize(), aci_sac.GetPointer(), aci_sac.GetSize());
}
}

View file

@ -36,7 +36,7 @@ namespace ams::sm {
virtual Result UnregisterProcess(os::ProcessId process_id);
virtual void AtmosphereEndInitDefers();
virtual void AtmosphereHasMitm(sf::Out<bool> out, ServiceName service);
virtual Result AtmosphereRegisterProcess(os::ProcessId process_id, ncm::TitleId title_id, const sf::InBuffer &acid_sac, const sf::InBuffer &aci_sac);
virtual Result AtmosphereRegisterProcess(os::ProcessId process_id, ncm::ProgramId program_id, const sf::InBuffer &acid_sac, const sf::InBuffer &aci_sac);
public:
DEFINE_SERVICE_DISPATCH_TABLE {
MAKE_SERVICE_COMMAND_META(RegisterProcess),

View file

@ -56,9 +56,9 @@ namespace ams::sm {
return impl::UninstallMitm(this->process_id, service);
}
Result UserService::AtmosphereAcknowledgeMitmSession(sf::Out<os::ProcessId> client_pid, sf::Out<ncm::TitleId> client_tid, sf::OutMoveHandle fwd_h, ServiceName service) {
Result UserService::AtmosphereAcknowledgeMitmSession(sf::Out<os::ProcessId> client_process_id, sf::Out<ncm::ProgramId> client_program_id, sf::OutMoveHandle fwd_h, ServiceName service) {
R_TRY(this->EnsureInitialized());
return impl::AcknowledgeMitmSession(client_pid.GetPointer(), client_tid.GetPointer(), fwd_h.GetHandlePointer(), this->process_id, service);
return impl::AcknowledgeMitmSession(client_process_id.GetPointer(), client_program_id.GetPointer(), fwd_h.GetHandlePointer(), this->process_id, service);
}
Result UserService::AtmosphereHasMitm(sf::Out<bool> out, ServiceName service) {

View file

@ -55,7 +55,7 @@ namespace ams::sm {
/* Atmosphere commands. */
virtual Result AtmosphereInstallMitm(sf::OutMoveHandle srv_h, sf::OutMoveHandle qry_h, ServiceName service);
virtual Result AtmosphereUninstallMitm(ServiceName service);
virtual Result AtmosphereAcknowledgeMitmSession(sf::Out<os::ProcessId> client_pid, sf::Out<ncm::TitleId> client_tid, sf::OutMoveHandle fwd_h, ServiceName service);
virtual Result AtmosphereAcknowledgeMitmSession(sf::Out<os::ProcessId> client_process_id, sf::Out<ncm::ProgramId> client_program_id, sf::OutMoveHandle fwd_h, ServiceName service);
virtual Result AtmosphereHasMitm(sf::Out<bool> out, ServiceName service);
virtual Result AtmosphereWaitMitm(ServiceName service);
virtual Result AtmosphereDeclareFutureMitm(ServiceName service);

View file

@ -46,7 +46,7 @@ extern "C" {
namespace ams {
ncm::TitleId CurrentTitleId = ncm::TitleId::Spl;
ncm::ProgramId CurrentProgramId = ncm::ProgramId::Spl;
namespace result {