From 05fe50cefb12a7333a320a3d101dccdd13b8034a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matteo=20Gm=C3=BCr?= Date: Tue, 3 Dec 2024 09:13:53 +0000 Subject: Clear old memory in contructor --- arch/x86_64/src/memory/heap/linked_list_allocator.cpp | 14 ++------------ arch/x86_64/src/memory/heap/memory_block.cpp | 10 +++++++--- 2 files changed, 9 insertions(+), 15 deletions(-) (limited to 'arch/x86_64/src') 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 d0bf8e6..e5bae21 100644 --- a/arch/x86_64/src/memory/heap/linked_list_allocator.cpp +++ b/arch/x86_64/src/memory/heap/linked_list_allocator.cpp @@ -3,10 +3,6 @@ #include "arch/exception_handling/assert.hpp" #include "arch/exception_handling/panic.hpp" -#include - -#include - namespace teachos::arch::memory::heap { linked_list_allocator::linked_list_allocator(std::size_t heap_start, std::size_t heap_end) @@ -112,7 +108,7 @@ namespace teachos::arch::memory::heap { previous_block->next = new_block; } - clear_memory_block_header(current_block); + current_block->~memory_block(); return reinterpret_cast(start_address); } @@ -134,8 +130,7 @@ namespace teachos::arch::memory::heap { block_size += current_block->size; next_block = current_block->next; - - clear_memory_block_header(current_block); + current_block->~memory_block(); } // If the block we want to deallocate is behind another free block and we can therefore combine both into one. @@ -170,9 +165,4 @@ namespace teachos::arch::memory::heap previous_block->next = new_block; } - auto linked_list_allocator::clear_memory_block_header(void * pointer) -> void - { - memset(pointer, 0, min_allocatable_size()); - } - } // namespace teachos::arch::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 b68dd6d..446cd96 100644 --- a/arch/x86_64/src/memory/heap/memory_block.cpp +++ b/arch/x86_64/src/memory/heap/memory_block.cpp @@ -1,11 +1,15 @@ #include "arch/memory/heap/memory_block.hpp" +#include + namespace teachos::arch::memory::heap { memory_block::memory_block(std::size_t size, memory_block * next) - : size(size) - , next(next) { - // Nothing to do + memset(static_cast(this), 0, size); + this->size = size; + this->next = next; } + + memory_block::~memory_block() { memset(static_cast(this), 0, sizeof(memory_block)); } } // namespace teachos::arch::memory::heap -- cgit v1.2.3