aboutsummaryrefslogtreecommitdiff
path: root/arch/x86_64/include
diff options
context:
space:
mode:
authorMatteo Gmür <matteo.gmuer1@ost.ch>2024-10-16 14:10:32 +0000
committerMatteo Gmür <matteo.gmuer1@ost.ch>2024-10-16 14:10:32 +0000
commit35e25757b6cffbcb2ff1eea8daf4c5f1ca421cb0 (patch)
treecbdf50536e8a2b2143bf067947d562b6d8407438 /arch/x86_64/include
parent934822e48a7c5a3e65ed74261ce5ab4315595f64 (diff)
downloadteachos-35e25757b6cffbcb2ff1eea8daf4c5f1ca421cb0.tar.xz
teachos-35e25757b6cffbcb2ff1eea8daf4c5f1ca421cb0.zip
Adjust table accessing code to make it safer (always out of bounds checked)
Diffstat (limited to 'arch/x86_64/include')
-rw-r--r--arch/x86_64/include/arch/memory/multiboot.hpp4
-rw-r--r--arch/x86_64/include/arch/memory/paging.hpp43
2 files changed, 31 insertions, 16 deletions
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
@@ -111,40 +111,53 @@ 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<const page_table *>;
+
+ /**
+ * @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<std::size_t>;
+ 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<const page_table *>;
+ 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<std::size_t>;
- private:
entry entries[PAGE_TABLE_ENTRY_COUNT];
- page_table const * p4 = reinterpret_cast<page_table *>(0xfffffffffffff000);
+ page_table const * p4;
};
} // namespace teachos::arch::memory