diff options
author | ReinUsesLisp <reinuseslisp@airmail.cc> | 2021-06-05 06:23:25 -0300 |
---|---|---|
committer | Markus Wick <markus@selfnet.de> | 2021-06-11 17:27:06 +0200 |
commit | a7837a3791562899bf5e0e98aef851a2f4aaf376 (patch) | |
tree | 85d764268addf120981442a6cf2fb8d5614b7768 /src/common/host_memory.h | |
parent | fbb170857fab65e67a423c7e60cd1d7dc72e0663 (diff) |
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 @@ +// Copyright 2019 yuzu Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#pragma once + +#include <memory> +#include "common/common_types.h" + +namespace Common { + +/** + * A low level linear memory buffer, which supports multiple mappings + * Its purpose is to rebuild a given sparse memory layout, including mirrors. + */ +class HostMemory { +public: + explicit HostMemory(size_t backing_size, size_t virtual_size); + ~HostMemory(); + + /** + * Copy constructors. They shall return a copy of the buffer without the mappings. + * TODO: Implement them with COW if needed. + */ + HostMemory(const HostMemory& other) = delete; + HostMemory& operator=(const HostMemory& other) = delete; + + /** + * Move constructors. They will move the buffer and the mappings to the new object. + */ + HostMemory(HostMemory&& other) noexcept; + HostMemory& operator=(HostMemory&& other) noexcept; + + void Map(size_t virtual_offset, size_t host_offset, size_t length); + + void Unmap(size_t virtual_offset, size_t length); + + void Protect(size_t virtual_offset, size_t length, bool read, bool write); + + [[nodiscard]] u8* BackingBasePointer() noexcept { + return backing_base; + } + [[nodiscard]] const u8* BackingBasePointer() const noexcept { + return backing_base; + } + + [[nodiscard]] u8* VirtualBasePointer() noexcept { + return virtual_base; + } + [[nodiscard]] const u8* VirtualBasePointer() const noexcept { + return virtual_base; + } + +private: + // Low level handler for the platform dependent memory routines + class Impl; + std::unique_ptr<Impl> impl; + u8* backing_base{}; + u8* virtual_base{}; +}; + +} // namespace Common |