diff options
author | bunnei <bunneidev@gmail.com> | 2020-04-05 21:26:25 +0200 |
---|---|---|
committer | bunnei <bunneidev@gmail.com> | 2020-04-17 06:59:30 +0200 |
commit | 548ef190ab95f2f4562f700f7e1c622df9bd6afe (patch) | |
tree | 161b938fe5304c1d06fffd0facc1067906050ea7 /src/core/hle/kernel/memory/memory_block_manager.h | |
parent | kernel: memory: Add PageHeap class, to manage a heap of pages. (diff) | |
download | yuzu-548ef190ab95f2f4562f700f7e1c622df9bd6afe.tar yuzu-548ef190ab95f2f4562f700f7e1c622df9bd6afe.tar.gz yuzu-548ef190ab95f2f4562f700f7e1c622df9bd6afe.tar.bz2 yuzu-548ef190ab95f2f4562f700f7e1c622df9bd6afe.tar.lz yuzu-548ef190ab95f2f4562f700f7e1c622df9bd6afe.tar.xz yuzu-548ef190ab95f2f4562f700f7e1c622df9bd6afe.tar.zst yuzu-548ef190ab95f2f4562f700f7e1c622df9bd6afe.zip |
Diffstat (limited to '')
-rw-r--r-- | src/core/hle/kernel/memory/memory_block_manager.h | 64 |
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 |