aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatteo Gmür <matteo.gmuer1@ost.ch>2025-05-09 12:00:23 +0000
committerMatteo Gmür <matteo.gmuer1@ost.ch>2025-05-09 12:00:23 +0000
commitd80ecf29baada6242c5181adaec0d1500707cad0 (patch)
tree096b96c2ac172a3556b7c213f20f232c357ce06d
parentd7205b75cda2caff078cea26ff1508f9daa5b4cc (diff)
downloadteachos-d80ecf29baada6242c5181adaec0d1500707cad0.tar.xz
teachos-d80ecf29baada6242c5181adaec0d1500707cad0.zip
Move necessary code into user text
-rw-r--r--arch/x86_64/include/arch/memory/heap/global_heap_allocator.hpp3
-rw-r--r--arch/x86_64/include/arch/memory/heap/user_heap_allocator.hpp2
-rw-r--r--arch/x86_64/include/arch/memory/paging/kernel_mapper.hpp8
-rw-r--r--arch/x86_64/scripts/kernel.ld5
-rw-r--r--arch/x86_64/src/memory/heap/global_heap_allocator.cpp3
-rw-r--r--arch/x86_64/src/memory/heap/user_heap_allocator.cpp5
6 files changed, 21 insertions, 5 deletions
diff --git a/arch/x86_64/include/arch/memory/heap/global_heap_allocator.hpp b/arch/x86_64/include/arch/memory/heap/global_heap_allocator.hpp
index 6fcab6f..b20a452 100644
--- a/arch/x86_64/include/arch/memory/heap/global_heap_allocator.hpp
+++ b/arch/x86_64/include/arch/memory/heap/global_heap_allocator.hpp
@@ -77,7 +77,8 @@ namespace teachos::arch::memory::heap
private:
static heap_allocator * kernel_allocator_instance; ///< Instance used to allocate and deallocate kernel heap memory
- [[gnu::section(".user_data")]] static user_heap_allocator *
+ [[gnu::section(".user_data")]]
+ static user_heap_allocator *
user_allocator_instance; ///< Instance used to allocate and deallocate user heap memory
/**
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 1dab047..9d00c19 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
@@ -28,6 +28,7 @@ namespace teachos::arch::memory::heap
// Nothing to do
}
+ [[gnu::section(".user_text")]]
auto allocate(std::size_t size) -> void *;
/**
@@ -35,6 +36,7 @@ namespace teachos::arch::memory::heap
*
* @note Simply does nothing, because this allocator leaks all memory
*/
+ [[gnu::section(".user_text")]]
auto deallocate(void * pointer) noexcept -> void;
private:
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 6459107..95d04f4 100644
--- a/arch/x86_64/include/arch/memory/paging/kernel_mapper.hpp
+++ b/arch/x86_64/include/arch/memory/paging/kernel_mapper.hpp
@@ -139,11 +139,13 @@ namespace teachos::arch::memory::paging
entry entry{section.flags};
// TODO: Why exactly are this section required or not required?
- // Required to be accesible in User Mode: .user_text (Contains the actuall code executed), .boot_bss (Contains
- // statically allocated variables), .boot_rodata (Contains constant data stored in ROM)
+ // Required to be accesible in User Mode: .user_text (Contains the actual code executed), .boot_bss (Contains
+ // statically allocated variables), .boot_rodata (Contains constant data stored in ROM), .user_data (Contains
+ // static user variables
// Not required: .text, .rodata, .ctors, .dtors, .bss, .data, .boot_data, .boot_text, .init
if (section.physical_address == 0x100000 || section.physical_address == 0x102000 ||
- section.physical_address == 0x217000)
+ section.physical_address == 0x217000 || section.physical_address == 0x21D000 ||
+ section.physical_address == 0x209000)
{
entry.set_user_accesible();
}
diff --git a/arch/x86_64/scripts/kernel.ld b/arch/x86_64/scripts/kernel.ld
index 239d026..88d90fe 100644
--- a/arch/x86_64/scripts/kernel.ld
+++ b/arch/x86_64/scripts/kernel.ld
@@ -128,6 +128,11 @@ SECTIONS
*(.data*)
}
+ .user_data ALIGN(4K) : AT (ADDR (.user_data))
+ {
+ *(.user_data*)
+ }
+
/***************************************************************************
* In accordance with the symbol definitions at the start, we generate some
* symbols to mark the end of our loaded image.
diff --git a/arch/x86_64/src/memory/heap/global_heap_allocator.cpp b/arch/x86_64/src/memory/heap/global_heap_allocator.cpp
index acba02d..23e2458 100644
--- a/arch/x86_64/src/memory/heap/global_heap_allocator.cpp
+++ b/arch/x86_64/src/memory/heap/global_heap_allocator.cpp
@@ -40,6 +40,7 @@ namespace teachos::arch::memory::heap
}
}
+ [[gnu::section(".user_data")]]
static user_heap_allocator user_allocator{USER_HEAP_START, USER_HEAP_START + USER_HEAP_SIZE};
user_allocator_instance = &user_allocator;
}
@@ -55,6 +56,8 @@ namespace teachos::arch::memory::heap
auto global_heap_allocator::user() -> user_heap_allocator &
{
+ // TODO: Assert Method does not exist in .user_text meaning this causes a Page Fault when accessed, Make it into a
+ // syscall instead
// exception_handling::assert(user_allocator_instance != nullptr,
// "Attempted to allocate or deallocate using the global_heap_allocator before "
// "register_heap_allocation_type was called.");
diff --git a/arch/x86_64/src/memory/heap/user_heap_allocator.cpp b/arch/x86_64/src/memory/heap/user_heap_allocator.cpp
index f09811d..eefcab5 100644
--- a/arch/x86_64/src/memory/heap/user_heap_allocator.cpp
+++ b/arch/x86_64/src/memory/heap/user_heap_allocator.cpp
@@ -25,7 +25,10 @@ namespace teachos::arch::memory::heap
auto user_heap_allocator::allocate(std::size_t size) -> void *
{
- // Reading the value only has to be done once, because compare_exchange_weak updates the value as well if the
+ // TODO: .load() crashes because it is only in the kernel .text section and not the user one? How would you fix
+ // Similarly assert cause a crash here it is easier though simply create a syscall for the assert method.
+
+ // that? Reading the value only has to be done once, because compare_exchange_weak updates the value as well if the
// exchange failed, becuase the value was not the expected one.
auto alloc_start = next.load(std::memory_order::relaxed);
// Repeat allocation until it succeeds, has to be done, because another allocator could overtake it at any time