From 3f17fe71334a27a60bf54adc55eabe2356ed31f5 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Thu, 6 Sep 2018 20:34:51 -0400 Subject: core: Migrate current_process pointer to the kernel Given we now have the kernel as a class, it doesn't make sense to keep the current process pointer within the System class, as processes are related to the kernel. This also gets rid of a subtle case where memory wouldn't be freed on core shutdown, as the current_process pointer would never be reset, causing the pointed to contents to continue to live. --- src/core/hle/kernel/kernel.cpp | 14 ++++++++++++++ src/core/hle/kernel/kernel.h | 9 +++++++++ 2 files changed, 23 insertions(+) (limited to 'src/core/hle/kernel') diff --git a/src/core/hle/kernel/kernel.cpp b/src/core/hle/kernel/kernel.cpp index 7902c2882..3e0800a71 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> process_list; + SharedPtr current_process; Kernel::HandleTable handle_table; std::array, 4> resource_limits; @@ -264,6 +266,18 @@ void KernelCore::AppendNewProcess(SharedPtr process) { impl->process_list.push_back(std::move(process)); } +void KernelCore::MakeCurrentProcess(SharedPtr process) { + impl->current_process = std::move(process); +} + +SharedPtr& KernelCore::CurrentProcess() { + return impl->current_process; +} + +const SharedPtr& KernelCore::CurrentProcess() const { + return impl->current_process; +} + void KernelCore::AddNamedPort(std::string name, SharedPtr 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.h index ab2e9bffa..c0771ecf0 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); + /// Makes the given process the new current process. + void MakeCurrentProcess(SharedPtr process); + + /// Retrieves a reference to the current process. + SharedPtr& CurrentProcess(); + + /// Retrieves a const reference to the current process. + const SharedPtr& CurrentProcess() const; + /// Adds a port to the named port table void AddNamedPort(std::string name, SharedPtr port); -- cgit v1.2.3