aboutsummaryrefslogtreecommitdiff
path: root/arch
diff options
context:
space:
mode:
Diffstat (limited to 'arch')
-rw-r--r--arch/x86_64/include/arch/memory/heap/linked_list_allocator.hpp30
-rw-r--r--arch/x86_64/src/memory/heap/linked_list_allocator.cpp27
2 files changed, 57 insertions, 0 deletions
diff --git a/arch/x86_64/include/arch/memory/heap/linked_list_allocator.hpp b/arch/x86_64/include/arch/memory/heap/linked_list_allocator.hpp
index a742018..da7fc37 100644
--- a/arch/x86_64/include/arch/memory/heap/linked_list_allocator.hpp
+++ b/arch/x86_64/include/arch/memory/heap/linked_list_allocator.hpp
@@ -22,12 +22,42 @@ namespace teachos::arch::memory::heap
linked_list_allocator(std::size_t heap_start, std::size_t heap_end);
/**
+ * @brief Allocates the specified amount of memory in the heap.
+ *
+ * @param size Amount of memory to allocate.
+ * @return Address of the first byte to the allocated area
+ */
+ auto allocate(std::size_t size) -> void *;
+
+ /**
+ * @brief Deallocates heap memory at the specified location.
+ *
+ * @note Simply does nothing, because this allocator leaks all memory.
+ *
+ * @param pointer Pointer to the location which should be deallocated.
+ * @param size Size of the underlying memory area we want to deallocate.
+ */
+ auto deallocate(uint8_t * pointer, std::size_t size) -> void;
+
+ private:
+ /**
* @brief Returns the smallest allocatable block of heap memory.
*
* @return Smallest allocatable block of heap memory.
*/
auto constexpr min_allocatable_size() -> std::size_t { return sizeof(memory_hole); }
+ /**
+ * @brief Splits the given hole into two, where the latter block keeps beeing free and the first part will be used
+ * for the allocation.
+ *
+ * @param current_hole Hole we want to split.
+ * @param new_hole New hole created by the split.
+ *
+ * @return Address of the hole we just split.
+ */
+ auto split_hole(memory_hole & current_hole, memory_hole *& new_hole) -> void *;
+
std::size_t heap_start; ///< Start of the allocatable heap area
std::size_t heap_end; ///< End of the allocatable heap area
memory_hole first; ///< First free entry in our memory
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 b0f011b..006d9c7 100644
--- a/arch/x86_64/src/memory/heap/linked_list_allocator.cpp
+++ b/arch/x86_64/src/memory/heap/linked_list_allocator.cpp
@@ -2,6 +2,8 @@
#include "arch/exception_handling/assert.hpp"
+#include <algorithm>
+
namespace teachos::arch::memory::heap
{
linked_list_allocator::linked_list_allocator(std::size_t heap_start, std::size_t heap_end)
@@ -13,4 +15,29 @@ namespace teachos::arch::memory::heap
"[Memory Hole List] Total heap size can not be smaller than minimum of 16 bytes to hold "
"atleast one memory hole entry");
}
+
+ auto linked_list_allocator::allocate(std::size_t size) -> void *
+ {
+ if (first.next == nullptr || size)
+ {
+ }
+ return nullptr;
+ }
+
+ auto linked_list_allocator::deallocate(uint8_t * pointer, std::size_t size) -> void
+ {
+ auto const deallocate_size = std::max(size, min_allocatable_size());
+ if (pointer || deallocate_size)
+ {
+ }
+ }
+
+ auto split_hole(memory_hole & current_hole, memory_hole *& new_hole) -> void *
+ {
+ if (new_hole)
+ {
+ }
+ return static_cast<void *>(&current_hole);
+ }
+
} // namespace teachos::arch::memory::heap