diff options
| author | 2023-02-18 16:26:48 -0500 | |
|---|---|---|
| committer | 2023-02-21 12:19:25 -0500 | |
| commit | a9369726147c7499e0016e183d5d56a7b44efe4b (patch) | |
| tree | c1d1b4a9fdafd92863c0922b05d72c14de83ffa7 /src/core/hle/kernel/kernel.h | |
| parent | core: defer cpu shutdown (diff) | |
| download | yuzu-a9369726147c7499e0016e183d5d56a7b44efe4b.tar.gz yuzu-a9369726147c7499e0016e183d5d56a7b44efe4b.tar.xz yuzu-a9369726147c7499e0016e183d5d56a7b44efe4b.zip | |
service: refactor server architecture
Converts services to have their own processes
Diffstat (limited to 'src/core/hle/kernel/kernel.h')
| -rw-r--r-- | src/core/hle/kernel/kernel.h | 69 |
1 files changed, 14 insertions, 55 deletions
diff --git a/src/core/hle/kernel/kernel.h b/src/core/hle/kernel/kernel.h index 6e0668f7f..4449f6949 100644 --- a/src/core/hle/kernel/kernel.h +++ b/src/core/hle/kernel/kernel.h | |||
| @@ -9,6 +9,8 @@ | |||
| 9 | #include <string> | 9 | #include <string> |
| 10 | #include <unordered_map> | 10 | #include <unordered_map> |
| 11 | #include <vector> | 11 | #include <vector> |
| 12 | |||
| 13 | #include "common/polyfill_thread.h" | ||
| 12 | #include "core/hardware_properties.h" | 14 | #include "core/hardware_properties.h" |
| 13 | #include "core/hle/kernel/k_auto_object.h" | 15 | #include "core/hle/kernel/k_auto_object.h" |
| 14 | #include "core/hle/kernel/k_slab_heap.h" | 16 | #include "core/hle/kernel/k_slab_heap.h" |
| @@ -24,6 +26,10 @@ class CoreTiming; | |||
| 24 | struct EventType; | 26 | struct EventType; |
| 25 | } // namespace Core::Timing | 27 | } // namespace Core::Timing |
| 26 | 28 | ||
| 29 | namespace Service { | ||
| 30 | class ServerManager; | ||
| 31 | } | ||
| 32 | |||
| 27 | namespace Service::SM { | 33 | namespace Service::SM { |
| 28 | class ServiceManager; | 34 | class ServiceManager; |
| 29 | } | 35 | } |
| @@ -65,13 +71,6 @@ class KTransferMemory; | |||
| 65 | class KWorkerTaskManager; | 71 | class KWorkerTaskManager; |
| 66 | class KCodeMemory; | 72 | class KCodeMemory; |
| 67 | class PhysicalCore; | 73 | class PhysicalCore; |
| 68 | class ServiceThread; | ||
| 69 | class Synchronization; | ||
| 70 | |||
| 71 | using ServiceInterfaceFactory = | ||
| 72 | std::function<KClientPort&(Service::SM::ServiceManager&, Core::System&)>; | ||
| 73 | |||
| 74 | using ServiceInterfaceHandlerFn = std::function<void(Service::SM::ServiceManager&, KServerPort*)>; | ||
| 75 | 74 | ||
| 76 | namespace Init { | 75 | namespace Init { |
| 77 | struct KSlabResourceCounts; | 76 | struct KSlabResourceCounts; |
| @@ -80,15 +79,8 @@ struct KSlabResourceCounts; | |||
| 80 | template <typename T> | 79 | template <typename T> |
| 81 | class KSlabHeap; | 80 | class KSlabHeap; |
| 82 | 81 | ||
| 83 | using EmuThreadHandle = uintptr_t; | ||
| 84 | constexpr EmuThreadHandle EmuThreadHandleInvalid{}; | ||
| 85 | constexpr EmuThreadHandle EmuThreadHandleReserved{1ULL << 63}; | ||
| 86 | |||
| 87 | /// Represents a single instance of the kernel. | 82 | /// Represents a single instance of the kernel. |
| 88 | class KernelCore { | 83 | class KernelCore { |
| 89 | private: | ||
| 90 | using NamedPortTable = std::unordered_map<std::string, KClientPort*>; | ||
| 91 | |||
| 92 | public: | 84 | public: |
| 93 | /// Constructs an instance of the kernel using the given System | 85 | /// Constructs an instance of the kernel using the given System |
| 94 | /// instance as a context for any necessary system-related state, | 86 | /// instance as a context for any necessary system-related state, |
| @@ -196,18 +188,6 @@ public: | |||
| 196 | 188 | ||
| 197 | void InvalidateCpuInstructionCacheRange(VAddr addr, std::size_t size); | 189 | void InvalidateCpuInstructionCacheRange(VAddr addr, std::size_t size); |
| 198 | 190 | ||
| 199 | /// Registers a named HLE service, passing a factory used to open a port to that service. | ||
| 200 | void RegisterNamedService(std::string name, ServiceInterfaceFactory&& factory); | ||
| 201 | |||
| 202 | /// Registers a setup function for the named HLE service. | ||
| 203 | void RegisterInterfaceForNamedService(std::string name, ServiceInterfaceHandlerFn&& handler); | ||
| 204 | |||
| 205 | /// Opens a port to a service previously registered with RegisterNamedService. | ||
| 206 | KClientPort* CreateNamedServicePort(std::string name); | ||
| 207 | |||
| 208 | /// Accepts a session on a port created by CreateNamedServicePort. | ||
| 209 | void RegisterNamedServiceHandler(std::string name, KServerPort* server_port); | ||
| 210 | |||
| 211 | /// Registers all kernel objects with the global emulation state, this is purely for tracking | 191 | /// Registers all kernel objects with the global emulation state, this is purely for tracking |
| 212 | /// leaks after emulation has been shutdown. | 192 | /// leaks after emulation has been shutdown. |
| 213 | void RegisterKernelObject(KAutoObject* object); | 193 | void RegisterKernelObject(KAutoObject* object); |
| @@ -224,8 +204,8 @@ public: | |||
| 224 | /// destroyed during the current emulation session. | 204 | /// destroyed during the current emulation session. |
| 225 | void UnregisterInUseObject(KAutoObject* object); | 205 | void UnregisterInUseObject(KAutoObject* object); |
| 226 | 206 | ||
| 227 | /// Determines whether or not the given port is a valid named port. | 207 | // Runs the given server manager until shutdown. |
| 228 | bool IsValidNamedPort(NamedPortTable::const_iterator port) const; | 208 | void RunServer(std::unique_ptr<Service::ServerManager>&& server_manager); |
| 229 | 209 | ||
| 230 | /// Gets the current host_thread/guest_thread pointer. | 210 | /// Gets the current host_thread/guest_thread pointer. |
| 231 | KThread* GetCurrentEmuThread() const; | 211 | KThread* GetCurrentEmuThread() const; |
| @@ -242,6 +222,12 @@ public: | |||
| 242 | /// Register the current thread as a non CPU core thread. | 222 | /// Register the current thread as a non CPU core thread. |
| 243 | void RegisterHostThread(KThread* existing_thread = nullptr); | 223 | void RegisterHostThread(KThread* existing_thread = nullptr); |
| 244 | 224 | ||
| 225 | void RunOnGuestCoreProcess(std::string&& process_name, std::function<void()> func); | ||
| 226 | |||
| 227 | std::jthread RunOnHostCoreProcess(std::string&& process_name, std::function<void()> func); | ||
| 228 | |||
| 229 | std::jthread RunOnHostCoreThread(std::string&& thread_name, std::function<void()> func); | ||
| 230 | |||
| 245 | /// Gets global data for KObjectName. | 231 | /// Gets global data for KObjectName. |
| 246 | KObjectNameGlobalData& ObjectNameGlobalData(); | 232 | KObjectNameGlobalData& ObjectNameGlobalData(); |
| 247 | 233 | ||
| @@ -310,33 +296,6 @@ public: | |||
| 310 | 296 | ||
| 311 | void ExitSVCProfile(); | 297 | void ExitSVCProfile(); |
| 312 | 298 | ||
| 313 | /** | ||
| 314 | * Creates a host thread to execute HLE service requests, which are used to execute service | ||
| 315 | * routines asynchronously. While these are allocated per ServerSession, these need to be owned | ||
| 316 | * and managed outside of ServerSession to avoid a circular dependency. In general, most | ||
| 317 | * services can just use the default service thread, and not need their own host service thread. | ||
| 318 | * See GetDefaultServiceThread. | ||
| 319 | * @param name String name for the ServerSession creating this thread, used for debug | ||
| 320 | * purposes. | ||
| 321 | * @returns A reference to the newly created service thread. | ||
| 322 | */ | ||
| 323 | Kernel::ServiceThread& CreateServiceThread(const std::string& name); | ||
| 324 | |||
| 325 | /** | ||
| 326 | * Gets the default host service thread, which executes HLE service requests. Unless service | ||
| 327 | * requests need to block on the host, the default service thread should be used in favor of | ||
| 328 | * creating a new service thread. | ||
| 329 | * @returns A reference to the default service thread. | ||
| 330 | */ | ||
| 331 | Kernel::ServiceThread& GetDefaultServiceThread() const; | ||
| 332 | |||
| 333 | /** | ||
| 334 | * Releases a HLE service thread, instructing KernelCore to free it. This should be called when | ||
| 335 | * the ServerSession associated with the thread is destroyed. | ||
| 336 | * @param service_thread Service thread to release. | ||
| 337 | */ | ||
| 338 | void ReleaseServiceThread(Kernel::ServiceThread& service_thread); | ||
| 339 | |||
| 340 | /// Workaround for single-core mode when preempting threads while idle. | 299 | /// Workaround for single-core mode when preempting threads while idle. |
| 341 | bool IsPhantomModeForSingleCore() const; | 300 | bool IsPhantomModeForSingleCore() const; |
| 342 | void SetIsPhantomModeForSingleCore(bool value); | 301 | void SetIsPhantomModeForSingleCore(bool value); |