summaryrefslogtreecommitdiff
path: root/src/core/hle/kernel/kernel.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/hle/kernel/kernel.h')
-rw-r--r--src/core/hle/kernel/kernel.h69
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;
24struct EventType; 26struct EventType;
25} // namespace Core::Timing 27} // namespace Core::Timing
26 28
29namespace Service {
30class ServerManager;
31}
32
27namespace Service::SM { 33namespace Service::SM {
28class ServiceManager; 34class ServiceManager;
29} 35}
@@ -65,13 +71,6 @@ class KTransferMemory;
65class KWorkerTaskManager; 71class KWorkerTaskManager;
66class KCodeMemory; 72class KCodeMemory;
67class PhysicalCore; 73class PhysicalCore;
68class ServiceThread;
69class Synchronization;
70
71using ServiceInterfaceFactory =
72 std::function<KClientPort&(Service::SM::ServiceManager&, Core::System&)>;
73
74using ServiceInterfaceHandlerFn = std::function<void(Service::SM::ServiceManager&, KServerPort*)>;
75 74
76namespace Init { 75namespace Init {
77struct KSlabResourceCounts; 76struct KSlabResourceCounts;
@@ -80,15 +79,8 @@ struct KSlabResourceCounts;
80template <typename T> 79template <typename T>
81class KSlabHeap; 80class KSlabHeap;
82 81
83using EmuThreadHandle = uintptr_t;
84constexpr EmuThreadHandle EmuThreadHandleInvalid{};
85constexpr EmuThreadHandle EmuThreadHandleReserved{1ULL << 63};
86
87/// Represents a single instance of the kernel. 82/// Represents a single instance of the kernel.
88class KernelCore { 83class KernelCore {
89private:
90 using NamedPortTable = std::unordered_map<std::string, KClientPort*>;
91
92public: 84public:
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);