diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/common/page_table.cpp | 2 | ||||
| -rw-r--r-- | src/common/page_table.h | 10 | ||||
| -rw-r--r-- | src/common/virtual_buffer.cpp | 4 | ||||
| -rw-r--r-- | src/common/virtual_buffer.h | 23 |
4 files changed, 30 insertions, 9 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 a5be7a668..9754fabf9 100644 --- a/src/common/page_table.h +++ b/src/common/page_table.h | |||
| @@ -4,6 +4,8 @@ | |||
| 4 | 4 | ||
| 5 | #pragma once | 5 | #pragma once |
| 6 | 6 | ||
| 7 | #include <tuple> | ||
| 8 | |||
| 7 | #include "common/common_types.h" | 9 | #include "common/common_types.h" |
| 8 | #include "common/memory_hook.h" | 10 | #include "common/memory_hook.h" |
| 9 | #include "common/virtual_buffer.h" | 11 | #include "common/virtual_buffer.h" |
| @@ -47,7 +49,13 @@ struct SpecialRegion { | |||
| 47 | */ | 49 | */ |
| 48 | struct PageTable { | 50 | struct PageTable { |
| 49 | PageTable(); | 51 | PageTable(); |
| 50 | ~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; | ||
| 51 | 59 | ||
| 52 | /** | 60 | /** |
| 53 | * 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 |
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..363913d45 100644 --- a/src/common/virtual_buffer.h +++ b/src/common/virtual_buffer.h | |||
| @@ -4,25 +4,38 @@ | |||
| 4 | 4 | ||
| 5 | #pragma once | 5 | #pragma once |
| 6 | 6 | ||
| 7 | #include "common/common_funcs.h" | 7 | #include <utility> |
| 8 | 8 | ||
| 9 | namespace Common { | 9 | namespace Common { |
| 10 | 10 | ||
| 11 | void* AllocateMemoryPages(std::size_t size); | 11 | void* AllocateMemoryPages(std::size_t size) noexcept; |
| 12 | void FreeMemoryPages(void* base, std::size_t size); | 12 | void FreeMemoryPages(void* base, std::size_t size) noexcept; |
| 13 | 13 | ||
| 14 | template <typename T> | 14 | template <typename T> |
| 15 | class VirtualBuffer final : NonCopyable { | 15 | class VirtualBuffer final { |
| 16 | public: | 16 | public: |
| 17 | constexpr VirtualBuffer() = default; | 17 | constexpr VirtualBuffer() = default; |
| 18 | explicit VirtualBuffer(std::size_t count) : alloc_size{count * sizeof(T)} { | 18 | explicit VirtualBuffer(std::size_t count) : alloc_size{count * sizeof(T)} { |
| 19 | base_ptr = reinterpret_cast<T*>(AllocateMemoryPages(alloc_size)); | 19 | base_ptr = reinterpret_cast<T*>(AllocateMemoryPages(alloc_size)); |
| 20 | } | 20 | } |
| 21 | 21 | ||
| 22 | ~VirtualBuffer() { | 22 | ~VirtualBuffer() noexcept { |
| 23 | FreeMemoryPages(base_ptr, alloc_size); | 23 | FreeMemoryPages(base_ptr, alloc_size); |
| 24 | } | 24 | } |
| 25 | 25 | ||
| 26 | VirtualBuffer(const VirtualBuffer&) = delete; | ||
| 27 | VirtualBuffer& operator=(const VirtualBuffer&) = delete; | ||
| 28 | |||
| 29 | VirtualBuffer(VirtualBuffer&& other) noexcept | ||
| 30 | : alloc_size{std::exchange(other.alloc_size, 0)}, base_ptr{std::exchange(other.base_ptr), | ||
| 31 | nullptr} {} | ||
| 32 | |||
| 33 | VirtualBuffer& operator=(VirtualBuffer&& other) noexcept { | ||
| 34 | alloc_size = std::exchange(other.alloc_size, 0); | ||
| 35 | base_ptr = std::exchange(other.base_ptr, nullptr); | ||
| 36 | return *this; | ||
| 37 | } | ||
| 38 | |||
| 26 | void resize(std::size_t count) { | 39 | void resize(std::size_t count) { |
| 27 | FreeMemoryPages(base_ptr, alloc_size); | 40 | FreeMemoryPages(base_ptr, alloc_size); |
| 28 | 41 | ||