aboutsummaryrefslogtreecommitdiff
path: root/arch/x86_64/pre/src/memory/heap
diff options
context:
space:
mode:
authorFelix Morgner <felix.morgner@ost.ch>2025-10-29 15:01:43 +0100
committerFelix Morgner <felix.morgner@ost.ch>2025-10-29 15:01:43 +0100
commitb157e2c472d8bd67ac1656404a6a6ee821260f4b (patch)
tree9c4ebaee21c9ad3521f86c543dc1f29906305baa /arch/x86_64/pre/src/memory/heap
parentc2b0bdfe3b725166f16c742cdaca7969052df382 (diff)
downloadkernel-b157e2c472d8bd67ac1656404a6a6ee821260f4b.tar.xz
kernel-b157e2c472d8bd67ac1656404a6a6ee821260f4b.zip
chore: reformat source code
Diffstat (limited to 'arch/x86_64/pre/src/memory/heap')
-rw-r--r--arch/x86_64/pre/src/memory/heap/global_heap_allocator.cpp33
-rw-r--r--arch/x86_64/pre/src/memory/heap/memory_block.cpp5
-rw-r--r--arch/x86_64/pre/src/memory/heap/user_heap_allocator.cpp4
3 files changed, 29 insertions, 13 deletions
diff --git a/arch/x86_64/pre/src/memory/heap/global_heap_allocator.cpp b/arch/x86_64/pre/src/memory/heap/global_heap_allocator.cpp
index 35cd623..709cda1 100644
--- a/arch/x86_64/pre/src/memory/heap/global_heap_allocator.cpp
+++ b/arch/x86_64/pre/src/memory/heap/global_heap_allocator.cpp
@@ -27,13 +27,25 @@ namespace teachos::arch::memory::heap
heap_allocator * global_heap_allocator::kernel_allocator_instance = nullptr;
user_heap_allocator * global_heap_allocator::user_allocator_instance = nullptr;
- auto global_heap_allocator::kmalloc(std::size_t size) -> void * { return kernel().allocate(size); }
+ auto global_heap_allocator::kmalloc(std::size_t size) -> void *
+ {
+ return kernel().allocate(size);
+ }
- auto global_heap_allocator::kfree(void * pointer) noexcept -> void { kernel().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::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::free(void * pointer) noexcept -> void
+ {
+ user().deallocate(pointer);
+ }
auto global_heap_allocator::register_heap_allocator(heap_allocator_type new_type) -> void
{
@@ -45,20 +57,21 @@ namespace teachos::arch::memory::heap
case heap_allocator_type::NONE:
// Nothing to do
break;
- case heap_allocator_type::BUMP: {
- static bump_allocator kernel_allocator{KERNEL_HEAP_START, KERNEL_HEAP_START + KERNEL_HEAP_SIZE};
+ case heap_allocator_type::BUMP:
+ {
+ bump_allocator static kernel_allocator{KERNEL_HEAP_START, KERNEL_HEAP_START + KERNEL_HEAP_SIZE};
kernel_allocator_instance = &kernel_allocator;
break;
}
- case heap_allocator_type::LINKED_LIST: {
- static linked_list_allocator kernel_allocator{KERNEL_HEAP_START, KERNEL_HEAP_START + KERNEL_HEAP_SIZE};
+ case heap_allocator_type::LINKED_LIST:
+ {
+ linked_list_allocator static kernel_allocator{KERNEL_HEAP_START, KERNEL_HEAP_START + KERNEL_HEAP_SIZE};
kernel_allocator_instance = &kernel_allocator;
break;
}
}
- [[gnu::section(".user_data")]]
- static user_heap_allocator user_allocator{};
+ [[gnu::section(".user_data")]] user_heap_allocator static user_allocator{};
user_allocator_instance = &user_allocator;
}
diff --git a/arch/x86_64/pre/src/memory/heap/memory_block.cpp b/arch/x86_64/pre/src/memory/heap/memory_block.cpp
index bc97bd6..4c07454 100644
--- a/arch/x86_64/pre/src/memory/heap/memory_block.cpp
+++ b/arch/x86_64/pre/src/memory/heap/memory_block.cpp
@@ -11,5 +11,8 @@ namespace teachos::arch::memory::heap
this->next = next;
}
- memory_block::~memory_block() { memset(static_cast<void *>(this), 0U, sizeof(memory_block)); }
+ memory_block::~memory_block()
+ {
+ memset(static_cast<void *>(this), 0U, sizeof(memory_block));
+ }
} // namespace teachos::arch::memory::heap
diff --git a/arch/x86_64/pre/src/memory/heap/user_heap_allocator.cpp b/arch/x86_64/pre/src/memory/heap/user_heap_allocator.cpp
index 427a68a..96de005 100644
--- a/arch/x86_64/pre/src/memory/heap/user_heap_allocator.cpp
+++ b/arch/x86_64/pre/src/memory/heap/user_heap_allocator.cpp
@@ -39,7 +39,7 @@ namespace teachos::arch::memory::heap
}
}
- char constexpr OUT_OF_MEMORY_ERROR_MESSAGE[] = "[Linked List Allocator] Out of memory";
+ constexpr char OUT_OF_MEMORY_ERROR_MESSAGE[] = "[Linked List Allocator] Out of memory";
context_switching::syscall::syscall(context_switching::syscall::type::ASSERT,
{false, reinterpret_cast<uint64_t>(&OUT_OF_MEMORY_ERROR_MESSAGE)});
return nullptr;
@@ -178,7 +178,7 @@ namespace teachos::arch::memory::heap
// Check if the block we want to deallocate is contained in the previous block, because if it is it can only mean
// that the block has already been deallocated and we therefore attempted a double free.
- char constexpr DOUBLE_FREE_ERROR_MESSAGE[] = "[Linked List Allocator] Attempted double free detected";
+ constexpr char DOUBLE_FREE_ERROR_MESSAGE[] = "[Linked List Allocator] Attempted double free detected";
context_switching::syscall::syscall(
context_switching::syscall::type::ASSERT,
{previous_block == nullptr ||