summaryrefslogtreecommitdiff
path: root/src/core/hle/kernel/kernel.h
diff options
context:
space:
mode:
authorGravatar bunnei2021-05-07 23:30:17 -0700
committerGravatar GitHub2021-05-07 23:30:17 -0700
commitfaa067f175cbf5e916ed75776817f0046e6731c4 (patch)
tree8ab02a72a6e4d6578848c8da2c02af02684aeec7 /src/core/hle/kernel/kernel.h
parentMerge pull request #6287 from lioncash/ldr-copy (diff)
parenthle: kernel: KPageTable: CanContain should not be constexpr. (diff)
downloadyuzu-faa067f175cbf5e916ed75776817f0046e6731c4.tar.gz
yuzu-faa067f175cbf5e916ed75776817f0046e6731c4.tar.xz
yuzu-faa067f175cbf5e916ed75776817f0046e6731c4.zip
Merge pull request #6266 from bunnei/kautoobject-refactor
Kernel Rework: Migrate kernel objects to KAutoObject
Diffstat (limited to 'src/core/hle/kernel/kernel.h')
-rw-r--r--src/core/hle/kernel/kernel.h117
1 files changed, 97 insertions, 20 deletions
diff --git a/src/core/hle/kernel/kernel.h b/src/core/hle/kernel/kernel.h
index a500e63bc..51aaccbc7 100644
--- a/src/core/hle/kernel/kernel.h
+++ b/src/core/hle/kernel/kernel.h
@@ -11,8 +11,10 @@
11#include <vector> 11#include <vector>
12#include "core/arm/cpu_interrupt_handler.h" 12#include "core/arm/cpu_interrupt_handler.h"
13#include "core/hardware_properties.h" 13#include "core/hardware_properties.h"
14#include "core/hle/kernel/k_auto_object.h"
15#include "core/hle/kernel/k_slab_heap.h"
14#include "core/hle/kernel/memory_types.h" 16#include "core/hle/kernel/memory_types.h"
15#include "core/hle/kernel/object.h" 17#include "core/hle/kernel/svc_common.h"
16 18
17namespace Core { 19namespace Core {
18class CPUInterruptHandler; 20class CPUInterruptHandler;
@@ -27,20 +29,32 @@ struct EventType;
27 29
28namespace Kernel { 30namespace Kernel {
29 31
30class ClientPort; 32class KClientPort;
31class GlobalSchedulerContext; 33class GlobalSchedulerContext;
32class HandleTable; 34class KAutoObjectWithListContainer;
35class KClientSession;
36class KEvent;
37class KHandleTable;
38class KLinkedListNode;
33class KMemoryManager; 39class KMemoryManager;
40class KPort;
41class KProcess;
34class KResourceLimit; 42class KResourceLimit;
35class KScheduler; 43class KScheduler;
44class KSession;
36class KSharedMemory; 45class KSharedMemory;
37class KThread; 46class KThread;
47class KTransferMemory;
48class KWritableEvent;
38class PhysicalCore; 49class PhysicalCore;
39class Process;
40class ServiceThread; 50class ServiceThread;
41class Synchronization; 51class Synchronization;
42class TimeManager; 52class TimeManager;
43 53
54namespace Init {
55struct KSlabResourceCounts;
56}
57
44template <typename T> 58template <typename T>
45class KSlabHeap; 59class KSlabHeap;
46 60
@@ -51,7 +65,7 @@ constexpr EmuThreadHandle EmuThreadHandleReserved{1ULL << 63};
51/// Represents a single instance of the kernel. 65/// Represents a single instance of the kernel.
52class KernelCore { 66class KernelCore {
53private: 67private:
54 using NamedPortTable = std::unordered_map<std::string, std::shared_ptr<ClientPort>>; 68 using NamedPortTable = std::unordered_map<std::string, KClientPort*>;
55 69
56public: 70public:
57 /// Constructs an instance of the kernel using the given System 71 /// Constructs an instance of the kernel using the given System
@@ -83,25 +97,28 @@ public:
83 void Shutdown(); 97 void Shutdown();
84 98
85 /// Retrieves a shared pointer to the system resource limit instance. 99 /// Retrieves a shared pointer to the system resource limit instance.
86 std::shared_ptr<KResourceLimit> GetSystemResourceLimit() const; 100 const KResourceLimit* GetSystemResourceLimit() const;
101
102 /// Retrieves a shared pointer to the system resource limit instance.
103 KResourceLimit* GetSystemResourceLimit();
87 104
88 /// Retrieves a shared pointer to a Thread instance within the thread wakeup handle table. 105 /// Retrieves a shared pointer to a Thread instance within the thread wakeup handle table.
89 std::shared_ptr<KThread> RetrieveThreadFromGlobalHandleTable(Handle handle) const; 106 KScopedAutoObject<KThread> RetrieveThreadFromGlobalHandleTable(Handle handle) const;
90 107
91 /// Adds the given shared pointer to an internal list of active processes. 108 /// Adds the given shared pointer to an internal list of active processes.
92 void AppendNewProcess(std::shared_ptr<Process> process); 109 void AppendNewProcess(KProcess* process);
93 110
94 /// Makes the given process the new current process. 111 /// Makes the given process the new current process.
95 void MakeCurrentProcess(Process* process); 112 void MakeCurrentProcess(KProcess* process);
96 113
97 /// Retrieves a pointer to the current process. 114 /// Retrieves a pointer to the current process.
98 Process* CurrentProcess(); 115 KProcess* CurrentProcess();
99 116
100 /// Retrieves a const pointer to the current process. 117 /// Retrieves a const pointer to the current process.
101 const Process* CurrentProcess() const; 118 const KProcess* CurrentProcess() const;
102 119
103 /// Retrieves the list of processes. 120 /// Retrieves the list of processes.
104 const std::vector<std::shared_ptr<Process>>& GetProcessList() const; 121 const std::vector<KProcess*>& GetProcessList() const;
105 122
106 /// Gets the sole instance of the global scheduler 123 /// Gets the sole instance of the global scheduler
107 Kernel::GlobalSchedulerContext& GlobalSchedulerContext(); 124 Kernel::GlobalSchedulerContext& GlobalSchedulerContext();
@@ -143,6 +160,10 @@ public:
143 160
144 const Core::ExclusiveMonitor& GetExclusiveMonitor() const; 161 const Core::ExclusiveMonitor& GetExclusiveMonitor() const;
145 162
163 KAutoObjectWithListContainer& ObjectListContainer();
164
165 const KAutoObjectWithListContainer& ObjectListContainer() const;
166
146 std::array<Core::CPUInterruptHandler, Core::Hardware::NUM_CPU_CORES>& Interrupts(); 167 std::array<Core::CPUInterruptHandler, Core::Hardware::NUM_CPU_CORES>& Interrupts();
147 168
148 const std::array<Core::CPUInterruptHandler, Core::Hardware::NUM_CPU_CORES>& Interrupts() const; 169 const std::array<Core::CPUInterruptHandler, Core::Hardware::NUM_CPU_CORES>& Interrupts() const;
@@ -152,7 +173,7 @@ public:
152 void InvalidateCpuInstructionCacheRange(VAddr addr, std::size_t size); 173 void InvalidateCpuInstructionCacheRange(VAddr addr, std::size_t size);
153 174
154 /// Adds a port to the named port table 175 /// Adds a port to the named port table
155 void AddNamedPort(std::string name, std::shared_ptr<ClientPort> port); 176 void AddNamedPort(std::string name, KClientPort* port);
156 177
157 /// Finds a port within the named port table with the given name. 178 /// Finds a port within the named port table with the given name.
158 NamedPortTable::iterator FindNamedPort(const std::string& name); 179 NamedPortTable::iterator FindNamedPort(const std::string& name);
@@ -225,9 +246,10 @@ public:
225 246
226 /** 247 /**
227 * Creates an HLE service thread, which are used to execute service routines asynchronously. 248 * Creates an HLE service thread, which are used to execute service routines asynchronously.
228 * While these are allocated per ServerSession, these need to be owned and managed outside of 249 * While these are allocated per ServerSession, these need to be owned and managed outside
229 * ServerSession to avoid a circular dependency. 250 * of ServerSession to avoid a circular dependency.
230 * @param name String name for the ServerSession creating this thread, used for debug purposes. 251 * @param name String name for the ServerSession creating this thread, used for debug
252 * purposes.
231 * @returns The a weak pointer newly created service thread. 253 * @returns The a weak pointer newly created service thread.
232 */ 254 */
233 std::weak_ptr<Kernel::ServiceThread> CreateServiceThread(const std::string& name); 255 std::weak_ptr<Kernel::ServiceThread> CreateServiceThread(const std::string& name);
@@ -243,9 +265,45 @@ public:
243 bool IsPhantomModeForSingleCore() const; 265 bool IsPhantomModeForSingleCore() const;
244 void SetIsPhantomModeForSingleCore(bool value); 266 void SetIsPhantomModeForSingleCore(bool value);
245 267
268 Core::System& System();
269 const Core::System& System() const;
270
271 /// Gets the slab heap for the specified kernel object type.
272 template <typename T>
273 KSlabHeap<T>& SlabHeap() {
274 if constexpr (std::is_same_v<T, KClientSession>) {
275 return slab_heap_container->client_session;
276 } else if constexpr (std::is_same_v<T, KEvent>) {
277 return slab_heap_container->event;
278 } else if constexpr (std::is_same_v<T, KLinkedListNode>) {
279 return slab_heap_container->linked_list_node;
280 } else if constexpr (std::is_same_v<T, KPort>) {
281 return slab_heap_container->port;
282 } else if constexpr (std::is_same_v<T, KProcess>) {
283 return slab_heap_container->process;
284 } else if constexpr (std::is_same_v<T, KResourceLimit>) {
285 return slab_heap_container->resource_limit;
286 } else if constexpr (std::is_same_v<T, KSession>) {
287 return slab_heap_container->session;
288 } else if constexpr (std::is_same_v<T, KSharedMemory>) {
289 return slab_heap_container->shared_memory;
290 } else if constexpr (std::is_same_v<T, KThread>) {
291 return slab_heap_container->thread;
292 } else if constexpr (std::is_same_v<T, KTransferMemory>) {
293 return slab_heap_container->transfer_memory;
294 } else if constexpr (std::is_same_v<T, KWritableEvent>) {
295 return slab_heap_container->writeable_event;
296 }
297 }
298
299 /// Gets the current slab resource counts.
300 Init::KSlabResourceCounts& SlabResourceCounts();
301
302 /// Gets the current slab resource counts.
303 const Init::KSlabResourceCounts& SlabResourceCounts() const;
304
246private: 305private:
247 friend class Object; 306 friend class KProcess;
248 friend class Process;
249 friend class KThread; 307 friend class KThread;
250 308
251 /// Creates a new object ID, incrementing the internal object ID counter. 309 /// Creates a new object ID, incrementing the internal object ID counter.
@@ -261,14 +319,33 @@ private:
261 u64 CreateNewThreadID(); 319 u64 CreateNewThreadID();
262 320
263 /// Provides a reference to the global handle table. 321 /// Provides a reference to the global handle table.
264 Kernel::HandleTable& GlobalHandleTable(); 322 KHandleTable& GlobalHandleTable();
265 323
266 /// Provides a const reference to the global handle table. 324 /// Provides a const reference to the global handle table.
267 const Kernel::HandleTable& GlobalHandleTable() const; 325 const KHandleTable& GlobalHandleTable() const;
268 326
269 struct Impl; 327 struct Impl;
270 std::unique_ptr<Impl> impl; 328 std::unique_ptr<Impl> impl;
329
271 bool exception_exited{}; 330 bool exception_exited{};
331
332private:
333 /// Helper to encapsulate all slab heaps in a single heap allocated container
334 struct SlabHeapContainer {
335 KSlabHeap<KClientSession> client_session;
336 KSlabHeap<KEvent> event;
337 KSlabHeap<KLinkedListNode> linked_list_node;
338 KSlabHeap<KPort> port;
339 KSlabHeap<KProcess> process;
340 KSlabHeap<KResourceLimit> resource_limit;
341 KSlabHeap<KSession> session;
342 KSlabHeap<KSharedMemory> shared_memory;
343 KSlabHeap<KThread> thread;
344 KSlabHeap<KTransferMemory> transfer_memory;
345 KSlabHeap<KWritableEvent> writeable_event;
346 };
347
348 std::unique_ptr<SlabHeapContainer> slab_heap_container;
272}; 349};
273 350
274} // namespace Kernel 351} // namespace Kernel