diff options
| author | 2018-09-02 11:58:58 -0400 | |
|---|---|---|
| committer | 2018-09-02 12:35:30 -0400 | |
| commit | 1242c1ec0aab88d91b0bb4faf6200e4f20e4bdc2 (patch) | |
| tree | f540b9cbc6db29bb5d41668f7efa8fc5c4e44469 /src/core/hle/kernel | |
| parent | Merge pull request #1213 from DarkLordZach/octopath-fs (diff) | |
| download | yuzu-1242c1ec0aab88d91b0bb4faf6200e4f20e4bdc2.tar.gz yuzu-1242c1ec0aab88d91b0bb4faf6200e4f20e4bdc2.tar.xz yuzu-1242c1ec0aab88d91b0bb4faf6200e4f20e4bdc2.zip | |
service: Migrate global named port map to the KernelCore class
Now that we have a class representing the kernel in some capacity, we
now have a place to put the named port map, so we move it over and get
rid of another piece of global state within the core.
Diffstat (limited to 'src/core/hle/kernel')
| -rw-r--r-- | src/core/hle/kernel/kernel.cpp | 24 | ||||
| -rw-r--r-- | src/core/hle/kernel/kernel.h | 18 | ||||
| -rw-r--r-- | src/core/hle/kernel/svc.cpp | 12 |
3 files changed, 49 insertions, 5 deletions
diff --git a/src/core/hle/kernel/kernel.cpp b/src/core/hle/kernel/kernel.cpp index 615d7901a..7902c2882 100644 --- a/src/core/hle/kernel/kernel.cpp +++ b/src/core/hle/kernel/kernel.cpp | |||
| @@ -13,6 +13,7 @@ | |||
| 13 | 13 | ||
| 14 | #include "core/core.h" | 14 | #include "core/core.h" |
| 15 | #include "core/core_timing.h" | 15 | #include "core/core_timing.h" |
| 16 | #include "core/hle/kernel/client_port.h" | ||
| 16 | #include "core/hle/kernel/handle_table.h" | 17 | #include "core/hle/kernel/handle_table.h" |
| 17 | #include "core/hle/kernel/kernel.h" | 18 | #include "core/hle/kernel/kernel.h" |
| 18 | #include "core/hle/kernel/process.h" | 19 | #include "core/hle/kernel/process.h" |
| @@ -124,6 +125,8 @@ struct KernelCore::Impl { | |||
| 124 | 125 | ||
| 125 | timer_callback_handle_table.Clear(); | 126 | timer_callback_handle_table.Clear(); |
| 126 | timer_callback_event_type = nullptr; | 127 | timer_callback_event_type = nullptr; |
| 128 | |||
| 129 | named_ports.clear(); | ||
| 127 | } | 130 | } |
| 128 | 131 | ||
| 129 | void InitializeResourceLimits(KernelCore& kernel) { | 132 | void InitializeResourceLimits(KernelCore& kernel) { |
| @@ -217,6 +220,10 @@ struct KernelCore::Impl { | |||
| 217 | // TODO(yuriks): This can be removed if Thread objects are explicitly pooled in the future, | 220 | // TODO(yuriks): This can be removed if Thread objects are explicitly pooled in the future, |
| 218 | // allowing us to simply use a pool index or similar. | 221 | // allowing us to simply use a pool index or similar. |
| 219 | Kernel::HandleTable thread_wakeup_callback_handle_table; | 222 | Kernel::HandleTable thread_wakeup_callback_handle_table; |
| 223 | |||
| 224 | /// Map of named ports managed by the kernel, which can be retrieved using | ||
| 225 | /// the ConnectToPort SVC. | ||
| 226 | NamedPortTable named_ports; | ||
| 220 | }; | 227 | }; |
| 221 | 228 | ||
| 222 | KernelCore::KernelCore() : impl{std::make_unique<Impl>()} {} | 229 | KernelCore::KernelCore() : impl{std::make_unique<Impl>()} {} |
| @@ -257,6 +264,23 @@ void KernelCore::AppendNewProcess(SharedPtr<Process> process) { | |||
| 257 | impl->process_list.push_back(std::move(process)); | 264 | impl->process_list.push_back(std::move(process)); |
| 258 | } | 265 | } |
| 259 | 266 | ||
| 267 | void KernelCore::AddNamedPort(std::string name, SharedPtr<ClientPort> port) { | ||
| 268 | impl->named_ports.emplace(std::move(name), std::move(port)); | ||
| 269 | } | ||
| 270 | |||
| 271 | KernelCore::NamedPortTable::iterator KernelCore::FindNamedPort(const std::string& name) { | ||
| 272 | return impl->named_ports.find(name); | ||
| 273 | } | ||
| 274 | |||
| 275 | KernelCore::NamedPortTable::const_iterator KernelCore::FindNamedPort( | ||
| 276 | const std::string& name) const { | ||
| 277 | return impl->named_ports.find(name); | ||
| 278 | } | ||
| 279 | |||
| 280 | bool KernelCore::IsValidNamedPort(NamedPortTable::const_iterator port) const { | ||
| 281 | return port != impl->named_ports.cend(); | ||
| 282 | } | ||
| 283 | |||
| 260 | u32 KernelCore::CreateNewObjectID() { | 284 | u32 KernelCore::CreateNewObjectID() { |
| 261 | return impl->next_object_id++; | 285 | return impl->next_object_id++; |
| 262 | } | 286 | } |
diff --git a/src/core/hle/kernel/kernel.h b/src/core/hle/kernel/kernel.h index 089e959ac..ab2e9bffa 100644 --- a/src/core/hle/kernel/kernel.h +++ b/src/core/hle/kernel/kernel.h | |||
| @@ -4,6 +4,8 @@ | |||
| 4 | 4 | ||
| 5 | #pragma once | 5 | #pragma once |
| 6 | 6 | ||
| 7 | #include <string> | ||
| 8 | #include <unordered_map> | ||
| 7 | #include "core/hle/kernel/object.h" | 9 | #include "core/hle/kernel/object.h" |
| 8 | 10 | ||
| 9 | template <typename T> | 11 | template <typename T> |
| @@ -15,6 +17,7 @@ struct EventType; | |||
| 15 | 17 | ||
| 16 | namespace Kernel { | 18 | namespace Kernel { |
| 17 | 19 | ||
| 20 | class ClientPort; | ||
| 18 | class HandleTable; | 21 | class HandleTable; |
| 19 | class Process; | 22 | class Process; |
| 20 | class ResourceLimit; | 23 | class ResourceLimit; |
| @@ -25,6 +28,9 @@ enum class ResourceLimitCategory : u8; | |||
| 25 | 28 | ||
| 26 | /// Represents a single instance of the kernel. | 29 | /// Represents a single instance of the kernel. |
| 27 | class KernelCore { | 30 | class KernelCore { |
| 31 | private: | ||
| 32 | using NamedPortTable = std::unordered_map<std::string, SharedPtr<ClientPort>>; | ||
| 33 | |||
| 28 | public: | 34 | public: |
| 29 | KernelCore(); | 35 | KernelCore(); |
| 30 | ~KernelCore(); | 36 | ~KernelCore(); |
| @@ -59,6 +65,18 @@ public: | |||
| 59 | /// Adds the given shared pointer to an internal list of active processes. | 65 | /// Adds the given shared pointer to an internal list of active processes. |
| 60 | void AppendNewProcess(SharedPtr<Process> process); | 66 | void AppendNewProcess(SharedPtr<Process> process); |
| 61 | 67 | ||
| 68 | /// Adds a port to the named port table | ||
| 69 | void AddNamedPort(std::string name, SharedPtr<ClientPort> port); | ||
| 70 | |||
| 71 | /// Finds a port within the named port table with the given name. | ||
| 72 | NamedPortTable::iterator FindNamedPort(const std::string& name); | ||
| 73 | |||
| 74 | /// Finds a port within the named port table with the given name. | ||
| 75 | NamedPortTable::const_iterator FindNamedPort(const std::string& name) const; | ||
| 76 | |||
| 77 | /// Determines whether or not the given port is a valid named port. | ||
| 78 | bool IsValidNamedPort(NamedPortTable::const_iterator port) const; | ||
| 79 | |||
| 62 | private: | 80 | private: |
| 63 | friend class Object; | 81 | friend class Object; |
| 64 | friend class Process; | 82 | friend class Process; |
diff --git a/src/core/hle/kernel/svc.cpp b/src/core/hle/kernel/svc.cpp index 5da71cff0..1c9373ed8 100644 --- a/src/core/hle/kernel/svc.cpp +++ b/src/core/hle/kernel/svc.cpp | |||
| @@ -68,19 +68,22 @@ static ResultCode UnmapMemory(VAddr dst_addr, VAddr src_addr, u64 size) { | |||
| 68 | 68 | ||
| 69 | /// Connect to an OS service given the port name, returns the handle to the port to out | 69 | /// Connect to an OS service given the port name, returns the handle to the port to out |
| 70 | static ResultCode ConnectToNamedPort(Handle* out_handle, VAddr port_name_address) { | 70 | static ResultCode ConnectToNamedPort(Handle* out_handle, VAddr port_name_address) { |
| 71 | if (!Memory::IsValidVirtualAddress(port_name_address)) | 71 | if (!Memory::IsValidVirtualAddress(port_name_address)) { |
| 72 | return ERR_NOT_FOUND; | 72 | return ERR_NOT_FOUND; |
| 73 | } | ||
| 73 | 74 | ||
| 74 | static constexpr std::size_t PortNameMaxLength = 11; | 75 | static constexpr std::size_t PortNameMaxLength = 11; |
| 75 | // Read 1 char beyond the max allowed port name to detect names that are too long. | 76 | // Read 1 char beyond the max allowed port name to detect names that are too long. |
| 76 | std::string port_name = Memory::ReadCString(port_name_address, PortNameMaxLength + 1); | 77 | std::string port_name = Memory::ReadCString(port_name_address, PortNameMaxLength + 1); |
| 77 | if (port_name.size() > PortNameMaxLength) | 78 | if (port_name.size() > PortNameMaxLength) { |
| 78 | return ERR_PORT_NAME_TOO_LONG; | 79 | return ERR_PORT_NAME_TOO_LONG; |
| 80 | } | ||
| 79 | 81 | ||
| 80 | LOG_TRACE(Kernel_SVC, "called port_name={}", port_name); | 82 | LOG_TRACE(Kernel_SVC, "called port_name={}", port_name); |
| 81 | 83 | ||
| 82 | auto it = Service::g_kernel_named_ports.find(port_name); | 84 | auto& kernel = Core::System::GetInstance().Kernel(); |
| 83 | if (it == Service::g_kernel_named_ports.end()) { | 85 | auto it = kernel.FindNamedPort(port_name); |
| 86 | if (!kernel.IsValidNamedPort(it)) { | ||
| 84 | LOG_WARNING(Kernel_SVC, "tried to connect to unknown port: {}", port_name); | 87 | LOG_WARNING(Kernel_SVC, "tried to connect to unknown port: {}", port_name); |
| 85 | return ERR_NOT_FOUND; | 88 | return ERR_NOT_FOUND; |
| 86 | } | 89 | } |
| @@ -91,7 +94,6 @@ static ResultCode ConnectToNamedPort(Handle* out_handle, VAddr port_name_address | |||
| 91 | CASCADE_RESULT(client_session, client_port->Connect()); | 94 | CASCADE_RESULT(client_session, client_port->Connect()); |
| 92 | 95 | ||
| 93 | // Return the client session | 96 | // Return the client session |
| 94 | auto& kernel = Core::System::GetInstance().Kernel(); | ||
| 95 | CASCADE_RESULT(*out_handle, kernel.HandleTable().Create(client_session)); | 97 | CASCADE_RESULT(*out_handle, kernel.HandleTable().Create(client_session)); |
| 96 | return RESULT_SUCCESS; | 98 | return RESULT_SUCCESS; |
| 97 | } | 99 | } |