diff options
| author | 2021-06-05 06:23:25 -0300 | |
|---|---|---|
| committer | 2021-06-11 17:27:06 +0200 | |
| commit | a7837a3791562899bf5e0e98aef851a2f4aaf376 (patch) | |
| tree | 85d764268addf120981442a6cf2fb8d5614b7768 /src/common/host_memory.h | |
| parent | Merge pull request #6450 from lat9nq/update-sdl (diff) | |
| download | yuzu-a7837a3791562899bf5e0e98aef851a2f4aaf376.tar.gz yuzu-a7837a3791562899bf5e0e98aef851a2f4aaf376.tar.xz yuzu-a7837a3791562899bf5e0e98aef851a2f4aaf376.zip | |
common/host_memory: Add interface and Windows implementation
Diffstat (limited to 'src/common/host_memory.h')
| -rw-r--r-- | src/common/host_memory.h | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/src/common/host_memory.h b/src/common/host_memory.h new file mode 100644 index 000000000..98005df7a --- /dev/null +++ b/src/common/host_memory.h | |||
| @@ -0,0 +1,62 @@ | |||
| 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 | |||
| 10 | namespace Common { | ||
| 11 | |||
| 12 | /** | ||
| 13 | * A low level linear memory buffer, which supports multiple mappings | ||
| 14 | * Its purpose is to rebuild a given sparse memory layout, including mirrors. | ||
| 15 | */ | ||
| 16 | class HostMemory { | ||
| 17 | public: | ||
| 18 | explicit HostMemory(size_t backing_size, size_t virtual_size); | ||
| 19 | ~HostMemory(); | ||
| 20 | |||
| 21 | /** | ||
| 22 | * Copy constructors. They shall return a copy of the buffer without the mappings. | ||
| 23 | * TODO: Implement them with COW if needed. | ||
| 24 | */ | ||
| 25 | HostMemory(const HostMemory& other) = delete; | ||
| 26 | HostMemory& operator=(const HostMemory& other) = delete; | ||
| 27 | |||
| 28 | /** | ||
| 29 | * Move constructors. They will move the buffer and the mappings to the new object. | ||
| 30 | */ | ||
| 31 | HostMemory(HostMemory&& other) noexcept; | ||
| 32 | HostMemory& operator=(HostMemory&& other) noexcept; | ||
| 33 | |||
| 34 | void Map(size_t virtual_offset, size_t host_offset, size_t length); | ||
| 35 | |||
| 36 | void Unmap(size_t virtual_offset, size_t length); | ||
| 37 | |||
| 38 | void Protect(size_t virtual_offset, size_t length, bool read, bool write); | ||
| 39 | |||
| 40 | [[nodiscard]] u8* BackingBasePointer() noexcept { | ||
| 41 | return backing_base; | ||
| 42 | } | ||
| 43 | [[nodiscard]] const u8* BackingBasePointer() const noexcept { | ||
| 44 | return backing_base; | ||
| 45 | } | ||
| 46 | |||
| 47 | [[nodiscard]] u8* VirtualBasePointer() noexcept { | ||
| 48 | return virtual_base; | ||
| 49 | } | ||
| 50 | [[nodiscard]] const u8* VirtualBasePointer() const noexcept { | ||
| 51 | return virtual_base; | ||
| 52 | } | ||
| 53 | |||
| 54 | private: | ||
| 55 | // Low level handler for the platform dependent memory routines | ||
| 56 | class Impl; | ||
| 57 | std::unique_ptr<Impl> impl; | ||
| 58 | u8* backing_base{}; | ||
| 59 | u8* virtual_base{}; | ||
| 60 | }; | ||
| 61 | |||
| 62 | } // namespace Common | ||