From d80ecf29baada6242c5181adaec0d1500707cad0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matteo=20Gm=C3=BCr?= Date: Fri, 9 May 2025 12:00:23 +0000 Subject: Move necessary code into user text --- arch/x86_64/src/memory/heap/global_heap_allocator.cpp | 3 +++ arch/x86_64/src/memory/heap/user_heap_allocator.cpp | 5 ++++- 2 files changed, 7 insertions(+), 1 deletion(-) (limited to 'arch/x86_64/src/memory/heap') 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 -- cgit v1.2.3