diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index d12260d9c1..a2dce69a7f 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -181,6 +181,7 @@ add_library(core STATIC hle/kernel/k_scoped_scheduler_lock_and_sleep.h hle/kernel/k_shared_memory.cpp hle/kernel/k_shared_memory.h + hle/kernel/k_slab_heap.h hle/kernel/k_spin_lock.cpp hle/kernel/k_spin_lock.h hle/kernel/k_synchronization_object.cpp @@ -205,7 +206,6 @@ add_library(core STATIC hle/kernel/memory/page_heap.h hle/kernel/memory/page_table.cpp hle/kernel/memory/page_table.h - hle/kernel/memory/slab_heap.h hle/kernel/object.cpp hle/kernel/object.h hle/kernel/physical_core.cpp diff --git a/src/core/hle/kernel/memory/slab_heap.h b/src/core/hle/kernel/k_slab_heap.h similarity index 86% rename from src/core/hle/kernel/memory/slab_heap.h rename to src/core/hle/kernel/k_slab_heap.h index 465eaddb32..aa4471d2f3 100644 --- a/src/core/hle/kernel/memory/slab_heap.h +++ b/src/core/hle/kernel/k_slab_heap.h @@ -2,9 +2,6 @@ // Licensed under GPLv2 or any later version // Refer to the license.txt file included. -// This file references various implementation details from Atmosphere, an open-source firmware for -// the Nintendo Switch. Copyright 2018-2020 Atmosphere-NX. - #pragma once #include @@ -12,17 +9,17 @@ #include "common/assert.h" #include "common/common_types.h" -namespace Kernel::Memory { +namespace Kernel { namespace impl { -class SlabHeapImpl final : NonCopyable { +class KSlabHeapImpl final : NonCopyable { public: struct Node { Node* next{}; }; - constexpr SlabHeapImpl() = default; + constexpr KSlabHeapImpl() = default; void Initialize(std::size_t size) { ASSERT(head == nullptr); @@ -65,9 +62,9 @@ private: } // namespace impl -class SlabHeapBase : NonCopyable { +class KSlabHeapBase : NonCopyable { public: - constexpr SlabHeapBase() = default; + constexpr KSlabHeapBase() = default; constexpr bool Contains(uintptr_t addr) const { return start <= addr && addr < end; @@ -126,7 +123,7 @@ public: } private: - using Impl = impl::SlabHeapImpl; + using Impl = impl::KSlabHeapImpl; Impl impl; uintptr_t peak{}; @@ -135,9 +132,9 @@ private: }; template -class SlabHeap final : public SlabHeapBase { +class KSlabHeap final : public KSlabHeapBase { public: - constexpr SlabHeap() : SlabHeapBase() {} + constexpr KSlabHeap() : KSlabHeapBase() {} void Initialize(void* memory, std::size_t memory_size) { InitializeImpl(sizeof(T), memory, memory_size); @@ -160,4 +157,4 @@ public: } }; -} // namespace Kernel::Memory +} // namespace Kernel diff --git a/src/core/hle/kernel/kernel.cpp b/src/core/hle/kernel/kernel.cpp index 98b3ec7120..e4de3f3bf7 100644 --- a/src/core/hle/kernel/kernel.cpp +++ b/src/core/hle/kernel/kernel.cpp @@ -31,10 +31,10 @@ #include "core/hle/kernel/k_resource_limit.h" #include "core/hle/kernel/k_scheduler.h" #include "core/hle/kernel/k_shared_memory.h" +#include "core/hle/kernel/k_slab_heap.h" #include "core/hle/kernel/k_thread.h" #include "core/hle/kernel/kernel.h" #include "core/hle/kernel/memory/memory_manager.h" -#include "core/hle/kernel/memory/slab_heap.h" #include "core/hle/kernel/physical_core.h" #include "core/hle/kernel/process.h" #include "core/hle/kernel/service_thread.h" @@ -306,7 +306,7 @@ struct KernelCore::Impl { Memory::MemoryPermission::Read, time_addr, time_size, "Time:SharedMemory"); // Allocate slab heaps - user_slab_heap_pages = std::make_unique>(); + user_slab_heap_pages = std::make_unique>(); constexpr u64 user_slab_heap_size{0x1ef000}; // Reserve slab heaps @@ -349,7 +349,7 @@ struct KernelCore::Impl { // Kernel memory management std::unique_ptr memory_manager; - std::unique_ptr> user_slab_heap_pages; + std::unique_ptr> user_slab_heap_pages; // Shared memory for services std::shared_ptr hid_shared_mem; @@ -581,11 +581,11 @@ const Memory::MemoryManager& KernelCore::MemoryManager() const { return *impl->memory_manager; } -Memory::SlabHeap& KernelCore::GetUserSlabHeapPages() { +KSlabHeap& KernelCore::GetUserSlabHeapPages() { return *impl->user_slab_heap_pages; } -const Memory::SlabHeap& KernelCore::GetUserSlabHeapPages() const { +const KSlabHeap& KernelCore::GetUserSlabHeapPages() const { return *impl->user_slab_heap_pages; } diff --git a/src/core/hle/kernel/kernel.h b/src/core/hle/kernel/kernel.h index c5b32b2609..5488c962a0 100644 --- a/src/core/hle/kernel/kernel.h +++ b/src/core/hle/kernel/kernel.h @@ -29,8 +29,7 @@ namespace Kernel { namespace Memory { class MemoryManager; -template -class SlabHeap; + } // namespace Memory class ClientPort; @@ -46,6 +45,9 @@ class Synchronization; class KThread; class TimeManager; +template +class KSlabHeap; + using EmuThreadHandle = uintptr_t; constexpr EmuThreadHandle EmuThreadHandleInvalid{}; constexpr EmuThreadHandle EmuThreadHandleReserved{1ULL << 63}; @@ -184,10 +186,10 @@ public: const Memory::MemoryManager& MemoryManager() const; /// Gets the slab heap allocated for user space pages. - Memory::SlabHeap& GetUserSlabHeapPages(); + KSlabHeap& GetUserSlabHeapPages(); /// Gets the slab heap allocated for user space pages. - const Memory::SlabHeap& GetUserSlabHeapPages() const; + const KSlabHeap& GetUserSlabHeapPages() const; /// Gets the shared memory object for HID services. Kernel::KSharedMemory& GetHidSharedMem();