diff options
Diffstat (limited to '')
-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 |