core: Implement APT:MapProgramIdForDebug (#2224)

This commit is contained in:
PabloMK7 2026-06-19 09:00:33 +02:00 committed by GitHub
parent 0a269688a3
commit 9e43e451d1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 38 additions and 3 deletions

View file

@ -359,6 +359,15 @@ bool AppletManager::CancelParameter(bool check_sender, AppletId sender_appid, bo
return cancellation_success;
}
void AppletManager::MapProgramIdForDebug(AppletId app_id, u64 title_id, FS::MediaType media_type) {
auto slot = GetAppletSlotFromId(app_id);
if (slot != AppletSlot::Error) {
auto applet_slot = GetAppletSlot(slot);
applet_slot->title_id = title_id;
applet_slot->media_type = media_type;
}
}
ResultVal<AppletManager::GetLockHandleResult> AppletManager::GetLockHandle(
AppletAttributes attributes) {
auto corrected_attributes = attributes;

View file

@ -288,6 +288,8 @@ public:
bool CancelParameter(bool check_sender, AppletId sender_appid, bool check_receiver,
AppletId receiver_appid);
void MapProgramIdForDebug(AppletId app_id, u64 title_id, FS::MediaType media_type);
struct GetLockHandleResult {
AppletAttributes corrected_attributes;
u32 state;

View file

@ -574,6 +574,28 @@ void Module::APTInterface::CancelParameter(Kernel::HLERequestContext& ctx) {
receiver_appid));
}
void Module::APTInterface::MapProgramIdForDebug(Kernel::HLERequestContext& ctx) {
// This function got stubbed at some point and no longer
// does anything on real hardware. It is implemented here
// so that emulated applications can take advantage of it.
IPC::RequestParser rp(ctx);
const auto app_id = rp.PopEnum<AppletId>();
u64 title_id = rp.Pop<u64>();
// NOTE: Real hardware forces the media type to nand.
// To allow better control of this service call,
// treat the highest byte of the title ID as the
// media type instead.
FS::MediaType media_type = static_cast<FS::MediaType>(title_id >> 56);
title_id &= ~0xFF00000000000000ULL;
apt->applet_manager->MapProgramIdForDebug(app_id, title_id, media_type);
IPC::RequestBuilder rb = rp.MakeBuilder(1, 0);
rb.Push(ResultSuccess); // No error
}
void Module::APTInterface::PrepareToDoApplicationJump(Kernel::HLERequestContext& ctx) {
IPC::RequestParser rp(ctx);
auto flags = rp.PopEnum<ApplicationJumpFlags>();

View file

@ -376,6 +376,8 @@ public:
*/
void CancelParameter(Kernel::HLERequestContext& ctx);
void MapProgramIdForDebug(Kernel::HLERequestContext& ctx);
/**
* APT::PrepareToStartApplication service function. When the input title-info programID is
* zero, NS will load the actual program ID via AMNet:GetTitleIDList. After doing some

View file

@ -27,7 +27,7 @@ APT_A::APT_A(std::shared_ptr<Module> apt)
{0x000E, &APT_A::GlanceParameter, "GlanceParameter"},
{0x000F, &APT_A::CancelParameter, "CancelParameter"},
{0x0010, nullptr, "DebugFunc"},
{0x0011, nullptr, "MapProgramIdForDebug"},
{0x0011, &APT_A::MapProgramIdForDebug, "MapProgramIdForDebug"},
{0x0012, nullptr, "SetHomeMenuAppletIdForDebug"},
{0x0013, nullptr, "GetPreparationState"},
{0x0014, nullptr, "SetPreparationState"},

View file

@ -27,7 +27,7 @@ APT_S::APT_S(std::shared_ptr<Module> apt)
{0x000E, &APT_S::GlanceParameter, "GlanceParameter"},
{0x000F, &APT_S::CancelParameter, "CancelParameter"},
{0x0010, nullptr, "DebugFunc"},
{0x0011, nullptr, "MapProgramIdForDebug"},
{0x0011, &APT_S::MapProgramIdForDebug, "MapProgramIdForDebug"},
{0x0012, nullptr, "SetHomeMenuAppletIdForDebug"},
{0x0013, nullptr, "GetPreparationState"},
{0x0014, nullptr, "SetPreparationState"},

View file

@ -27,7 +27,7 @@ APT_U::APT_U(std::shared_ptr<Module> apt)
{0x000E, &APT_U::GlanceParameter, "GlanceParameter"},
{0x000F, &APT_U::CancelParameter, "CancelParameter"},
{0x0010, nullptr, "DebugFunc"},
{0x0011, nullptr, "MapProgramIdForDebug"},
{0x0011, &APT_U::MapProgramIdForDebug, "MapProgramIdForDebug"},
{0x0012, nullptr, "SetHomeMenuAppletIdForDebug"},
{0x0013, nullptr, "GetPreparationState"},
{0x0014, nullptr, "SetPreparationState"},