aboutsummaryrefslogtreecommitdiff
path: root/arch/x86_64/src/memory
diff options
context:
space:
mode:
authorFabian Imhof <fabian.imhof@ost.ch>2024-12-01 13:34:46 +0000
committerFabian Imhof <fabian.imhof@ost.ch>2024-12-01 13:34:46 +0000
commit9072c2a277c0da298b977cf4fb3dbebb5481abd0 (patch)
treee3c4fdf75e3cb73a0cc2d966c7179b371612d77f /arch/x86_64/src/memory
parent0cf972394e99dfa69fbaf2ec9f4c718fd36bbc3e (diff)
downloadteachos-9072c2a277c0da298b977cf4fb3dbebb5481abd0.tar.xz
teachos-9072c2a277c0da298b977cf4fb3dbebb5481abd0.zip
implement clear_memory_block_header
Diffstat (limited to 'arch/x86_64/src/memory')
-rw-r--r--arch/x86_64/src/memory/heap/linked_list_allocator.cpp22
1 files changed, 15 insertions, 7 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 63a762e..07d7e5e 100644
--- a/arch/x86_64/src/memory/heap/linked_list_allocator.cpp
+++ b/arch/x86_64/src/memory/heap/linked_list_allocator.cpp
@@ -3,6 +3,8 @@
#include "arch/exception_handling/assert.hpp"
#include "arch/exception_handling/panic.hpp"
+#include <string.h>
+
#include <algorithm>
namespace teachos::arch::memory::heap
@@ -14,7 +16,7 @@ namespace teachos::arch::memory::heap
{
auto const heap_size = heap_end - heap_start;
exception_handling::assert(
- heap_size < min_allocatable_size(),
+ 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);
@@ -22,7 +24,7 @@ namespace teachos::arch::memory::heap
auto linked_list_allocator::allocate(std::size_t size) -> void *
{
- exception_handling::assert(size < min_allocatable_size(),
+ exception_handling::assert(size > min_allocatable_size(),
"[Linked List Allocator] Allocated memory cannot be smaller than 16 bytes");
auto & previous = first;
@@ -34,7 +36,8 @@ namespace teachos::arch::memory::heap
{
return split_free_memory_block(current, size);
}
- else if (current->size >= size)
+
+ if (current->size >= size)
{
if (previous != current)
{
@@ -42,10 +45,10 @@ namespace teachos::arch::memory::heap
}
else
{
- current = current->next;
+ first = current->next;
}
- delete current;
+ clear_memory_block_header(current);
return static_cast<void *>(current);
}
@@ -57,7 +60,7 @@ namespace teachos::arch::memory::heap
auto linked_list_allocator::deallocate(void * pointer, std::size_t size) -> void
{
- exception_handling::assert(size < min_allocatable_size(),
+ exception_handling::assert(size > min_allocatable_size(),
"[Linked List Allocator] Allocated memory cannot be smaller than 16 bytes");
auto const start_address = reinterpret_cast<std::size_t>(pointer);
@@ -118,7 +121,7 @@ namespace teachos::arch::memory::heap
block_size += current_block->size;
next_block = current_block->next;
- delete current_block;
+ clear_memory_block_header(current_block);
}
// If the block we want to deallocate is behind another free block and we can therefore combine both into one.
@@ -137,4 +140,9 @@ 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