diff options
| author | Felix Morgner <felix.morgner@ost.ch> | 2026-09-10 08:53:57 +0200 |
|---|---|---|
| committer | Felix Morgner <felix.morgner@ost.ch> | 2026-09-10 08:53:57 +0200 |
| commit | 5449acc193f96d2ffaeb224aad5cea16bf753cdb (patch) | |
| tree | 2a939bc19d7f7f365800e2d275d3cc85a7bcbe54 /arch/x86_64/kapi | |
| parent | da6cf94fc47f38cab580e9df1c6e6a46894aded5 (diff) | |
| download | kernel-5449acc193f96d2ffaeb224aad5cea16bf753cdb.tar.xz kernel-5449acc193f96d2ffaeb224aad5cea16bf753cdb.zip | |
x86_64: replace raw pointers with observer_ptr
Diffstat (limited to 'arch/x86_64/kapi')
| -rw-r--r-- | arch/x86_64/kapi/memory.cpp | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/arch/x86_64/kapi/memory.cpp b/arch/x86_64/kapi/memory.cpp index 03c5107c..307789cd 100644 --- a/arch/x86_64/kapi/memory.cpp +++ b/arch/x86_64/kapi/memory.cpp @@ -12,6 +12,7 @@ #include <kapi/boot.hpp> #include <kapi/system.hpp> +#include <kstd/memory.hpp> #include <kstd/print.hpp> #include <kstd/units.hpp> @@ -49,7 +50,7 @@ namespace kapi::memory } auto const & mbi = boot::bootstrap_information.mbi; - auto mbi_span = std::span{std::bit_cast<std::byte *>(mbi), static_cast<std::size_t>(mbi->size())}; + auto mbi_span = std::span{reinterpret_cast<std::byte const *>(mbi.get()), static_cast<std::size_t>(mbi->size())}; auto image_span = std::span{&arch::boot::_start_physical, &arch::boot::_end_physical}; return arch::memory::region_allocator::memory_information{ @@ -62,6 +63,9 @@ namespace kapi::memory auto establish_higher_half_direct_mapping() -> void { + // We can't use an observer_ptr here, since this first frame allocation is very likely to return frame number + // zero, which has a starting address of zero. observer_ptr will interpret this as being a nullptr and raise a + // panic on dereference. auto pml3_frame = kapi::memory::allocate_frame(); auto pml3 = static_cast<arch::memory::page_table *>(pml3_frame->start_address()); pml3->clear(); @@ -75,7 +79,7 @@ namespace kapi::memory }); auto current_cr3 = arch::cpu::cr3::read(); - auto pml4 = static_cast<arch::memory::page_table *>(current_cr3.address()); + auto pml4 = static_cast<kstd::observer_ptr<arch::memory::page_table>>(current_cr3.address()); (*pml4)[256].frame(*pml3_frame, arch::memory::page_table::entry::flags::present | arch::memory::page_table::entry::flags::writable | arch::memory::page_table::entry::flags::global); @@ -218,7 +222,7 @@ namespace kapi::memory system::panic("[ARCH:MEM] Failed to allocate new PML4!"); } auto new_pml4 = arch::memory::to_higher_half_pointer<arch::memory::page_table>(new_pml4_frame->start_address()); - std::construct_at(new_pml4); + std::construct_at(new_pml4.get()); higher_half_mapper.emplace(new_pml4); set_page_mapper(*higher_half_mapper); @@ -229,7 +233,7 @@ namespace kapi::memory remap_bootloader_modules(*higher_half_mapper); auto current_cr3 = arch::cpu::cr3::read(); - auto old_pml4 = static_cast<arch::memory::page_table *>(current_cr3.address()); + auto old_pml4 = static_cast<kstd::observer_ptr<arch::memory::page_table>>(current_cr3.address()); (*new_pml4)[256] = (*old_pml4)[256]; kstd::println("[ARCH:MEM] Switching to new paging hierarchy."); |
