Add a check for O3DS extended-memory ROMs in applet_manager.cpp to ensure reboot if necessary.

This commit is contained in:
Malachi 2025-09-15 12:33:26 -04:00
parent 34d46528eb
commit 619fbcaeac
3 changed files with 32 additions and 2 deletions

View file

@ -1349,6 +1349,19 @@ Result AppletManager::StartApplication(const std::vector<u8>& parameter,
// PM::LaunchTitle. We should research more about that.
ASSERT_MSG(app_start_parameters, "Trying to start an application without preparing it first.");
// Determine if the target title is an O3DS extended-memory title.
bool needs_extended_memory_reboot = NS::RequiresExtendedMemoryOld3DS(
app_start_parameters->next_media_type, app_start_parameters->next_title_id);
if (needs_extended_memory_reboot) {
// For O3DS extended-memory titles, reboot to ensure a clean low-memory state to prevent
// hang/crash.
NS::RebootToTitle(system, app_start_parameters->next_media_type,
app_start_parameters->next_title_id);
app_start_parameters.reset();
return ResultSuccess;
}
active_slot = AppletSlot::Application;
// Launch the title directly.

View file

@ -1,4 +1,4 @@
// Copyright 2017 Citra Emulator Project
// Copyright Citra Emulator Project / Azahar Emulator Project
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.
@ -54,4 +54,17 @@ void RebootToTitle(Core::System& system, FS::MediaType media_type, u64 title_id)
system.RequestReset(new_path);
}
bool RequiresExtendedMemoryOld3DS(FS::MediaType media_type, u64 title_id) {
const std::string path = AM::GetTitleContentPath(media_type, title_id);
auto loader = Loader::GetLoader(path);
if (!loader)
return false;
auto [mem_mode_opt, status] = loader->LoadKernelMemoryMode();
if (status != Loader::ResultStatus::Success || !mem_mode_opt.has_value())
return false;
return (*mem_mode_opt != Kernel::MemoryMode::Prod);
}
} // namespace Service::NS

View file

@ -1,4 +1,4 @@
// Copyright 2017 Citra Emulator Project
// Copyright Citra Emulator Project / Azahar Emulator Project
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.
@ -22,4 +22,8 @@ std::shared_ptr<Kernel::Process> LaunchTitle(Core::System& system, FS::MediaType
/// Reboots the system to the specified title.
void RebootToTitle(Core::System& system, FS::MediaType media_type, u64 title_id);
/// Returns true if the specified title requires extended memory on Old 3DS
/// (i.e., its ExHeader system mode is not Prod/64MB).
bool RequiresExtendedMemoryOld3DS(FS::MediaType media_type, u64 title_id);
} // namespace Service::NS