diff options
| author | 2021-05-07 23:30:17 -0700 | |
|---|---|---|
| committer | 2021-05-07 23:30:17 -0700 | |
| commit | faa067f175cbf5e916ed75776817f0046e6731c4 (patch) | |
| tree | 8ab02a72a6e4d6578848c8da2c02af02684aeec7 /src/core/hle/kernel/kernel.h | |
| parent | Merge pull request #6287 from lioncash/ldr-copy (diff) | |
| parent | hle: kernel: KPageTable: CanContain should not be constexpr. (diff) | |
| download | yuzu-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.h | 117 |
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 | ||
| 17 | namespace Core { | 19 | namespace Core { |
| 18 | class CPUInterruptHandler; | 20 | class CPUInterruptHandler; |
| @@ -27,20 +29,32 @@ struct EventType; | |||
| 27 | 29 | ||
| 28 | namespace Kernel { | 30 | namespace Kernel { |
| 29 | 31 | ||
| 30 | class ClientPort; | 32 | class KClientPort; |
| 31 | class GlobalSchedulerContext; | 33 | class GlobalSchedulerContext; |
| 32 | class HandleTable; | 34 | class KAutoObjectWithListContainer; |
| 35 | class KClientSession; | ||
| 36 | class KEvent; | ||
| 37 | class KHandleTable; | ||
| 38 | class KLinkedListNode; | ||
| 33 | class KMemoryManager; | 39 | class KMemoryManager; |
| 40 | class KPort; | ||
| 41 | class KProcess; | ||
| 34 | class KResourceLimit; | 42 | class KResourceLimit; |
| 35 | class KScheduler; | 43 | class KScheduler; |
| 44 | class KSession; | ||
| 36 | class KSharedMemory; | 45 | class KSharedMemory; |
| 37 | class KThread; | 46 | class KThread; |
| 47 | class KTransferMemory; | ||
| 48 | class KWritableEvent; | ||
| 38 | class PhysicalCore; | 49 | class PhysicalCore; |
| 39 | class Process; | ||
| 40 | class ServiceThread; | 50 | class ServiceThread; |
| 41 | class Synchronization; | 51 | class Synchronization; |
| 42 | class TimeManager; | 52 | class TimeManager; |
| 43 | 53 | ||
| 54 | namespace Init { | ||
| 55 | struct KSlabResourceCounts; | ||
| 56 | } | ||
| 57 | |||
| 44 | template <typename T> | 58 | template <typename T> |
| 45 | class KSlabHeap; | 59 | class 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. |
| 52 | class KernelCore { | 66 | class KernelCore { |
| 53 | private: | 67 | private: |
| 54 | using NamedPortTable = std::unordered_map<std::string, std::shared_ptr<ClientPort>>; | 68 | using NamedPortTable = std::unordered_map<std::string, KClientPort*>; |
| 55 | 69 | ||
| 56 | public: | 70 | public: |
| 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 | |||
| 246 | private: | 305 | private: |
| 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 | |||
| 332 | private: | ||
| 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 |