diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/common/page_table.cpp | 2 | ||||
| -rw-r--r-- | src/common/page_table.h | 14 | ||||
| -rw-r--r-- | src/common/virtual_buffer.cpp | 4 | ||||
| -rw-r--r-- | src/common/virtual_buffer.h | 29 |
4 files changed, 37 insertions, 12 deletions
diff --git a/src/common/page_table.cpp b/src/common/page_table.cpp index e5d3090d5..bccea0894 100644 --- a/src/common/page_table.cpp +++ b/src/common/page_table.cpp | |||
| @@ -8,7 +8,7 @@ namespace Common { | |||
| 8 | 8 | ||
| 9 | PageTable::PageTable() = default; | 9 | PageTable::PageTable() = default; |
| 10 | 10 | ||
| 11 | PageTable::~PageTable() = default; | 11 | PageTable::~PageTable() noexcept = default; |
| 12 | 12 | ||
| 13 | void PageTable::Resize(std::size_t address_space_width_in_bits, std::size_t page_size_in_bits, | 13 | void PageTable::Resize(std::size_t address_space_width_in_bits, std::size_t page_size_in_bits, |
| 14 | bool has_attribute) { | 14 | bool has_attribute) { |
diff --git a/src/common/page_table.h b/src/common/page_table.h index cf5eed780..9754fabf9 100644 --- a/src/common/page_table.h +++ b/src/common/page_table.h | |||
| @@ -4,9 +4,7 @@ | |||
| 4 | 4 | ||
| 5 | #pragma once | 5 | #pragma once |
| 6 | 6 | ||
| 7 | #include <vector> | 7 | #include <tuple> |
| 8 | |||
| 9 | #include <boost/icl/interval_map.hpp> | ||
| 10 | 8 | ||
| 11 | #include "common/common_types.h" | 9 | #include "common/common_types.h" |
| 12 | #include "common/memory_hook.h" | 10 | #include "common/memory_hook.h" |
| @@ -51,13 +49,21 @@ struct SpecialRegion { | |||
| 51 | */ | 49 | */ |
| 52 | struct PageTable { | 50 | struct PageTable { |
| 53 | PageTable(); | 51 | PageTable(); |
| 54 | ~PageTable(); | 52 | ~PageTable() noexcept; |
| 53 | |||
| 54 | PageTable(const PageTable&) = delete; | ||
| 55 | PageTable& operator=(const PageTable&) = delete; | ||
| 56 | |||
| 57 | PageTable(PageTable&&) noexcept = default; | ||
| 58 | PageTable& operator=(PageTable&&) noexcept = default; | ||
| 55 | 59 | ||
| 56 | /** | 60 | /** |
| 57 | * Resizes the page table to be able to accomodate enough pages within | 61 | * Resizes the page table to be able to accomodate enough pages within |
| 58 | * a given address space. | 62 | * a given address space. |
| 59 | * | 63 | * |
| 60 | * @param address_space_width_in_bits The address size width in bits. | 64 | * @param address_space_width_in_bits The address size width in bits. |
| 65 | * @param page_size_in_bits The page size in bits. | ||
| 66 | * @param has_attribute Whether or not this page has any backing attributes. | ||
| 61 | */ | 67 | */ |
| 62 | void Resize(std::size_t address_space_width_in_bits, std::size_t page_size_in_bits, | 68 | void Resize(std::size_t address_space_width_in_bits, std::size_t page_size_in_bits, |
| 63 | bool has_attribute); | 69 | bool has_attribute); |
diff --git a/src/common/virtual_buffer.cpp b/src/common/virtual_buffer.cpp index b009cb500..e3ca29258 100644 --- a/src/common/virtual_buffer.cpp +++ b/src/common/virtual_buffer.cpp | |||
| @@ -13,7 +13,7 @@ | |||
| 13 | 13 | ||
| 14 | namespace Common { | 14 | namespace Common { |
| 15 | 15 | ||
| 16 | void* AllocateMemoryPages(std::size_t size) { | 16 | void* AllocateMemoryPages(std::size_t size) noexcept { |
| 17 | #ifdef _WIN32 | 17 | #ifdef _WIN32 |
| 18 | void* base{VirtualAlloc(nullptr, size, MEM_COMMIT, PAGE_READWRITE)}; | 18 | void* base{VirtualAlloc(nullptr, size, MEM_COMMIT, PAGE_READWRITE)}; |
| 19 | #else | 19 | #else |
| @@ -29,7 +29,7 @@ void* AllocateMemoryPages(std::size_t size) { | |||
| 29 | return base; | 29 | return base; |
| 30 | } | 30 | } |
| 31 | 31 | ||
| 32 | void FreeMemoryPages(void* base, [[maybe_unused]] std::size_t size) { | 32 | void FreeMemoryPages(void* base, [[maybe_unused]] std::size_t size) noexcept { |
| 33 | if (!base) { | 33 | if (!base) { |
| 34 | return; | 34 | return; |
| 35 | } | 35 | } |
diff --git a/src/common/virtual_buffer.h b/src/common/virtual_buffer.h index 125cb42f0..078e61c77 100644 --- a/src/common/virtual_buffer.h +++ b/src/common/virtual_buffer.h | |||
| @@ -4,25 +4,44 @@ | |||
| 4 | 4 | ||
| 5 | #pragma once | 5 | #pragma once |
| 6 | 6 | ||
| 7 | #include "common/common_funcs.h" | 7 | #include <type_traits> |
| 8 | #include <utility> | ||
| 8 | 9 | ||
| 9 | namespace Common { | 10 | namespace Common { |
| 10 | 11 | ||
| 11 | void* AllocateMemoryPages(std::size_t size); | 12 | void* AllocateMemoryPages(std::size_t size) noexcept; |
| 12 | void FreeMemoryPages(void* base, std::size_t size); | 13 | void FreeMemoryPages(void* base, std::size_t size) noexcept; |
| 13 | 14 | ||
| 14 | template <typename T> | 15 | template <typename T> |
| 15 | class VirtualBuffer final : NonCopyable { | 16 | class VirtualBuffer final { |
| 16 | public: | 17 | public: |
| 18 | static_assert( | ||
| 19 | std::is_trivially_constructible_v<T>, | ||
| 20 | "T must be trivially constructible, as non-trivial constructors will not be executed " | ||
| 21 | "with the current allocator"); | ||
| 22 | |||
| 17 | constexpr VirtualBuffer() = default; | 23 | constexpr VirtualBuffer() = default; |
| 18 | explicit VirtualBuffer(std::size_t count) : alloc_size{count * sizeof(T)} { | 24 | explicit VirtualBuffer(std::size_t count) : alloc_size{count * sizeof(T)} { |
| 19 | base_ptr = reinterpret_cast<T*>(AllocateMemoryPages(alloc_size)); | 25 | base_ptr = reinterpret_cast<T*>(AllocateMemoryPages(alloc_size)); |
| 20 | } | 26 | } |
| 21 | 27 | ||
| 22 | ~VirtualBuffer() { | 28 | ~VirtualBuffer() noexcept { |
| 23 | FreeMemoryPages(base_ptr, alloc_size); | 29 | FreeMemoryPages(base_ptr, alloc_size); |
| 24 | } | 30 | } |
| 25 | 31 | ||
| 32 | VirtualBuffer(const VirtualBuffer&) = delete; | ||
| 33 | VirtualBuffer& operator=(const VirtualBuffer&) = delete; | ||
| 34 | |||
| 35 | VirtualBuffer(VirtualBuffer&& other) noexcept | ||
| 36 | : alloc_size{std::exchange(other.alloc_size, 0)}, base_ptr{std::exchange(other.base_ptr), | ||
| 37 | nullptr} {} | ||
| 38 | |||
| 39 | VirtualBuffer& operator=(VirtualBuffer&& other) noexcept { | ||
| 40 | alloc_size = std::exchange(other.alloc_size, 0); | ||
| 41 | base_ptr = std::exchange(other.base_ptr, nullptr); | ||
| 42 | return *this; | ||
| 43 | } | ||
| 44 | |||
| 26 | void resize(std::size_t count) { | 45 | void resize(std::size_t count) { |
| 27 | FreeMemoryPages(base_ptr, alloc_size); | 46 | FreeMemoryPages(base_ptr, alloc_size); |
| 28 | 47 | ||