summaryrefslogtreecommitdiff
path: root/src/common/host_memory.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/common/host_memory.h')
-rw-r--r--src/common/host_memory.h70
1 files changed, 70 insertions, 0 deletions
diff --git a/src/common/host_memory.h b/src/common/host_memory.h
new file mode 100644
index 000000000..9b8326d0f
--- /dev/null
+++ b/src/common/host_memory.h
@@ -0,0 +1,70 @@
1// Copyright 2019 yuzu Emulator Project
2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included.
4
5#pragma once
6
7#include <memory>
8#include "common/common_types.h"
9#include "common/virtual_buffer.h"
10
11namespace Common {
12
13/**
14 * A low level linear memory buffer, which supports multiple mappings
15 * Its purpose is to rebuild a given sparse memory layout, including mirrors.
16 */
17class HostMemory {
18public:
19 explicit HostMemory(size_t backing_size_, size_t virtual_size_);
20 ~HostMemory();
21
22 /**
23 * Copy constructors. They shall return a copy of the buffer without the mappings.
24 * TODO: Implement them with COW if needed.
25 */
26 HostMemory(const HostMemory& other) = delete;
27 HostMemory& operator=(const HostMemory& other) = delete;
28
29 /**
30 * Move constructors. They will move the buffer and the mappings to the new object.
31 */
32 HostMemory(HostMemory&& other) noexcept;
33 HostMemory& operator=(HostMemory&& other) noexcept;
34
35 void Map(size_t virtual_offset, size_t host_offset, size_t length);
36
37 void Unmap(size_t virtual_offset, size_t length);
38
39 void Protect(size_t virtual_offset, size_t length, bool read, bool write);
40
41 [[nodiscard]] u8* BackingBasePointer() noexcept {
42 return backing_base;
43 }
44 [[nodiscard]] const u8* BackingBasePointer() const noexcept {
45 return backing_base;
46 }
47
48 [[nodiscard]] u8* VirtualBasePointer() noexcept {
49 return virtual_base;
50 }
51 [[nodiscard]] const u8* VirtualBasePointer() const noexcept {
52 return virtual_base;
53 }
54
55private:
56 size_t backing_size{};
57 size_t virtual_size{};
58
59 // Low level handler for the platform dependent memory routines
60 class Impl;
61 std::unique_ptr<Impl> impl;
62 u8* backing_base{};
63 u8* virtual_base{};
64 size_t virtual_base_offset{};
65
66 // Fallback if fastmem is not supported on this platform
67 std::unique_ptr<Common::VirtualBuffer<u8>> fallback_buffer;
68};
69
70} // namespace Common