aboutsummaryrefslogtreecommitdiff
path: root/arch/x86_64/src
diff options
context:
space:
mode:
authorMatteo Gmür <matteo.gmuer1@ost.ch>2025-05-12 08:50:12 +0000
committerMatteo Gmür <matteo.gmuer1@ost.ch>2025-05-12 08:50:12 +0000
commitee4c61f7313fedd23d01c69ea5036fa38ef6248a (patch)
treecacb52db9b5233794c6284d14ef9306a045f5d72 /arch/x86_64/src
parentef156dd6430855434b54275b22cd43ee3cedcfdc (diff)
downloadteachos-ee4c61f7313fedd23d01c69ea5036fa38ef6248a.tar.xz
teachos-ee4c61f7313fedd23d01c69ea5036fa38ef6248a.zip
Adjust user heap to lazy allocate heap
Diffstat (limited to 'arch/x86_64/src')
-rw-r--r--arch/x86_64/src/context_switching/syscall/syscall_handler.cpp10
-rw-r--r--arch/x86_64/src/memory/heap/global_heap_allocator.cpp2
-rw-r--r--arch/x86_64/src/memory/heap/linked_list_allocator.cpp4
-rw-r--r--arch/x86_64/src/memory/heap/memory_block.cpp4
-rw-r--r--arch/x86_64/src/memory/heap/user_heap_allocator.cpp14
-rw-r--r--arch/x86_64/src/memory/main.cpp4
6 files changed, 9 insertions, 29 deletions
diff --git a/arch/x86_64/src/context_switching/syscall/syscall_handler.cpp b/arch/x86_64/src/context_switching/syscall/syscall_handler.cpp
index 9ca03d9..7272e9e 100644
--- a/arch/x86_64/src/context_switching/syscall/syscall_handler.cpp
+++ b/arch/x86_64/src/context_switching/syscall/syscall_handler.cpp
@@ -21,11 +21,10 @@ namespace teachos::arch::context_switching::syscall
auto expand_user_heap() -> error
{
- // TODO: use actual addresses instead of this constant!
- memory::remap_heap(memory::heap::USER_HEAP_SIZE + memory::heap::USER_HEAP_SIZE, memory::heap::USER_HEAP_SIZE,
- memory::paging::entry::USER_ACCESSIBLE);
+ static auto current_heap_end = memory::heap::USER_HEAP_START;
+ memory::remap_heap(current_heap_end, memory::heap::USER_HEAP_SIZE, memory::paging::entry::USER_ACCESSIBLE);
- arguments args{};
+ arguments args{current_heap_end, memory::heap::USER_HEAP_SIZE};
asm volatile("mov %[input], %%rdi"
: /* no output from call */
: [input] "m"(args.arg_0)
@@ -34,7 +33,8 @@ namespace teachos::arch::context_switching::syscall
: /* no output from call */
: [input] "m"(args.arg_1)
: "memory");
- return error::OUT_OF_MEMORY;
+ current_heap_end += memory::heap::USER_HEAP_SIZE;
+ return error::OK;
}
} // namespace
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 23e2458..e6c268a 100644
--- a/arch/x86_64/src/memory/heap/global_heap_allocator.cpp
+++ b/arch/x86_64/src/memory/heap/global_heap_allocator.cpp
@@ -41,7 +41,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};
+ static user_heap_allocator user_allocator{};
user_allocator_instance = &user_allocator;
}
diff --git a/arch/x86_64/src/memory/heap/linked_list_allocator.cpp b/arch/x86_64/src/memory/heap/linked_list_allocator.cpp
index 5101ab2..63a6111 100644
--- a/arch/x86_64/src/memory/heap/linked_list_allocator.cpp
+++ b/arch/x86_64/src/memory/heap/linked_list_allocator.cpp
@@ -8,9 +8,7 @@
namespace teachos::arch::memory::heap
{
linked_list_allocator::linked_list_allocator(std::size_t heap_start, std::size_t heap_end)
- : heap_start(heap_start)
- , heap_end(heap_end)
- , first(nullptr)
+ : first(nullptr)
, mutex{stl::mutex{}}
{
auto const heap_size = heap_end - heap_start;
diff --git a/arch/x86_64/src/memory/heap/memory_block.cpp b/arch/x86_64/src/memory/heap/memory_block.cpp
index 9f1fea8..6ee675a 100644
--- a/arch/x86_64/src/memory/heap/memory_block.cpp
+++ b/arch/x86_64/src/memory/heap/memory_block.cpp
@@ -7,10 +7,10 @@ namespace teachos::arch::memory::heap
memory_block::memory_block(std::size_t size, memory_block * next)
{
// TODO: Figure out why this memset fails
- memset(static_cast<void *>(this), 0, size);
+ // memset(static_cast<void *>(this), 0, size);
this->size = size;
this->next = next;
}
- memory_block::~memory_block() { memset(static_cast<void *>(this), 0, sizeof(memory_block)); }
+ memory_block::~memory_block() { /*memset(static_cast<void *>(this), 0, sizeof(memory_block));*/ }
} // namespace teachos::arch::memory::heap
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 ce8b0fa..9cb6c17 100644
--- a/arch/x86_64/src/memory/heap/user_heap_allocator.cpp
+++ b/arch/x86_64/src/memory/heap/user_heap_allocator.cpp
@@ -8,20 +8,6 @@
namespace teachos::arch::memory::heap
{
- user_heap_allocator::user_heap_allocator(std::size_t heap_start, std::size_t heap_end)
- : heap_start(heap_start)
- , heap_end(heap_end)
- , first(nullptr)
- , mutex{stl::mutex{}}
- {
- auto const heap_size = heap_end - heap_start;
- exception_handling::assert(
- heap_size > min_allocatable_size(),
- "[Linked List Allocator] Total heap size can not be smaller than minimum of 16 bytes to hold "
- "atleast one memory hole entry");
- // first = new (reinterpret_cast<void *>(heap_start)) memory_block(heap_size, nullptr);
- }
-
auto user_heap_allocator::allocate(std::size_t size) -> void *
{
// Add size of size_t to the total allocated size, because we add a header that includes the size of the allocated
diff --git a/arch/x86_64/src/memory/main.cpp b/arch/x86_64/src/memory/main.cpp
index 595cb0d..5e671ac 100644
--- a/arch/x86_64/src/memory/main.cpp
+++ b/arch/x86_64/src/memory/main.cpp
@@ -69,11 +69,7 @@ namespace teachos::arch::memory
video::vga::text::write("Kernel remapping successful", video::vga::text::common_attributes::green_on_black);
video::vga::text::newline();
- // Remap kernel heap
remap_heap(heap::KERNEL_HEAP_START, heap::KERNEL_HEAP_SIZE);
- // Remap user heap
- remap_heap(heap::USER_HEAP_SIZE, heap::USER_HEAP_SIZE, paging::entry::USER_ACCESSIBLE);
-
video::vga::text::write("Heap remapping successful", video::vga::text::common_attributes::green_on_black);
video::vga::text::newline();
}