diff options
author | bunnei <bunneidev@gmail.com> | 2021-04-10 07:10:14 +0200 |
---|---|---|
committer | bunnei <bunneidev@gmail.com> | 2021-05-06 01:40:51 +0200 |
commit | b6156e735cd78d4b7863491ae6bdc63e44404b73 (patch) | |
tree | e1ec7753ea7c86223135e2f51b1b1f649af48b90 /src/core/hle/kernel/slab_helpers.h | |
parent | hle: kernel: Ensure all kernel objects with KAutoObject are properly created. (diff) | |
download | yuzu-b6156e735cd78d4b7863491ae6bdc63e44404b73.tar yuzu-b6156e735cd78d4b7863491ae6bdc63e44404b73.tar.gz yuzu-b6156e735cd78d4b7863491ae6bdc63e44404b73.tar.bz2 yuzu-b6156e735cd78d4b7863491ae6bdc63e44404b73.tar.lz yuzu-b6156e735cd78d4b7863491ae6bdc63e44404b73.tar.xz yuzu-b6156e735cd78d4b7863491ae6bdc63e44404b73.tar.zst yuzu-b6156e735cd78d4b7863491ae6bdc63e44404b73.zip |
Diffstat (limited to 'src/core/hle/kernel/slab_helpers.h')
-rw-r--r-- | src/core/hle/kernel/slab_helpers.h | 95 |
1 files changed, 48 insertions, 47 deletions
diff --git a/src/core/hle/kernel/slab_helpers.h b/src/core/hle/kernel/slab_helpers.h index ae9d097da..4f23ddabf 100644 --- a/src/core/hle/kernel/slab_helpers.h +++ b/src/core/hle/kernel/slab_helpers.h @@ -20,44 +20,44 @@ namespace Kernel { template <class Derived> class KSlabAllocated { -private: - static inline KSlabHeap<Derived> s_slab_heap; - public: constexpr KSlabAllocated() = default; - size_t GetSlabIndex() const { - return s_slab_heap.GetIndex(static_cast<const Derived*>(this)); + size_t GetSlabIndex(KernelCore& kernel) const { + return kernel.SlabHeap<Derived>().GetIndex(static_cast<const Derived*>(this)); } public: - static void InitializeSlabHeap(void* memory, size_t memory_size) { - s_slab_heap.Initialize(memory, memory_size); + static void InitializeSlabHeap(KernelCore& kernel, void* memory, size_t memory_size) { + kernel.SlabHeap<Derived>().Initialize(memory, memory_size); } - static Derived* Allocate() { - return s_slab_heap.Allocate(); + static Derived* Allocate(KernelCore& kernel) { + return kernel.SlabHeap<Derived>().Allocate(); } - static void Free(Derived* obj) { - s_slab_heap.Free(obj); + static void Free(KernelCore& kernel, Derived* obj) { + kernel.SlabHeap<Derived>().Free(obj); } - static size_t GetObjectSize() { - return s_slab_heap.GetObjectSize(); + static size_t GetObjectSize(KernelCore& kernel) { + return kernel.SlabHeap<Derived>().GetObjectSize(); } - static size_t GetSlabHeapSize() { - return s_slab_heap.GetSlabHeapSize(); + + static size_t GetSlabHeapSize(KernelCore& kernel) { + return kernel.SlabHeap<Derived>().GetSlabHeapSize(); } - static size_t GetPeakIndex() { - return s_slab_heap.GetPeakIndex(); + + static size_t GetPeakIndex(KernelCore& kernel) { + return kernel.SlabHeap<Derived>().GetPeakIndex(); } - static uintptr_t GetSlabHeapAddress() { - return s_slab_heap.GetSlabHeapAddress(); + + static uintptr_t GetSlabHeapAddress(KernelCore& kernel) { + return kernel.SlabHeap<Derived>().GetSlabHeapAddress(); } - static size_t GetNumRemaining() { - return s_slab_heap.GetNumRemaining(); + static size_t GetNumRemaining(KernelCore& kernel) { + return kernel.SlabHeap<Derived>().GetNumRemaining(); } }; @@ -66,43 +66,38 @@ class KAutoObjectWithSlabHeapAndContainer : public Base { static_assert(std::is_base_of<KAutoObjectWithList, Base>::value); private: - static inline KSlabHeap<Derived> s_slab_heap; - KernelCore& m_kernel; - -private: - static Derived* Allocate() { - return s_slab_heap.Allocate(); + static Derived* Allocate(KernelCore& kernel) { + return kernel.SlabHeap<Derived>().Allocate(); } static Derived* AllocateWithKernel(KernelCore& kernel) { - return s_slab_heap.AllocateWithKernel(kernel); + return kernel.SlabHeap<Derived>().AllocateWithKernel(kernel); } - static void Free(Derived* obj) { - s_slab_heap.Free(obj); + static void Free(KernelCore& kernel, Derived* obj) { + kernel.SlabHeap<Derived>().Free(obj); } public: class ListAccessor : public KAutoObjectWithListContainer::ListAccessor { public: - ListAccessor() - : KAutoObjectWithListContainer::ListAccessor(m_kernel.ObjectListContainer()) {} + ListAccessor() : KAutoObjectWithListContainer::ListAccessor(kernel.ObjectListContainer()) {} ~ListAccessor() = default; }; public: - KAutoObjectWithSlabHeapAndContainer(KernelCore& kernel) : Base(kernel), m_kernel(kernel) {} + KAutoObjectWithSlabHeapAndContainer(KernelCore& kernel_) : Base(kernel_), kernel(kernel_) {} virtual ~KAutoObjectWithSlabHeapAndContainer() {} virtual void Destroy() override { const bool is_initialized = this->IsInitialized(); uintptr_t arg = 0; if (is_initialized) { - m_kernel.ObjectListContainer().Unregister(this); + kernel.ObjectListContainer().Unregister(this); arg = this->GetPostDestroyArgument(); this->Finalize(); } - Free(static_cast<Derived*>(this)); + Free(kernel, static_cast<Derived*>(this)); if (is_initialized) { Derived::PostDestroy(arg); } @@ -116,12 +111,12 @@ public: } size_t GetSlabIndex() const { - return s_slab_heap.GetObjectIndex(static_cast<const Derived*>(this)); + return SlabHeap<Derived>(kernel).GetObjectIndex(static_cast<const Derived*>(this)); } public: static void InitializeSlabHeap(KernelCore& kernel, void* memory, size_t memory_size) { - s_slab_heap.Initialize(memory, memory_size); + kernel.SlabHeap<Derived>().Initialize(memory, memory_size); kernel.ObjectListContainer().Initialize(); } @@ -145,22 +140,28 @@ public: return kernel.ObjectListContainer().Register(obj); } - static size_t GetObjectSize() { - return s_slab_heap.GetObjectSize(); + static size_t GetObjectSize(KernelCore& kernel) { + return kernel.SlabHeap<Derived>().GetObjectSize(); } - static size_t GetSlabHeapSize() { - return s_slab_heap.GetSlabHeapSize(); + + static size_t GetSlabHeapSize(KernelCore& kernel) { + return kernel.SlabHeap<Derived>().GetSlabHeapSize(); } - static size_t GetPeakIndex() { - return s_slab_heap.GetPeakIndex(); + + static size_t GetPeakIndex(KernelCore& kernel) { + return kernel.SlabHeap<Derived>().GetPeakIndex(); } - static uintptr_t GetSlabHeapAddress() { - return s_slab_heap.GetSlabHeapAddress(); + + static uintptr_t GetSlabHeapAddress(KernelCore& kernel) { + return kernel.SlabHeap<Derived>().GetSlabHeapAddress(); } - static size_t GetNumRemaining() { - return s_slab_heap.GetNumRemaining(); + static size_t GetNumRemaining(KernelCore& kernel) { + return kernel.SlabHeap<Derived>().GetNumRemaining(); } + +protected: + KernelCore& kernel; }; } // namespace Kernel |