VERY experimental Nintendo Switch 2 emulator
C++
core: Migrate current_process pointer to the kernel
Lioncash420597d70dd5
diff --git a/src/core/core.cpp b/src/core/core.cppindex bf39ad689b..713ee17c1d 100644--- a/src/core/core.cpp+++ b/src/core/core.cpp@@ -136,7 +136,7 @@ struct System::Impl {if (virtual_filesystem == nullptr)virtual_filesystem = std::make_shared<FileSys::RealVfsFilesystem>();- current_process = Kernel::Process::Create(kernel, "main");+ kernel.MakeCurrentProcess(Kernel::Process::Create(kernel, "main"));cpu_barrier = std::make_shared<CpuBarrier>();cpu_exclusive_monitor = Cpu::MakeExclusiveMonitor(cpu_cores.size());@@ -202,7 +202,7 @@ struct System::Impl {return init_result;}- const Loader::ResultStatus load_result{app_loader->Load(current_process)};+ const Loader::ResultStatus load_result{app_loader->Load(kernel.CurrentProcess())};if (load_result != Loader::ResultStatus::Success) {LOG_CRITICAL(Core, "Failed to load ROM (Error {})!", static_cast<int>(load_result));Shutdown();@@ -281,7 +281,6 @@ struct System::Impl {std::unique_ptr<VideoCore::RendererBase> renderer;std::unique_ptr<Tegra::GPU> gpu_core;std::shared_ptr<Tegra::DebugContext> debug_context;- Kernel::SharedPtr<Kernel::Process> current_process;std::shared_ptr<ExclusiveMonitor> cpu_exclusive_monitor;std::shared_ptr<CpuBarrier> cpu_barrier;std::array<std::shared_ptr<Cpu>, NUM_CPU_CORES> cpu_cores;@@ -363,7 +362,11 @@ const std::shared_ptr<Kernel::Scheduler>& System::Scheduler(size_t core_index) {}Kernel::SharedPtr<Kernel::Process>& System::CurrentProcess() {- return impl->current_process;+ return impl->kernel.CurrentProcess();+}++const Kernel::SharedPtr<Kernel::Process>& System::CurrentProcess() const {+ return impl->kernel.CurrentProcess();}ARM_Interface& System::ArmInterface(size_t core_index) {diff --git a/src/core/core.h b/src/core/core.hindex 5c3c0e2a17..ab36634274 100644--- a/src/core/core.h+++ b/src/core/core.h@@ -174,9 +174,12 @@ public:/// Gets the scheduler for the CPU core with the specified indexconst std::shared_ptr<Kernel::Scheduler>& Scheduler(size_t core_index);- /// Gets the current process+ /// Provides a reference to the current processKernel::SharedPtr<Kernel::Process>& CurrentProcess();+ /// Provides a constant reference to the current process.+ const Kernel::SharedPtr<Kernel::Process>& CurrentProcess() const;+/// Provides a reference to the kernel instance.Kernel::KernelCore& Kernel();diff --git a/src/core/hle/kernel/kernel.cpp b/src/core/hle/kernel/kernel.cppindex 7902c28829..3e0800a716 100644--- a/src/core/hle/kernel/kernel.cpp+++ b/src/core/hle/kernel/kernel.cpp@@ -116,6 +116,7 @@ struct KernelCore::Impl {next_thread_id = 1;process_list.clear();+ current_process.reset();handle_table.Clear();resource_limits.fill(nullptr);@@ -206,6 +207,7 @@ struct KernelCore::Impl {// Lists all processes that exist in the current session.std::vector<SharedPtr<Process>> process_list;+ SharedPtr<Process> current_process;Kernel::HandleTable handle_table;std::array<SharedPtr<ResourceLimit>, 4> resource_limits;@@ -264,6 +266,18 @@ void KernelCore::AppendNewProcess(SharedPtr<Process> process) {impl->process_list.push_back(std::move(process));}+void KernelCore::MakeCurrentProcess(SharedPtr<Process> process) {+ impl->current_process = std::move(process);+}++SharedPtr<Process>& KernelCore::CurrentProcess() {+ return impl->current_process;+}++const SharedPtr<Process>& KernelCore::CurrentProcess() const {+ return impl->current_process;+}+void KernelCore::AddNamedPort(std::string name, SharedPtr<ClientPort> port) {impl->named_ports.emplace(std::move(name), std::move(port));}diff --git a/src/core/hle/kernel/kernel.h b/src/core/hle/kernel/kernel.hindex ab2e9bffa1..c0771ecf07 100644--- a/src/core/hle/kernel/kernel.h+++ b/src/core/hle/kernel/kernel.h@@ -65,6 +65,15 @@ public:/// Adds the given shared pointer to an internal list of active processes.void AppendNewProcess(SharedPtr<Process> process);+ /// Makes the given process the new current process.+ void MakeCurrentProcess(SharedPtr<Process> process);++ /// Retrieves a reference to the current process.+ SharedPtr<Process>& CurrentProcess();++ /// Retrieves a const reference to the current process.+ const SharedPtr<Process>& CurrentProcess() const;+/// Adds a port to the named port tablevoid AddNamedPort(std::string name, SharedPtr<ClientPort> port);