summaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
Diffstat (limited to 'src/common')
-rw-r--r--src/common/CMakeLists.txt1
-rw-r--r--src/common/bit_cast.h22
-rw-r--r--src/common/logging/backend.cpp1
-rw-r--r--src/common/logging/log.h1
-rw-r--r--src/common/page_table.cpp2
-rw-r--r--src/common/page_table.h14
-rw-r--r--src/common/virtual_buffer.cpp4
-rw-r--r--src/common/virtual_buffer.h36
8 files changed, 68 insertions, 13 deletions
diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt
index 207c7a0a6..d20e6c3b5 100644
--- a/src/common/CMakeLists.txt
+++ b/src/common/CMakeLists.txt
@@ -102,6 +102,7 @@ add_library(common STATIC
102 atomic_ops.h 102 atomic_ops.h
103 detached_tasks.cpp 103 detached_tasks.cpp
104 detached_tasks.h 104 detached_tasks.h
105 bit_cast.h
105 bit_field.h 106 bit_field.h
106 bit_util.h 107 bit_util.h
107 cityhash.cpp 108 cityhash.cpp
diff --git a/src/common/bit_cast.h b/src/common/bit_cast.h
new file mode 100644
index 000000000..a32a063d1
--- /dev/null
+++ b/src/common/bit_cast.h
@@ -0,0 +1,22 @@
1// Copyright 2020 yuzu emulator team
2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included.
4
5#pragma once
6
7#include <cstring>
8#include <type_traits>
9
10namespace Common {
11
12template <typename To, typename From>
13[[nodiscard]] std::enable_if_t<sizeof(To) == sizeof(From) && std::is_trivially_copyable_v<From> &&
14 std::is_trivially_copyable_v<To>,
15 To>
16BitCast(const From& src) noexcept {
17 To dst;
18 std::memcpy(&dst, &src, sizeof(To));
19 return dst;
20}
21
22} // namespace Common
diff --git a/src/common/logging/backend.cpp b/src/common/logging/backend.cpp
index 90dfa22ca..7859344b9 100644
--- a/src/common/logging/backend.cpp
+++ b/src/common/logging/backend.cpp
@@ -222,6 +222,7 @@ void DebuggerBackend::Write(const Entry& entry) {
222 SUB(Service, NPNS) \ 222 SUB(Service, NPNS) \
223 SUB(Service, NS) \ 223 SUB(Service, NS) \
224 SUB(Service, NVDRV) \ 224 SUB(Service, NVDRV) \
225 SUB(Service, OLSC) \
225 SUB(Service, PCIE) \ 226 SUB(Service, PCIE) \
226 SUB(Service, PCTL) \ 227 SUB(Service, PCTL) \
227 SUB(Service, PCV) \ 228 SUB(Service, PCV) \
diff --git a/src/common/logging/log.h b/src/common/logging/log.h
index 13a4f1e30..835894918 100644
--- a/src/common/logging/log.h
+++ b/src/common/logging/log.h
@@ -95,6 +95,7 @@ enum class Class : ClassType {
95 Service_NPNS, ///< The NPNS service 95 Service_NPNS, ///< The NPNS service
96 Service_NS, ///< The NS services 96 Service_NS, ///< The NS services
97 Service_NVDRV, ///< The NVDRV (Nvidia driver) service 97 Service_NVDRV, ///< The NVDRV (Nvidia driver) service
98 Service_OLSC, ///< The OLSC service
98 Service_PCIE, ///< The PCIe service 99 Service_PCIE, ///< The PCIe service
99 Service_PCTL, ///< The PCTL (Parental control) service 100 Service_PCTL, ///< The PCTL (Parental control) service
100 Service_PCV, ///< The PCV service 101 Service_PCV, ///< The PCV service
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
9PageTable::PageTable() = default; 9PageTable::PageTable() = default;
10 10
11PageTable::~PageTable() = default; 11PageTable::~PageTable() noexcept = default;
12 12
13void PageTable::Resize(std::size_t address_space_width_in_bits, std::size_t page_size_in_bits, 13void 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 */
52struct PageTable { 50struct 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
14namespace Common { 14namespace Common {
15 15
16void* AllocateMemoryPages(std::size_t size) { 16void* 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
32void FreeMemoryPages(void* base, [[maybe_unused]] std::size_t size) { 32void 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..91d430036 100644
--- a/src/common/virtual_buffer.h
+++ b/src/common/virtual_buffer.h
@@ -4,29 +4,53 @@
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
9namespace Common { 10namespace Common {
10 11
11void* AllocateMemoryPages(std::size_t size); 12void* AllocateMemoryPages(std::size_t size) noexcept;
12void FreeMemoryPages(void* base, std::size_t size); 13void FreeMemoryPages(void* base, std::size_t size) noexcept;
13 14
14template <typename T> 15template <typename T>
15class VirtualBuffer final : NonCopyable { 16class VirtualBuffer final {
16public: 17public:
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) {
46 const auto new_size = count * sizeof(T);
47 if (new_size == alloc_size) {
48 return;
49 }
50
27 FreeMemoryPages(base_ptr, alloc_size); 51 FreeMemoryPages(base_ptr, alloc_size);
28 52
29 alloc_size = count * sizeof(T); 53 alloc_size = new_size;
30 base_ptr = reinterpret_cast<T*>(AllocateMemoryPages(alloc_size)); 54 base_ptr = reinterpret_cast<T*>(AllocateMemoryPages(alloc_size));
31 } 55 }
32 56