aboutsummaryrefslogtreecommitdiff
path: root/arch/x86_64/include
diff options
context:
space:
mode:
authorMatteo Gmür <matteo.gmuer1@ost.ch>2025-05-20 12:29:09 +0000
committerMatteo Gmür <matteo.gmuer1@ost.ch>2025-05-20 12:29:09 +0000
commit8a6a9a3a159ce1b960721eb921b8e8d81b15b718 (patch)
treee2d05240795ece00e6599c97b959c1696f66cb78 /arch/x86_64/include
parent8d39f3f67734bf39cada370c39243e6ef33bf4a0 (diff)
downloadteachos-8a6a9a3a159ce1b960721eb921b8e8d81b15b718.tar.xz
teachos-8a6a9a3a159ce1b960721eb921b8e8d81b15b718.zip
Improve syscalls and user heap allocator
Diffstat (limited to 'arch/x86_64/include')
-rw-r--r--arch/x86_64/include/arch/memory/heap/user_heap_allocator.hpp15
-rw-r--r--arch/x86_64/include/arch/memory/paging/kernel_mapper.hpp20
2 files changed, 23 insertions, 12 deletions
diff --git a/arch/x86_64/include/arch/memory/heap/user_heap_allocator.hpp b/arch/x86_64/include/arch/memory/heap/user_heap_allocator.hpp
index 42af23f..6b1b7bb 100644
--- a/arch/x86_64/include/arch/memory/heap/user_heap_allocator.hpp
+++ b/arch/x86_64/include/arch/memory/heap/user_heap_allocator.hpp
@@ -4,6 +4,8 @@
#include "arch/memory/heap/memory_block.hpp"
#include "arch/stl/mutex.hpp"
+#include <optional>
+
namespace teachos::arch::memory::heap
{
/**
@@ -47,6 +49,19 @@ namespace teachos::arch::memory::heap
[[gnu::section(".user_text")]] auto constexpr min_allocatable_size() -> std::size_t { return sizeof(memory_block); }
/**
+ * @brief Checks if the given memory block is big enough and if it is allocates into the current block.
+ *
+ * @note Adjusts the link of the previous memory block to the new smaller remaining block. If the allocation used
+ * the complete block instead the previous block will point to the next block of the current memroy block that was
+ * used for the allocation.
+ *
+ * @return Allocated usable memory area.
+ */
+ [[gnu::section(".user_text")]] auto
+ allocate_into_memory_block_if_big_enough(memory_block * current, memory_block * previous, std::size_t total_size)
+ -> std::optional<void *>;
+
+ /**
* @brief Special functionality fo the user heap allocator. Which will result in it being expanded by a syscall with
* addtionally 100 KiB, which are mapped into the page table. Will always work until there is no physical memory
* left.
diff --git a/arch/x86_64/include/arch/memory/paging/kernel_mapper.hpp b/arch/x86_64/include/arch/memory/paging/kernel_mapper.hpp
index 977b40d..b211b8b 100644
--- a/arch/x86_64/include/arch/memory/paging/kernel_mapper.hpp
+++ b/arch/x86_64/include/arch/memory/paging/kernel_mapper.hpp
@@ -124,6 +124,13 @@ namespace teachos::arch::memory::paging
auto map_elf_kernel_sections(active_page_table & active_table) -> void
{
exception_handling::assert(!mem_info.sections.empty(), "[Kernel Mapper] Kernel elf sections empty");
+ std::array<uint64_t, 6U> constexpr USER_SECTION_BASES = {
+ 0x102000, // .boot_bss (Contains statically allocated variables)
+ 0x209000, // .stl_text (Contains code for custom std implementations and standard library code)
+ 0x218000, // .user_text (Contains the actual user code executed)
+ 0x21F000, // .user_data (Contains static user variables)
+ };
+
for (auto const & section : mem_info.sections)
{
if (!section.flags.contains_flags(multiboot::elf_section_flags::OCCUPIES_MEMORY))
@@ -144,18 +151,7 @@ namespace teachos::arch::memory::paging
allocator::frame_container const frames{begin, end};
entry entry{section.flags};
- // Required to be accessible in User Mode:
- constexpr std::array<uint64_t, 6> user_section_bases = {
- 0x102000, // .boot_bss (Contains statically allocated variables)
- 0x209000, // .stl_text (Contains code for custom std implementations and standard library code)
- 0x218000, // .user_text (Contains the actual user code executed)
- 0x21E000, // .user_data (Contains static user variables)
-
- 0x20A000 // .text (Necessary, because symbols for standard library are placed there)
- };
-
- if (std::find(user_section_bases.begin(), user_section_bases.end(), section.physical_address) !=
- user_section_bases.end())
+ if (std::ranges::find(USER_SECTION_BASES, section.physical_address) != USER_SECTION_BASES.end())
{
entry.set_user_accessible();
}