Service, Kernel: move named port list to kernel

This commit is contained in:
Weiyi Wang 2018-10-26 10:27:13 -04:00
parent ece96807c4
commit fc84091d88
6 changed files with 18 additions and 30 deletions

View File

@ -256,7 +256,6 @@ void System::Shutdown() {
// Shutdown emulation session
GDBStub::Shutdown();
VideoCore::Shutdown();
Service::Shutdown();
kernel.reset();
HW::Shutdown();
telemetry_session.reset();

View File

@ -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<ClientPort> port) {
named_ports.emplace(std::move(name), std::move(port));
}
} // namespace Kernel

View File

@ -8,6 +8,7 @@
#include <atomic>
#include <memory>
#include <string>
#include <unordered_map>
#include <vector>
#include <boost/smart_ptr/intrusive_ptr.hpp>
#include "common/common_types.h"
@ -215,6 +216,12 @@ public:
std::array<MemoryRegionInfo, 3> memory_regions;
/// Adds a port to the named port table
void AddNamedPort(std::string name, SharedPtr<ClientPort> port);
/// Map of named ports managed by the kernel, which can be retrieved using the ConnectToPort
std::unordered_map<std::string, SharedPtr<ClientPort>> named_ports;
private:
void MemoryInit(u32 mem_type);

View File

@ -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;
}

View File

@ -61,8 +61,6 @@ using Kernel::SharedPtr;
namespace Service {
std::unordered_map<std::string, SharedPtr<ClientPort>> g_kernel_named_ports;
const std::array<ServiceModuleInfo, 40> service_module_map{
{{"FS", 0x00040130'00001102, FS::InstallInterfaces},
{"PM", 0x00040130'00001202, PM::InstallInterfaces},
@ -149,7 +147,7 @@ void ServiceFrameworkBase::InstallAsNamedPort(Kernel::KernelSystem& kernel) {
SharedPtr<ClientPort> 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<ServerSession> server_ses
////////////////////////////////////////////////////////////////////////////////////////////////////
// Module interface
// TODO(yuriks): Move to kernel
void AddNamedPort(std::string name, SharedPtr<ClientPort> 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

View File

@ -8,7 +8,6 @@
#include <cstddef>
#include <functional>
#include <string>
#include <unordered_map>
#include <boost/container/flat_map.hpp>
#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<std::string, Kernel::SharedPtr<Kernel::ClientPort>> g_kernel_named_ports;
struct ServiceModuleInfo {
std::string name;
u64 title_id;
@ -201,7 +194,4 @@ struct ServiceModuleInfo {
extern const std::array<ServiceModuleInfo, 40> service_module_map;
/// Adds a port to the named port table
void AddNamedPort(std::string name, Kernel::SharedPtr<Kernel::ClientPort> port);
} // namespace Service