From c291e1ed629489c418049f6c4116433636717636 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matteo=20Gm=C3=BCr?= Date: Sun, 24 Nov 2024 13:51:12 +0000 Subject: Add comments and rename file --- arch/x86_64/src/memory/heap/allocator.cpp | 27 -------------------------- arch/x86_64/src/memory/heap/bump_allocator.cpp | 26 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 27 deletions(-) delete mode 100644 arch/x86_64/src/memory/heap/allocator.cpp create mode 100644 arch/x86_64/src/memory/heap/bump_allocator.cpp (limited to 'arch/x86_64/src/memory/heap') diff --git a/arch/x86_64/src/memory/heap/allocator.cpp b/arch/x86_64/src/memory/heap/allocator.cpp deleted file mode 100644 index bb61be4..0000000 --- a/arch/x86_64/src/memory/heap/allocator.cpp +++ /dev/null @@ -1,27 +0,0 @@ -#include "arch/memory/heap/allocator.hpp" - -#include "arch/exception_handling/assert.hpp" - -namespace teachos::arch::memory::heap -{ - auto bump_allocator::allocate(std::size_t size) -> void * - { - // Uses some sort of alignment orignally: - // https://github.com/phil-opp/blog_os/blob/7f6576c9dc34e360b81236c54c25c7827fd6a2df/src/memory/heap_allocator.rs#L24 - auto alloc_start = next; - auto alloc_end = next + size; - - arch::exception_handling::assert(alloc_end <= heap_end, "[Heap Allocator] Out of memory!"); - - next = alloc_end; - return reinterpret_cast(alloc_start); - } - - auto bump_allocator::deallocate(uint8_t * pointer) -> void - { - // Not implemented; leaking memory - if (pointer) - { - } - } -} // namespace teachos::arch::memory::heap \ No newline at end of file diff --git a/arch/x86_64/src/memory/heap/bump_allocator.cpp b/arch/x86_64/src/memory/heap/bump_allocator.cpp new file mode 100644 index 0000000..486ece8 --- /dev/null +++ b/arch/x86_64/src/memory/heap/bump_allocator.cpp @@ -0,0 +1,26 @@ +#include "arch/memory/heap/bump_allocator.hpp" + +#include "arch/exception_handling/assert.hpp" + +namespace teachos::arch::memory::heap +{ + auto bump_allocator::allocate(std::size_t size) -> void * + { + // Uses some sort of alignment orignally: + // https://github.com/phil-opp/blog_os/blob/7f6576c9dc34e360b81236c54c25c7827fd6a2df/src/memory/heap_allocator.rs#L24 + auto alloc_start = next; + auto alloc_end = next + size; + + arch::exception_handling::assert(alloc_end <= heap_end, "[Heap Allocator] Out of memory!"); + + next = alloc_end; + return reinterpret_cast(alloc_start); + } + + auto bump_allocator::deallocate(uint8_t * pointer, std::size_t size) -> void + { + if (pointer || size) + { + } + } +} // namespace teachos::arch::memory::heap \ No newline at end of file -- cgit v1.2.3