From 29e067867e7a437d12351b481024d4bab431b202 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matteo=20Gm=C3=BCr?= Date: Mon, 12 May 2025 13:51:12 +0000 Subject: Fix crashes because of are frame allocator copy --- arch/x86_64/src/memory/heap/memory_block.cpp | 5 ++--- arch/x86_64/src/memory/heap/user_heap_allocator.cpp | 13 ++++--------- 2 files changed, 6 insertions(+), 12 deletions(-) (limited to 'arch/x86_64/src/memory/heap') diff --git a/arch/x86_64/src/memory/heap/memory_block.cpp b/arch/x86_64/src/memory/heap/memory_block.cpp index 6ee675a..bc97bd6 100644 --- a/arch/x86_64/src/memory/heap/memory_block.cpp +++ b/arch/x86_64/src/memory/heap/memory_block.cpp @@ -6,11 +6,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(this), 0, size); + memset(static_cast(this), 0U, size); this->size = size; this->next = next; } - memory_block::~memory_block() { /*memset(static_cast(this), 0, sizeof(memory_block));*/ } + memory_block::~memory_block() { memset(static_cast(this), 0U, 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 9cb6c17..f3fe1c2 100644 --- a/arch/x86_64/src/memory/heap/user_heap_allocator.cpp +++ b/arch/x86_64/src/memory/heap/user_heap_allocator.cpp @@ -104,16 +104,11 @@ namespace teachos::arch::memory::heap auto user_heap_allocator::expand_heap_if_full() -> memory_block * { - context_switching::syscall::arguments args{}; - auto const result = context_switching::syscall::syscall(context_switching::syscall::type::EXPAND_HEAP, args); + auto const result = context_switching::syscall::syscall(context_switching::syscall::type::EXPAND_HEAP); - if (!result.error_code) - { - uint64_t const heap_start = result.values.arg_0; - uint64_t const heap_size = result.values.arg_1; - return new (reinterpret_cast(heap_start)) memory_block(heap_size, nullptr); - } - return nullptr; + uint64_t const heap_start = result.values.arg_0; + uint64_t const heap_size = result.values.arg_1; + return !result.error_code ? new (reinterpret_cast(heap_start)) memory_block(heap_size, nullptr) : nullptr; } auto user_heap_allocator::remove_free_memory_block(memory_block * previous_block, memory_block * current_block) -- cgit v1.2.3