diff options
| author | Matteo Gmür <matteo.gmuer1@ost.ch> | 2024-10-26 07:37:50 +0000 |
|---|---|---|
| committer | Matteo Gmür <matteo.gmuer1@ost.ch> | 2024-10-26 07:37:50 +0000 |
| commit | e44a16e45a309aa96375a2215d0d2405cf467dae (patch) | |
| tree | d1f206dd004a31ad8b02f7c3cb7e7fcfabbe520a /arch | |
| parent | 873f8c52699c6d4e3d32e5df253ae8ec0266a501 (diff) | |
| download | teachos-e44a16e45a309aa96375a2215d0d2405cf467dae.tar.xz teachos-e44a16e45a309aa96375a2215d0d2405cf467dae.zip | |
Use construct at to zero memory before using it.
Diffstat (limited to 'arch')
| -rw-r--r-- | arch/x86_64/src/memory/paging/page_mapper.cpp | 11 | ||||
| -rw-r--r-- | arch/x86_64/src/memory/paging/page_table.cpp | 15 |
2 files changed, 13 insertions, 13 deletions
diff --git a/arch/x86_64/src/memory/paging/page_mapper.cpp b/arch/x86_64/src/memory/paging/page_mapper.cpp index 687bffd..cd77366 100644 --- a/arch/x86_64/src/memory/paging/page_mapper.cpp +++ b/arch/x86_64/src/memory/paging/page_mapper.cpp @@ -4,17 +4,10 @@ namespace teachos::arch::memory::paging { - namespace - { - constexpr size_t PAGE_TABLE_LEVEL_4_ADDRESS = 0xfffffffffffff000; - } // namespace - auto create_or_get() -> page_table_handle { - // Perhaps we need to access boot::page_map_level_4; so we do not crash when returning entry? - static page_table * const active_page = reinterpret_cast<page_table *>(PAGE_TABLE_LEVEL_4_ADDRESS); - // We can not save page_table_handle as a static variable directly, if we do the program will fail to link. - return page_table_handle{active_page, page_table_handle::LEVEL4}; + // TODO: As soon as linker error is fixed in toolchain make handle static and return that. + return page_table_handle{arch::boot::page_map_level_4, page_table_handle::LEVEL4}; } auto translate_page(virtual_page page) -> std::optional<allocator::physical_frame> diff --git a/arch/x86_64/src/memory/paging/page_table.cpp b/arch/x86_64/src/memory/paging/page_table.cpp index 1d7b8a0..2f97a80 100644 --- a/arch/x86_64/src/memory/paging/page_table.cpp +++ b/arch/x86_64/src/memory/paging/page_table.cpp @@ -1,6 +1,7 @@ #include "arch/memory/paging/page_table.hpp" #include <array> +#include <memory> namespace teachos::arch::memory::paging { @@ -10,6 +11,11 @@ namespace teachos::arch::memory::paging struct page_table { /** + * @brief Defaulted constructor. + */ + page_table() = default; + + /** * @brief Set every entry of the page to unused. */ auto zero_entries() -> void; @@ -46,9 +52,9 @@ namespace teachos::arch::memory::paging */ auto next_table_address(std::size_t table_index) -> std::optional<std::size_t>; - std::array<entry, PAGE_TABLE_ENTRY_COUNT> - entries{}; ///< Entries containing addresses to page tables of a level below or - ///< actual virtual addresses for the level 1 page table. + std::array<entry, PAGE_TABLE_ENTRY_COUNT> entries = + {}; ///< Entries containing addresses to page tables of a level below or + ///< actual virtual addresses for the level 1 page table. }; auto page_table::zero_entries() -> void @@ -67,7 +73,8 @@ namespace teachos::arch::memory::paging auto address = next_table_address(table_index); if (address) { - return reinterpret_cast<page_table *>(address.value()); + // TODO: Probably erases the data even if the page table already existed previously and had values. + return std::construct_at(reinterpret_cast<page_table *>(address.value())); } return std::nullopt; } |
