hle: kernel: Migrate SlabHeap to KSlabHeap.
This commit is contained in:
parent
1d162f28d1
commit
9e520e8f12
|
@ -181,6 +181,7 @@ add_library(core STATIC
|
||||||
hle/kernel/k_scoped_scheduler_lock_and_sleep.h
|
hle/kernel/k_scoped_scheduler_lock_and_sleep.h
|
||||||
hle/kernel/k_shared_memory.cpp
|
hle/kernel/k_shared_memory.cpp
|
||||||
hle/kernel/k_shared_memory.h
|
hle/kernel/k_shared_memory.h
|
||||||
|
hle/kernel/k_slab_heap.h
|
||||||
hle/kernel/k_spin_lock.cpp
|
hle/kernel/k_spin_lock.cpp
|
||||||
hle/kernel/k_spin_lock.h
|
hle/kernel/k_spin_lock.h
|
||||||
hle/kernel/k_synchronization_object.cpp
|
hle/kernel/k_synchronization_object.cpp
|
||||||
|
@ -205,7 +206,6 @@ add_library(core STATIC
|
||||||
hle/kernel/memory/page_heap.h
|
hle/kernel/memory/page_heap.h
|
||||||
hle/kernel/memory/page_table.cpp
|
hle/kernel/memory/page_table.cpp
|
||||||
hle/kernel/memory/page_table.h
|
hle/kernel/memory/page_table.h
|
||||||
hle/kernel/memory/slab_heap.h
|
|
||||||
hle/kernel/object.cpp
|
hle/kernel/object.cpp
|
||||||
hle/kernel/object.h
|
hle/kernel/object.h
|
||||||
hle/kernel/physical_core.cpp
|
hle/kernel/physical_core.cpp
|
||||||
|
|
|
@ -2,9 +2,6 @@
|
||||||
// Licensed under GPLv2 or any later version
|
// Licensed under GPLv2 or any later version
|
||||||
// Refer to the license.txt file included.
|
// 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
|
#pragma once
|
||||||
|
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
|
@ -12,17 +9,17 @@
|
||||||
#include "common/assert.h"
|
#include "common/assert.h"
|
||||||
#include "common/common_types.h"
|
#include "common/common_types.h"
|
||||||
|
|
||||||
namespace Kernel::Memory {
|
namespace Kernel {
|
||||||
|
|
||||||
namespace impl {
|
namespace impl {
|
||||||
|
|
||||||
class SlabHeapImpl final : NonCopyable {
|
class KSlabHeapImpl final : NonCopyable {
|
||||||
public:
|
public:
|
||||||
struct Node {
|
struct Node {
|
||||||
Node* next{};
|
Node* next{};
|
||||||
};
|
};
|
||||||
|
|
||||||
constexpr SlabHeapImpl() = default;
|
constexpr KSlabHeapImpl() = default;
|
||||||
|
|
||||||
void Initialize(std::size_t size) {
|
void Initialize(std::size_t size) {
|
||||||
ASSERT(head == nullptr);
|
ASSERT(head == nullptr);
|
||||||
|
@ -65,9 +62,9 @@ private:
|
||||||
|
|
||||||
} // namespace impl
|
} // namespace impl
|
||||||
|
|
||||||
class SlabHeapBase : NonCopyable {
|
class KSlabHeapBase : NonCopyable {
|
||||||
public:
|
public:
|
||||||
constexpr SlabHeapBase() = default;
|
constexpr KSlabHeapBase() = default;
|
||||||
|
|
||||||
constexpr bool Contains(uintptr_t addr) const {
|
constexpr bool Contains(uintptr_t addr) const {
|
||||||
return start <= addr && addr < end;
|
return start <= addr && addr < end;
|
||||||
|
@ -126,7 +123,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
using Impl = impl::SlabHeapImpl;
|
using Impl = impl::KSlabHeapImpl;
|
||||||
|
|
||||||
Impl impl;
|
Impl impl;
|
||||||
uintptr_t peak{};
|
uintptr_t peak{};
|
||||||
|
@ -135,9 +132,9 @@ private:
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
class SlabHeap final : public SlabHeapBase {
|
class KSlabHeap final : public KSlabHeapBase {
|
||||||
public:
|
public:
|
||||||
constexpr SlabHeap() : SlabHeapBase() {}
|
constexpr KSlabHeap() : KSlabHeapBase() {}
|
||||||
|
|
||||||
void Initialize(void* memory, std::size_t memory_size) {
|
void Initialize(void* memory, std::size_t memory_size) {
|
||||||
InitializeImpl(sizeof(T), memory, memory_size);
|
InitializeImpl(sizeof(T), memory, memory_size);
|
||||||
|
@ -160,4 +157,4 @@ public:
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Kernel::Memory
|
} // namespace Kernel
|
|
@ -31,10 +31,10 @@
|
||||||
#include "core/hle/kernel/k_resource_limit.h"
|
#include "core/hle/kernel/k_resource_limit.h"
|
||||||
#include "core/hle/kernel/k_scheduler.h"
|
#include "core/hle/kernel/k_scheduler.h"
|
||||||
#include "core/hle/kernel/k_shared_memory.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/k_thread.h"
|
||||||
#include "core/hle/kernel/kernel.h"
|
#include "core/hle/kernel/kernel.h"
|
||||||
#include "core/hle/kernel/memory/memory_manager.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/physical_core.h"
|
||||||
#include "core/hle/kernel/process.h"
|
#include "core/hle/kernel/process.h"
|
||||||
#include "core/hle/kernel/service_thread.h"
|
#include "core/hle/kernel/service_thread.h"
|
||||||
|
@ -306,7 +306,7 @@ struct KernelCore::Impl {
|
||||||
Memory::MemoryPermission::Read, time_addr, time_size, "Time:SharedMemory");
|
Memory::MemoryPermission::Read, time_addr, time_size, "Time:SharedMemory");
|
||||||
|
|
||||||
// Allocate slab heaps
|
// Allocate slab heaps
|
||||||
user_slab_heap_pages = std::make_unique<Memory::SlabHeap<Memory::Page>>();
|
user_slab_heap_pages = std::make_unique<KSlabHeap<Memory::Page>>();
|
||||||
|
|
||||||
constexpr u64 user_slab_heap_size{0x1ef000};
|
constexpr u64 user_slab_heap_size{0x1ef000};
|
||||||
// Reserve slab heaps
|
// Reserve slab heaps
|
||||||
|
@ -349,7 +349,7 @@ struct KernelCore::Impl {
|
||||||
|
|
||||||
// Kernel memory management
|
// Kernel memory management
|
||||||
std::unique_ptr<Memory::MemoryManager> memory_manager;
|
std::unique_ptr<Memory::MemoryManager> memory_manager;
|
||||||
std::unique_ptr<Memory::SlabHeap<Memory::Page>> user_slab_heap_pages;
|
std::unique_ptr<KSlabHeap<Memory::Page>> user_slab_heap_pages;
|
||||||
|
|
||||||
// Shared memory for services
|
// Shared memory for services
|
||||||
std::shared_ptr<Kernel::KSharedMemory> hid_shared_mem;
|
std::shared_ptr<Kernel::KSharedMemory> hid_shared_mem;
|
||||||
|
@ -581,11 +581,11 @@ const Memory::MemoryManager& KernelCore::MemoryManager() const {
|
||||||
return *impl->memory_manager;
|
return *impl->memory_manager;
|
||||||
}
|
}
|
||||||
|
|
||||||
Memory::SlabHeap<Memory::Page>& KernelCore::GetUserSlabHeapPages() {
|
KSlabHeap<Memory::Page>& KernelCore::GetUserSlabHeapPages() {
|
||||||
return *impl->user_slab_heap_pages;
|
return *impl->user_slab_heap_pages;
|
||||||
}
|
}
|
||||||
|
|
||||||
const Memory::SlabHeap<Memory::Page>& KernelCore::GetUserSlabHeapPages() const {
|
const KSlabHeap<Memory::Page>& KernelCore::GetUserSlabHeapPages() const {
|
||||||
return *impl->user_slab_heap_pages;
|
return *impl->user_slab_heap_pages;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -29,8 +29,7 @@ namespace Kernel {
|
||||||
|
|
||||||
namespace Memory {
|
namespace Memory {
|
||||||
class MemoryManager;
|
class MemoryManager;
|
||||||
template <typename T>
|
|
||||||
class SlabHeap;
|
|
||||||
} // namespace Memory
|
} // namespace Memory
|
||||||
|
|
||||||
class ClientPort;
|
class ClientPort;
|
||||||
|
@ -46,6 +45,9 @@ class Synchronization;
|
||||||
class KThread;
|
class KThread;
|
||||||
class TimeManager;
|
class TimeManager;
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
class KSlabHeap;
|
||||||
|
|
||||||
using EmuThreadHandle = uintptr_t;
|
using EmuThreadHandle = uintptr_t;
|
||||||
constexpr EmuThreadHandle EmuThreadHandleInvalid{};
|
constexpr EmuThreadHandle EmuThreadHandleInvalid{};
|
||||||
constexpr EmuThreadHandle EmuThreadHandleReserved{1ULL << 63};
|
constexpr EmuThreadHandle EmuThreadHandleReserved{1ULL << 63};
|
||||||
|
@ -184,10 +186,10 @@ public:
|
||||||
const Memory::MemoryManager& MemoryManager() const;
|
const Memory::MemoryManager& MemoryManager() const;
|
||||||
|
|
||||||
/// Gets the slab heap allocated for user space pages.
|
/// Gets the slab heap allocated for user space pages.
|
||||||
Memory::SlabHeap<Memory::Page>& GetUserSlabHeapPages();
|
KSlabHeap<Memory::Page>& GetUserSlabHeapPages();
|
||||||
|
|
||||||
/// Gets the slab heap allocated for user space pages.
|
/// Gets the slab heap allocated for user space pages.
|
||||||
const Memory::SlabHeap<Memory::Page>& GetUserSlabHeapPages() const;
|
const KSlabHeap<Memory::Page>& GetUserSlabHeapPages() const;
|
||||||
|
|
||||||
/// Gets the shared memory object for HID services.
|
/// Gets the shared memory object for HID services.
|
||||||
Kernel::KSharedMemory& GetHidSharedMem();
|
Kernel::KSharedMemory& GetHidSharedMem();
|
||||||
|
|
Loading…
Reference in New Issue