From 35e25757b6cffbcb2ff1eea8daf4c5f1ca421cb0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matteo=20Gm=C3=BCr?= Date: Wed, 16 Oct 2024 14:10:32 +0000 Subject: Adjust table accessing code to make it safer (always out of bounds checked) --- arch/x86_64/include/arch/memory/multiboot.hpp | 4 ++- arch/x86_64/include/arch/memory/paging.hpp | 43 +++++++++++++++++---------- 2 files changed, 31 insertions(+), 16 deletions(-) (limited to 'arch/x86_64/include') diff --git a/arch/x86_64/include/arch/memory/multiboot.hpp b/arch/x86_64/include/arch/memory/multiboot.hpp index 9a753fa..9cca8bc 100644 --- a/arch/x86_64/include/arch/memory/multiboot.hpp +++ b/arch/x86_64/include/arch/memory/multiboot.hpp @@ -194,7 +194,9 @@ namespace teachos::arch::memory auto operator==(elf_section_flags const & other) const -> bool = default; private: - std::bitset<64U> flags; + std::bitset<64U> flags; ///< Underlying bitset used to read the flags from. Bits 21 - 28 are reserved for operating + ///< system specific semantics and bits 29 - 32 are reserved for processor specific + ///< semantics. Bits 33 - 64 are unused for compatability with ELF32. }; /** diff --git a/arch/x86_64/include/arch/memory/paging.hpp b/arch/x86_64/include/arch/memory/paging.hpp index 4092d18..d55835e 100644 --- a/arch/x86_64/include/arch/memory/paging.hpp +++ b/arch/x86_64/include/arch/memory/paging.hpp @@ -110,41 +110,54 @@ namespace teachos::arch::memory */ struct page_table { + /** + * @brief Constructor. + */ + page_table(); + /** * @brief Set every entry of the page to unused */ auto zero_entries() -> void; /** - * @brief Find and return the next table address + * @brief Convert the address of a page_table into a page_table * - * The next table address is only valid if the corresponding entry is present - * and does not create a huge page + * @param index Index of the entry we want to access + * @return An optional of the next page table or null + */ + auto next_table(std::size_t index) const -> std::optional; + + /** + * @brief Index operator overload to access specific mutable entry directy * - * @param index - * @return An optional of the address of the next page table or null + * @param index Index of the entry we want to access and change + * @return Entry at the given table index */ - auto next_table_address(std::size_t index) const -> std::optional; + auto operator[](std::size_t index) -> entry &; /** - * @brief Convert the address of a page_table into a page_table + * @brief Index operator overload to access specific immutable entry directy * - * @param index - * @return An optional of the next page table or null + * @param index Index of the entry we want to access and only read + * @return Entry at the given table index */ - auto next_table(std::size_t index) const -> std::optional; + auto operator[](std::size_t index) const -> entry const &; + private: /** - * @brief Index operator overload to access specific entries directy + * @brief Find and return the next table address + * + * The next table address is only valid if the corresponding entry is present + * and does not create a huge page * * @param index - * @return The address of the accessed entry + * @return An optional of the address of the next page table or null */ - entry & operator[](std::size_t index); + auto next_table_address(std::size_t index) const -> std::optional; - private: entry entries[PAGE_TABLE_ENTRY_COUNT]; - page_table const * p4 = reinterpret_cast(0xfffffffffffff000); + page_table const * p4; }; } // namespace teachos::arch::memory -- cgit v1.2.3