Merge pull request #7009 from ameerj/main_process_cleanup

core: Destroy main_process during shutdown
This commit is contained in:
bunnei 2021-09-13 23:32:43 -07:00 committed by GitHub
commit 081ccc6441
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 12 additions and 3 deletions

View File

@ -83,6 +83,12 @@ FileSys::StorageId GetStorageIdForFrontendSlot(
} }
} }
void KProcessDeleter(Kernel::KProcess* process) {
process->Destroy();
}
using KProcessPtr = std::unique_ptr<Kernel::KProcess, decltype(&KProcessDeleter)>;
} // Anonymous namespace } // Anonymous namespace
FileSys::VirtualFile GetGameFileFromPath(const FileSys::VirtualFilesystem& vfs, FileSys::VirtualFile GetGameFileFromPath(const FileSys::VirtualFilesystem& vfs,
@ -233,8 +239,8 @@ struct System::Impl {
} }
telemetry_session->AddInitialInfo(*app_loader, fs_controller, *content_provider); telemetry_session->AddInitialInfo(*app_loader, fs_controller, *content_provider);
auto main_process = Kernel::KProcess::Create(system.Kernel()); main_process = KProcessPtr{Kernel::KProcess::Create(system.Kernel()), KProcessDeleter};
ASSERT(Kernel::KProcess::Initialize(main_process, system, "main", ASSERT(Kernel::KProcess::Initialize(main_process.get(), system, "main",
Kernel::KProcess::ProcessType::Userland) Kernel::KProcess::ProcessType::Userland)
.IsSuccess()); .IsSuccess());
main_process->Open(); main_process->Open();
@ -247,7 +253,7 @@ struct System::Impl {
static_cast<u32>(load_result)); static_cast<u32>(load_result));
} }
AddGlueRegistrationForProcess(*app_loader, *main_process); AddGlueRegistrationForProcess(*app_loader, *main_process);
kernel.MakeCurrentProcess(main_process); kernel.MakeCurrentProcess(main_process.get());
kernel.InitializeCores(); kernel.InitializeCores();
// Initialize cheat engine // Initialize cheat engine
@ -316,6 +322,8 @@ struct System::Impl {
kernel.Shutdown(); kernel.Shutdown();
memory.Reset(); memory.Reset();
applet_manager.ClearAll(); applet_manager.ClearAll();
// TODO: The main process should be freed based on KAutoObject ref counting.
main_process.reset();
LOG_DEBUG(Core, "Shutdown OK"); LOG_DEBUG(Core, "Shutdown OK");
} }
@ -374,6 +382,7 @@ struct System::Impl {
std::unique_ptr<Tegra::GPU> gpu_core; std::unique_ptr<Tegra::GPU> gpu_core;
std::unique_ptr<Hardware::InterruptManager> interrupt_manager; std::unique_ptr<Hardware::InterruptManager> interrupt_manager;
std::unique_ptr<Core::DeviceMemory> device_memory; std::unique_ptr<Core::DeviceMemory> device_memory;
KProcessPtr main_process{nullptr, KProcessDeleter};
Core::Memory::Memory memory; Core::Memory::Memory memory;
CpuManager cpu_manager; CpuManager cpu_manager;
std::atomic_bool is_powered_on{}; std::atomic_bool is_powered_on{};