summaryrefslogtreecommitdiffstats
path: root/src/core/hle/kernel/memory/memory_block_manager.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/hle/kernel/memory/memory_block_manager.h')
-rw-r--r--src/core/hle/kernel/memory/memory_block_manager.h64
1 files changed, 64 insertions, 0 deletions
diff --git a/src/core/hle/kernel/memory/memory_block_manager.h b/src/core/hle/kernel/memory/memory_block_manager.h
new file mode 100644
index 000000000..0f2270f0f
--- /dev/null
+++ b/src/core/hle/kernel/memory/memory_block_manager.h
@@ -0,0 +1,64 @@
+// Copyright 2020 yuzu Emulator Project
+// Licensed under GPLv2 or any later version
+// Refer to the license.txt file included.
+
+#pragma once
+
+#include <functional>
+#include <list>
+#include <memory>
+
+#include "common/common_types.h"
+#include "core/hle/kernel/memory/memory_block.h"
+
+namespace Kernel::Memory {
+
+class MemoryBlockManager final {
+public:
+ using MemoryBlockTree = std::list<MemoryBlock>;
+ using iterator = MemoryBlockTree::iterator;
+ using const_iterator = MemoryBlockTree::const_iterator;
+
+public:
+ MemoryBlockManager(VAddr start_addr, VAddr end_addr);
+
+ iterator end() {
+ return memory_block_tree.end();
+ }
+ const_iterator end() const {
+ return memory_block_tree.end();
+ }
+ const_iterator cend() const {
+ return memory_block_tree.cend();
+ }
+
+ iterator FindIterator(VAddr addr);
+
+ VAddr FindFreeArea(VAddr region_start, std::size_t region_num_pages, std::size_t num_pages,
+ std::size_t align, std::size_t offset, std::size_t guard_pages);
+
+ void Update(VAddr addr, std::size_t num_pages, MemoryState prev_state,
+ MemoryPermission prev_perm, MemoryAttribute prev_attribute, MemoryState state,
+ MemoryPermission perm, MemoryAttribute attribute);
+
+ void Update(VAddr addr, std::size_t num_pages, MemoryState state,
+ MemoryPermission perm = MemoryPermission::None,
+ MemoryAttribute attribute = MemoryAttribute::None);
+
+ using IterateFunc = std::function<void(const MemoryInfo&)>;
+ void IterateForRange(VAddr start, VAddr end, IterateFunc&& func);
+
+ MemoryBlock& FindBlock(VAddr addr) {
+ return *FindIterator(addr);
+ }
+
+private:
+ void MergeAdjacent(iterator it, iterator& next_it);
+
+ const VAddr start_addr;
+ const VAddr end_addr;
+
+ MemoryBlockTree memory_block_tree;
+};
+
+} // namespace Kernel::Memory