diff options
Diffstat (limited to 'arch/x86_64/include')
| -rw-r--r-- | arch/x86_64/include/x86_64/memory/scoped_mapping.hpp | 39 |
1 files changed, 39 insertions, 0 deletions
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<typename DataType> + auto map_as(frame frame, page_table::entry::flags flags) -> DataType * + { + return std::bit_cast<DataType *>(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 |
