From fc84091d88ce131be7cbb143b4cd458bb0d1da51 Mon Sep 17 00:00:00 2001 From: Weiyi Wang Date: Fri, 26 Oct 2018 10:27:13 -0400 Subject: [PATCH] Service, Kernel: move named port list to kernel --- src/core/core.cpp | 1 - src/core/hle/kernel/kernel.cpp | 5 +++++ src/core/hle/kernel/kernel.h | 7 +++++++ src/core/hle/kernel/svc.cpp | 10 +++++----- src/core/hle/service/service.cpp | 15 +-------------- src/core/hle/service/service.h | 10 ---------- 6 files changed, 18 insertions(+), 30 deletions(-) diff --git a/src/core/core.cpp b/src/core/core.cpp index a06a9b549..78585380c 100644 --- a/src/core/core.cpp +++ b/src/core/core.cpp @@ -256,7 +256,6 @@ void System::Shutdown() { // Shutdown emulation session GDBStub::Shutdown(); VideoCore::Shutdown(); - Service::Shutdown(); kernel.reset(); HW::Shutdown(); telemetry_session.reset(); diff --git a/src/core/hle/kernel/kernel.cpp b/src/core/hle/kernel/kernel.cpp index 704b7b709..1c174d2ea 100644 --- a/src/core/hle/kernel/kernel.cpp +++ b/src/core/hle/kernel/kernel.cpp @@ -2,6 +2,7 @@ // Licensed under GPLv2 or any later version // Refer to the license.txt file included. +#include "core/hle/kernel/client_port.h" #include "core/hle/kernel/config_mem.h" #include "core/hle/kernel/handle_table.h" #include "core/hle/kernel/kernel.h" @@ -70,4 +71,8 @@ const SharedPage::Handler& KernelSystem::GetSharedPageHandler() const { return *shared_page_handler; } +void KernelSystem::AddNamedPort(std::string name, SharedPtr port) { + named_ports.emplace(std::move(name), std::move(port)); +} + } // namespace Kernel diff --git a/src/core/hle/kernel/kernel.h b/src/core/hle/kernel/kernel.h index 7d7560e50..f010cd388 100644 --- a/src/core/hle/kernel/kernel.h +++ b/src/core/hle/kernel/kernel.h @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include "common/common_types.h" @@ -215,6 +216,12 @@ public: std::array memory_regions; + /// Adds a port to the named port table + void AddNamedPort(std::string name, SharedPtr port); + + /// Map of named ports managed by the kernel, which can be retrieved using the ConnectToPort + std::unordered_map> named_ports; + private: void MemoryInit(u32 mem_type); diff --git a/src/core/hle/kernel/svc.cpp b/src/core/hle/kernel/svc.cpp index 9dc6f2700..f23b569d7 100644 --- a/src/core/hle/kernel/svc.cpp +++ b/src/core/hle/kernel/svc.cpp @@ -235,8 +235,10 @@ static ResultCode ConnectToPort(Handle* out_handle, VAddr port_name_address) { LOG_TRACE(Kernel_SVC, "called port_name={}", port_name); - auto it = Service::g_kernel_named_ports.find(port_name); - if (it == Service::g_kernel_named_ports.end()) { + KernelSystem& kernel = Core::System::GetInstance().Kernel(); + + auto it = kernel.named_ports.find(port_name); + if (it == kernel.named_ports.end()) { LOG_WARNING(Kernel_SVC, "tried to connect to unknown port: {}", port_name); return ERR_NOT_FOUND; } @@ -247,9 +249,7 @@ static ResultCode ConnectToPort(Handle* out_handle, VAddr port_name_address) { CASCADE_RESULT(client_session, client_port->Connect()); // Return the client session - CASCADE_RESULT(*out_handle, - Core::System::GetInstance().Kernel().GetCurrentProcess()->handle_table.Create( - client_session)); + CASCADE_RESULT(*out_handle, kernel.GetCurrentProcess()->handle_table.Create(client_session)); return RESULT_SUCCESS; } diff --git a/src/core/hle/service/service.cpp b/src/core/hle/service/service.cpp index 2402a786d..d4112fc21 100644 --- a/src/core/hle/service/service.cpp +++ b/src/core/hle/service/service.cpp @@ -61,8 +61,6 @@ using Kernel::SharedPtr; namespace Service { -std::unordered_map> g_kernel_named_ports; - const std::array service_module_map{ {{"FS", 0x00040130'00001102, FS::InstallInterfaces}, {"PM", 0x00040130'00001202, PM::InstallInterfaces}, @@ -149,7 +147,7 @@ void ServiceFrameworkBase::InstallAsNamedPort(Kernel::KernelSystem& kernel) { SharedPtr client_port; std::tie(server_port, client_port) = kernel.CreatePortPair(max_sessions, service_name); server_port->SetHleHandler(shared_from_this()); - AddNamedPort(service_name, std::move(client_port)); + kernel.AddNamedPort(service_name, std::move(client_port)); } void ServiceFrameworkBase::RegisterHandlersBase(const FunctionInfoBase* functions, std::size_t n) { @@ -214,11 +212,6 @@ void ServiceFrameworkBase::HandleSyncRequest(SharedPtr server_ses //////////////////////////////////////////////////////////////////////////////////////////////////// // Module interface -// TODO(yuriks): Move to kernel -void AddNamedPort(std::string name, SharedPtr port) { - g_kernel_named_ports.emplace(std::move(name), std::move(port)); -} - static bool AttemptLLE(const ServiceModuleInfo& service_module) { if (!Settings::values.lle_modules.at(service_module.name)) return false; @@ -247,10 +240,4 @@ void Init(Core::System& core) { LOG_DEBUG(Service, "initialized OK"); } -/// Shutdown ServiceManager -void Shutdown() { - - g_kernel_named_ports.clear(); - LOG_DEBUG(Service, "shutdown OK"); -} } // namespace Service diff --git a/src/core/hle/service/service.h b/src/core/hle/service/service.h index 5cb4fbf23..5f36f98de 100644 --- a/src/core/hle/service/service.h +++ b/src/core/hle/service/service.h @@ -8,7 +8,6 @@ #include #include #include -#include #include #include "common/common_types.h" #include "core/hle/kernel/hle_ipc.h" @@ -187,12 +186,6 @@ private: /// Initialize ServiceManager void Init(Core::System& system); -/// Shutdown ServiceManager -void Shutdown(); - -/// Map of named ports managed by the kernel, which can be retrieved using the ConnectToPort SVC. -extern std::unordered_map> g_kernel_named_ports; - struct ServiceModuleInfo { std::string name; u64 title_id; @@ -201,7 +194,4 @@ struct ServiceModuleInfo { extern const std::array service_module_map; -/// Adds a port to the named port table -void AddNamedPort(std::string name, Kernel::SharedPtr port); - } // namespace Service