aboutsummaryrefslogtreecommitdiff
path: root/arch/x86_64/src/memory
diff options
context:
space:
mode:
authorMatteo Gmür <matteo.gmuer1@ost.ch>2024-12-03 09:13:53 +0000
committerMatteo Gmür <matteo.gmuer1@ost.ch>2024-12-03 09:13:53 +0000
commit05fe50cefb12a7333a320a3d101dccdd13b8034a (patch)
treed8857629506a93536eee255cbc8cd303473a81f5 /arch/x86_64/src/memory
parent6dff0ff5bcdd63de4a68f9c361acd0bace39b5ca (diff)
downloadteachos-05fe50cefb12a7333a320a3d101dccdd13b8034a.tar.xz
teachos-05fe50cefb12a7333a320a3d101dccdd13b8034a.zip
Clear old memory in contructor
Diffstat (limited to 'arch/x86_64/src/memory')
-rw-r--r--arch/x86_64/src/memory/heap/linked_list_allocator.cpp14
-rw-r--r--arch/x86_64/src/memory/heap/memory_block.cpp10
2 files changed, 9 insertions, 15 deletions
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 <string.h>
-
-#include <algorithm>
-
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<void *>(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 <string.h>
+
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<void *>(this), 0, size);
+ this->size = size;
+ this->next = next;
}
+
+ memory_block::~memory_block() { memset(static_cast<void *>(this), 0, sizeof(memory_block)); }
} // namespace teachos::arch::memory::heap