aboutsummaryrefslogtreecommitdiff
path: root/arch/x86_64/src/memory/heap
diff options
context:
space:
mode:
Diffstat (limited to 'arch/x86_64/src/memory/heap')
-rw-r--r--arch/x86_64/src/memory/heap/global_heap_allocator.cpp54
1 files changed, 37 insertions, 17 deletions
diff --git a/arch/x86_64/src/memory/heap/global_heap_allocator.cpp b/arch/x86_64/src/memory/heap/global_heap_allocator.cpp
index c1ca160..51f6261 100644
--- a/arch/x86_64/src/memory/heap/global_heap_allocator.cpp
+++ b/arch/x86_64/src/memory/heap/global_heap_allocator.cpp
@@ -6,15 +6,20 @@
namespace teachos::arch::memory::heap
{
- heap_allocator * global_heap_allocator::allocator_instance = nullptr;
+ heap_allocator * global_heap_allocator::kernel_allocator_instance = nullptr;
+ heap_allocator * global_heap_allocator::user_allocator_instance = nullptr;
- auto global_heap_allocator::allocate(std::size_t size) -> void * { return get().allocate(size); }
+ auto global_heap_allocator::kmalloc(std::size_t size) -> void * { return kernel().allocate(size); }
- auto global_heap_allocator::deallocate(void * pointer) noexcept -> void { get().deallocate(pointer); }
+ auto global_heap_allocator::kfree(void * pointer) noexcept -> void { kernel().deallocate(pointer); }
+
+ auto global_heap_allocator::malloc(std::size_t size) -> void * { return user().allocate(size); }
+
+ auto global_heap_allocator::free(void * pointer) noexcept -> void { user().deallocate(pointer); }
auto global_heap_allocator::register_heap_allocator(heap_allocator_type new_type) -> void
{
- exception_handling::assert(allocator_instance == nullptr,
+ exception_handling::assert(kernel_allocator_instance == nullptr,
"Calling register_heap_allocator_type can only be done once.");
switch (new_type)
@@ -23,56 +28,71 @@ namespace teachos::arch::memory::heap
// Nothing to do
break;
case heap_allocator_type::BUMP: {
- static bump_allocator allocator{HEAP_START, HEAP_START + HEAP_SIZE};
- allocator_instance = &allocator;
+ static bump_allocator kernel_allocator{KERNEL_HEAP_START, KERNEL_HEAP_START + KERNEL_HEAP_SIZE};
+ kernel_allocator_instance = &kernel_allocator;
+
+ static bump_allocator user_allocator{USER_HEAP_START, USER_HEAP_START + USER_HEAP_SIZE};
+ user_allocator_instance = &user_allocator;
break;
}
case heap_allocator_type::LINKED_LIST: {
- static linked_list_allocator allocator{HEAP_START, HEAP_START + HEAP_SIZE};
- allocator_instance = &allocator;
+ static linked_list_allocator kernel_allocator{KERNEL_HEAP_START, KERNEL_HEAP_START + KERNEL_HEAP_SIZE};
+ kernel_allocator_instance = &kernel_allocator;
+
+ static linked_list_allocator user_allocator{USER_HEAP_START, USER_HEAP_START + USER_HEAP_SIZE};
+ user_allocator_instance = &user_allocator;
break;
}
}
}
- auto global_heap_allocator::get() -> heap_allocator &
+ auto global_heap_allocator::kernel() -> heap_allocator &
+ {
+ exception_handling::assert(kernel_allocator_instance != nullptr,
+ "Attempted to allocate or deallocate using the global_heap_allocator before "
+ "register_heap_allocation_type was called.");
+
+ return *kernel_allocator_instance;
+ }
+
+ auto global_heap_allocator::user() -> heap_allocator &
{
- exception_handling::assert(allocator_instance != nullptr,
+ exception_handling::assert(user_allocator_instance != nullptr,
"Attempted to allocate or deallocate using the global_heap_allocator before "
"register_heap_allocation_type was called.");
- return *allocator_instance;
+ return *user_allocator_instance;
}
} // namespace teachos::arch::memory::heap
auto operator new(std::size_t size) -> void *
{
- return teachos::arch::memory::heap::global_heap_allocator::allocate(size);
+ return teachos::arch::memory::heap::global_heap_allocator::kmalloc(size);
}
auto operator delete(void * pointer) noexcept -> void
{
- teachos::arch::memory::heap::global_heap_allocator::deallocate(pointer);
+ teachos::arch::memory::heap::global_heap_allocator::kfree(pointer);
}
auto operator delete(void * pointer, std::size_t size) noexcept -> void
{
(void)size;
- teachos::arch::memory::heap::global_heap_allocator::deallocate(pointer);
+ teachos::arch::memory::heap::global_heap_allocator::kfree(pointer);
}
auto operator new[](std::size_t size) -> void *
{
- return teachos::arch::memory::heap::global_heap_allocator::allocate(size);
+ return teachos::arch::memory::heap::global_heap_allocator::kmalloc(size);
}
auto operator delete[](void * pointer) noexcept -> void
{
- teachos::arch::memory::heap::global_heap_allocator::deallocate(pointer);
+ teachos::arch::memory::heap::global_heap_allocator::kfree(pointer);
}
auto operator delete[](void * pointer, std::size_t size) noexcept -> void
{
(void)size;
- teachos::arch::memory::heap::global_heap_allocator::deallocate(pointer);
+ teachos::arch::memory::heap::global_heap_allocator::kfree(pointer);
}