From 203355e51690073e571d4906d53f2494c3dad41b Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Mon, 1 Dec 2025 19:32:19 +0100 Subject: x86_64/memory: prepare scoped_mapping extraction --- .../include/x86_64/memory/scoped_mapping.hpp | 39 ++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 arch/x86_64/include/x86_64/memory/scoped_mapping.hpp (limited to 'arch/x86_64/include') diff --git a/arch/x86_64/include/x86_64/memory/scoped_mapping.hpp b/arch/x86_64/include/x86_64/memory/scoped_mapping.hpp new file mode 100644 index 0000000..1719e6b --- /dev/null +++ b/arch/x86_64/include/x86_64/memory/scoped_mapping.hpp @@ -0,0 +1,39 @@ +#ifndef TEACHOS_X86_64_SCOPED_MAPPING_HPP +#define TEACHOS_X86_64_SCOPED_MAPPING_HPP + +#include "kapi/memory.hpp" + +#include "x86_64/memory/page_table.hpp" + +namespace teachos::memory::x86_64 +{ + + struct scoped_mapping + { + scoped_mapping(scoped_mapping const &) = delete; + scoped_mapping(scoped_mapping &&); + scoped_mapping(linear_address address, frame_allocator & allocator); + + ~scoped_mapping(); + + auto operator=(scoped_mapping const &) -> scoped_mapping = delete; + auto operator=(scoped_mapping &&) -> scoped_mapping &; + + auto map(frame frame, page_table::entry::flags flags) -> std::byte *; + auto unmap() -> void; + + template + auto map_as(frame frame, page_table::entry::flags flags) -> DataType * + { + return std::bit_cast(map(frame, flags)); + } + + private: + linear_address m_address; + frame_allocator * m_allocator; + bool m_mapped; + }; + +} // namespace teachos::memory::x86_64 + +#endif \ No newline at end of file -- cgit v1.2.3