From db70018fc76800dd56b4421be797bffd00d7619d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matteo=20Gm=C3=BCr?= Date: Sun, 3 Nov 2024 13:52:22 +0000 Subject: Convert elf section flags to entry flags --- .../include/arch/memory/paging/kernel_mapper.hpp | 4 ++-- .../x86_64/include/arch/memory/paging/page_entry.hpp | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) (limited to 'arch/x86_64/include') diff --git a/arch/x86_64/include/arch/memory/paging/kernel_mapper.hpp b/arch/x86_64/include/arch/memory/paging/kernel_mapper.hpp index f30ca24..54ec682 100644 --- a/arch/x86_64/include/arch/memory/paging/kernel_mapper.hpp +++ b/arch/x86_64/include/arch/memory/paging/kernel_mapper.hpp @@ -116,11 +116,11 @@ namespace teachos::arch::memory::paging allocator::physical_frame_iterator const begin{start_frame}; allocator::physical_frame_iterator const end{end_frame}; frame_container frames{begin, end}; + entry entry{section.flags}; for (auto const & frame : frames) { - // TODO: Use actual elf section flags, convert from one to the other flag type. - active_table.identity_map(allocator, frame, entry::WRITABLE); + active_table.identity_map(allocator, frame, entry.get_flags()); } } } diff --git a/arch/x86_64/include/arch/memory/paging/page_entry.hpp b/arch/x86_64/include/arch/memory/paging/page_entry.hpp index 5959801..ab9659d 100644 --- a/arch/x86_64/include/arch/memory/paging/page_entry.hpp +++ b/arch/x86_64/include/arch/memory/paging/page_entry.hpp @@ -2,6 +2,7 @@ #define TEACHOS_ARCH_X86_64_MEMORY_PAGING_PAGE_ENTRY_HPP #include "arch/memory/allocator/physical_frame.hpp" +#include "arch/memory/multiboot/elf_symbols_section.hpp" #include #include @@ -47,6 +48,18 @@ namespace teachos::arch::memory::paging */ explicit entry(uint64_t flags); + /** + * @brief Converts the given elf section flags into the corresponding correct entry flags. + * + * @note Enables us to set the correct flags on a entry depending on which elf section it is contained in. For + * example entries of .text sections should be executable and read only or entries of .data sections should be + * writable but not executable. + * + * @param elf_flags Elf section flags we want to convert into entry flags. + * @return Entry that has the corresponding bit flags set. + */ + explicit entry(multiboot::elf_section_flags elf_flags); + /** * @brief Whether the current page is unused, meaning the underlying std::bitset is 0. * @@ -86,6 +99,13 @@ namespace teachos::arch::memory::paging */ auto contains_flags(std::bitset<64U> other) const -> bool; + /** + * @brief Extracts only the flags from the underlying entry and ignores all bits that contain the physical address. + * + * @return Extracted entry flags, without the physical address. + */ + auto get_flags() -> std::bitset<64U>; + private: std::bitset<64U> flags; ///< Underlying bitset used to read the flags from. Bits 9 - 11 and 52 - 62 can be ///< freely used for additional flags by the operating system. -- cgit v1.2.3