From bff6c39a8d4571cd5c41e3926d5fc1428916f32c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matteo=20Gm=C3=BCr?= Date: Thu, 20 Feb 2025 10:07:03 +0000 Subject: Create global heap allocator attempt --- .../arch/memory/heap/global_heap_allocator.hpp | 46 ++++++++++++++++++++++ .../arch/memory/heap/new_delete_override.hpp | 27 ------------- 2 files changed, 46 insertions(+), 27 deletions(-) create mode 100644 arch/x86_64/include/arch/memory/heap/global_heap_allocator.hpp delete mode 100644 arch/x86_64/include/arch/memory/heap/new_delete_override.hpp (limited to 'arch/x86_64/include') diff --git a/arch/x86_64/include/arch/memory/heap/global_heap_allocator.hpp b/arch/x86_64/include/arch/memory/heap/global_heap_allocator.hpp new file mode 100644 index 0000000..b7b2073 --- /dev/null +++ b/arch/x86_64/include/arch/memory/heap/global_heap_allocator.hpp @@ -0,0 +1,46 @@ +#ifndef TEACHOS_ARCH_X86_64_MEMORY_HEAP_GLOBAL_HEAP_ALLOCATOR_HPP +#define TEACHOS_ARCH_X86_64_MEMORY_HEAP_GLOBAL_HEAP_ALLOCATOR_HPP + +#include "arch/memory/heap/linked_list_allocator.hpp" + +namespace teachos::arch::memory::heap +{ + struct global_heap_allocator + { + static auto allocate(std::size_t size) -> void *; + + static auto deallocate(void * pointer, std::size_t size) -> void; + }; +} // namespace teachos::arch::memory::heap + +auto operator new(std::size_t size) -> void * +{ + return teachos::arch::memory::heap::global_heap_allocator::allocate(size); +} + +auto operator delete(void * pointer) noexcept -> void +{ + teachos::arch::memory::heap::global_heap_allocator::deallocate(pointer, 64); +} + +auto operator delete(void * pointer, std::size_t size) noexcept -> void +{ + teachos::arch::memory::heap::global_heap_allocator::deallocate(pointer, size); +} + +auto operator new[](std::size_t size) -> void * +{ + return teachos::arch::memory::heap::global_heap_allocator::allocate(size); +} + +auto operator delete[](void * pointer) noexcept -> void +{ + teachos::arch::memory::heap::global_heap_allocator::deallocate(pointer, 64); +} + +auto operator delete[](void * pointer, std::size_t size) noexcept -> void +{ + teachos::arch::memory::heap::global_heap_allocator::deallocate(pointer, size); +} + +#endif // TEACHOS_ARCH_X86_64_MEMORY_HEAP_GLOBAL_HEAP_ALLOCATOR_HPP diff --git a/arch/x86_64/include/arch/memory/heap/new_delete_override.hpp b/arch/x86_64/include/arch/memory/heap/new_delete_override.hpp deleted file mode 100644 index c51c737..0000000 --- a/arch/x86_64/include/arch/memory/heap/new_delete_override.hpp +++ /dev/null @@ -1,27 +0,0 @@ -#ifndef TEACHOS_ARCH_X86_64_MEMORY_NEW_DELETE_OVERRIDE_CONCEPT_HPP -#define TEACHOS_ARCH_X86_64_MEMORY_NEW_DELETE_OVERRIDE_CONCEPT_HPP - -#include "linked_list_allocator.hpp" -#include - -void * operator new(std::size_t size) { teachos::arch::memory::heap::kernel_heap.allocate(size); } - -void operator delete(void * pointer) noexcept { teachos::arch::memory::heap::kernel_heap.deallocate(pointer, 64); } - -void operator delete(void * pointer, std::size_t size) noexcept -{ - teachos::arch::memory::heap::kernel_heap.deallocate(pointer, size); -} - -void * operator new[](std::size_t size) { teachos::arch::memory::heap::kernel_heap.allocate(size); } - -void operator delete[](void * pointer) noexcept -{ - // NOPE -} - -void operator delete[](void * pointer, std::size_t size) noexcept -{ - teachos::arch::memory::heap::kernel_heap.deallocate(pointer, size); -} -#endif // TEACHOS_ARCH_X86_64_KERNEL_NEW_DELETE_OVERRIDE_HPP \ No newline at end of file -- cgit v1.2.3