From 5449acc193f96d2ffaeb224aad5cea16bf753cdb Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Thu, 10 Sep 2026 08:53:57 +0200 Subject: x86_64: replace raw pointers with observer_ptr --- arch/x86_64/kapi/memory.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'arch/x86_64/kapi') 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 #include +#include #include #include @@ -49,7 +50,7 @@ namespace kapi::memory } auto const & mbi = boot::bootstrap_information.mbi; - auto mbi_span = std::span{std::bit_cast(mbi), static_cast(mbi->size())}; + auto mbi_span = std::span{reinterpret_cast(mbi.get()), static_cast(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(pml3_frame->start_address()); pml3->clear(); @@ -75,7 +79,7 @@ namespace kapi::memory }); auto current_cr3 = arch::cpu::cr3::read(); - auto pml4 = static_cast(current_cr3.address()); + auto pml4 = static_cast>(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(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(current_cr3.address()); + auto old_pml4 = static_cast>(current_cr3.address()); (*new_pml4)[256] = (*old_pml4)[256]; kstd::println("[ARCH:MEM] Switching to new paging hierarchy."); -- cgit v1.2.3