diff options
| author | Matteo Gmür <matteo.gmuer1@ost.ch> | 2024-11-28 13:53:01 +0000 |
|---|---|---|
| committer | Matteo Gmür <matteo.gmuer1@ost.ch> | 2024-11-28 13:53:01 +0000 |
| commit | d3e4df4dd4ee117e247f78a86746bf178787bc8f (patch) | |
| tree | c09041ee2513dfd79c44414e2327f66d19e0b1bb /arch/x86_64 | |
| parent | 31796138b1c85e7b3236055b6d93d568e1fe8a81 (diff) | |
| download | teachos-d3e4df4dd4ee117e247f78a86746bf178787bc8f.tar.xz teachos-d3e4df4dd4ee117e247f78a86746bf178787bc8f.zip | |
Start with linked list alloc and dealloc
Diffstat (limited to 'arch/x86_64')
| -rw-r--r-- | arch/x86_64/include/arch/memory/heap/linked_list_allocator.hpp | 30 | ||||
| -rw-r--r-- | arch/x86_64/src/memory/heap/linked_list_allocator.cpp | 27 |
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 *>(¤t_hole); + } + } // namespace teachos::arch::memory::heap |
