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/include | |
| parent | 31796138b1c85e7b3236055b6d93d568e1fe8a81 (diff) | |
| download | teachos-d3e4df4dd4ee117e247f78a86746bf178787bc8f.tar.xz teachos-d3e4df4dd4ee117e247f78a86746bf178787bc8f.zip | |
Start with linked list alloc and dealloc
Diffstat (limited to 'arch/x86_64/include')
| -rw-r--r-- | arch/x86_64/include/arch/memory/heap/linked_list_allocator.hpp | 30 |
1 files changed, 30 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 |
