aboutsummaryrefslogtreecommitdiff
path: root/arch/x86_64/src/memory/main.cpp
diff options
context:
space:
mode:
authorFabian Imhof <fabian.imhof@ost.ch>2025-05-08 08:51:52 +0000
committerFabian Imhof <fabian.imhof@ost.ch>2025-05-08 08:51:52 +0000
commit0b62fdb3fe657d056a42d7567b67951ba3468738 (patch)
tree8d95b14bc044a3c729183c37893f010b8cdf4980 /arch/x86_64/src/memory/main.cpp
parentbe32189323ba8c46091d6deaf091cf41147426b4 (diff)
downloadteachos-0b62fdb3fe657d056a42d7567b67951ba3468738.tar.xz
teachos-0b62fdb3fe657d056a42d7567b67951ba3468738.zip
wip allocating heap memory in user mode
Diffstat (limited to 'arch/x86_64/src/memory/main.cpp')
-rw-r--r--arch/x86_64/src/memory/main.cpp18
1 files changed, 12 insertions, 6 deletions
diff --git a/arch/x86_64/src/memory/main.cpp b/arch/x86_64/src/memory/main.cpp
index 558fbce..4cdfa80 100644
--- a/arch/x86_64/src/memory/main.cpp
+++ b/arch/x86_64/src/memory/main.cpp
@@ -20,18 +20,23 @@ namespace teachos::arch::memory
}
template<allocator::FrameAllocator T>
- auto remap_heap(T & allocator, paging::active_page_table & active_table) -> void
+ auto remap_heap(T & allocator, paging::active_page_table & active_table, bool is_user_heap = false) -> void
{
- auto const start_page = paging::virtual_page::containing_address(heap::KERNEL_HEAP_START);
- auto const end_page =
- ++(paging::virtual_page::containing_address(heap::KERNEL_HEAP_START + heap::KERNEL_HEAP_SIZE - 1));
+ auto const heap_start = is_user_heap ? heap::USER_HEAP_START : heap::KERNEL_HEAP_START;
+ auto const heap_size = is_user_heap ? heap::USER_HEAP_SIZE : heap::KERNEL_HEAP_SIZE;
+
+ auto const start_page = paging::virtual_page::containing_address(heap_start);
+ auto const end_page = ++(paging::virtual_page::containing_address(heap_start + heap_size - 1));
paging::page_container::iterator const begin{start_page};
paging::page_container::iterator const end{end_page};
paging::page_container const pages{begin, end};
+ constexpr auto base_flags = paging::entry::WRITABLE;
+ auto const flags = is_user_heap ? base_flags | paging::entry::USER_ACCESSIBLE : base_flags;
+
for (auto const & page : pages)
{
- active_table.map_page_to_next_free_frame(allocator, page, paging::entry::WRITABLE);
+ active_table.map_page_to_next_free_frame(allocator, page, flags);
}
}
} // namespace
@@ -54,7 +59,8 @@ namespace teachos::arch::memory
video::vga::text::write("Kernel remapping successful", video::vga::text::common_attributes::green_on_black);
video::vga::text::newline();
- remap_heap(allocator, active_table);
+ remap_heap(allocator, active_table); // Remap kernel heap
+ remap_heap(allocator, active_table, true); // Remap user heap
video::vga::text::write("Heap remapping successful", video::vga::text::common_attributes::green_on_black);
video::vga::text::newline();
}