summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar bunnei2022-10-29 13:49:09 -0700
committerGravatar bunnei2022-11-03 21:17:06 -0700
commit62574616849e9c045fbec1f07f81461268f9ccb5 (patch)
tree8448e69d9bf05a6bcb3734f358cc650fe07a0c9b /src
parentcore: hle: kernel: k_system_control: Add SecureAppletMemorySize. (diff)
downloadyuzu-62574616849e9c045fbec1f07f81461268f9ccb5.tar.gz
yuzu-62574616849e9c045fbec1f07f81461268f9ccb5.tar.xz
yuzu-62574616849e9c045fbec1f07f81461268f9ccb5.zip
core: hle: kernel: k_page_group: Add KPageBufferSlabHeap.
Diffstat (limited to 'src')
-rw-r--r--src/core/hle/kernel/k_page_group.h86
1 files changed, 86 insertions, 0 deletions
diff --git a/src/core/hle/kernel/k_page_group.h b/src/core/hle/kernel/k_page_group.h
index 968753992..316f172f2 100644
--- a/src/core/hle/kernel/k_page_group.h
+++ b/src/core/hle/kernel/k_page_group.h
@@ -5,6 +5,7 @@
5 5
6#include <list> 6#include <list>
7 7
8#include "common/alignment.h"
8#include "common/assert.h" 9#include "common/assert.h"
9#include "common/common_types.h" 10#include "common/common_types.h"
10#include "core/hle/kernel/memory_types.h" 11#include "core/hle/kernel/memory_types.h"
@@ -12,6 +13,89 @@
12 13
13namespace Kernel { 14namespace Kernel {
14 15
16class KPageGroup;
17
18class KBlockInfo {
19private:
20 friend class KPageGroup;
21
22public:
23 constexpr KBlockInfo() = default;
24
25 constexpr void Initialize(PAddr addr, size_t np) {
26 ASSERT(Common::IsAligned(addr, PageSize));
27 ASSERT(static_cast<u32>(np) == np);
28
29 m_page_index = static_cast<u32>(addr) / PageSize;
30 m_num_pages = static_cast<u32>(np);
31 }
32
33 constexpr PAddr GetAddress() const {
34 return m_page_index * PageSize;
35 }
36 constexpr size_t GetNumPages() const {
37 return m_num_pages;
38 }
39 constexpr size_t GetSize() const {
40 return this->GetNumPages() * PageSize;
41 }
42 constexpr PAddr GetEndAddress() const {
43 return (m_page_index + m_num_pages) * PageSize;
44 }
45 constexpr PAddr GetLastAddress() const {
46 return this->GetEndAddress() - 1;
47 }
48
49 constexpr KBlockInfo* GetNext() const {
50 return m_next;
51 }
52
53 constexpr bool IsEquivalentTo(const KBlockInfo& rhs) const {
54 return m_page_index == rhs.m_page_index && m_num_pages == rhs.m_num_pages;
55 }
56
57 constexpr bool operator==(const KBlockInfo& rhs) const {
58 return this->IsEquivalentTo(rhs);
59 }
60
61 constexpr bool operator!=(const KBlockInfo& rhs) const {
62 return !(*this == rhs);
63 }
64
65 constexpr bool IsStrictlyBefore(PAddr addr) const {
66 const PAddr end = this->GetEndAddress();
67
68 if (m_page_index != 0 && end == 0) {
69 return false;
70 }
71
72 return end < addr;
73 }
74
75 constexpr bool operator<(PAddr addr) const {
76 return this->IsStrictlyBefore(addr);
77 }
78
79 constexpr bool TryConcatenate(PAddr addr, size_t np) {
80 if (addr != 0 && addr == this->GetEndAddress()) {
81 m_num_pages += static_cast<u32>(np);
82 return true;
83 }
84 return false;
85 }
86
87private:
88 constexpr void SetNext(KBlockInfo* next) {
89 m_next = next;
90 }
91
92private:
93 KBlockInfo* m_next{};
94 u32 m_page_index{};
95 u32 m_num_pages{};
96};
97static_assert(sizeof(KBlockInfo) <= 0x10);
98
15class KPageGroup final { 99class KPageGroup final {
16public: 100public:
17 class Node final { 101 class Node final {
@@ -92,6 +176,8 @@ public:
92 return nodes.empty(); 176 return nodes.empty();
93 } 177 }
94 178
179 void Finalize() {}
180
95private: 181private:
96 std::list<Node> nodes; 182 std::list<Node> nodes;
97}; 183};