diff options
| author | Matteo Gmür <matteo.gmuer1@ost.ch> | 2025-02-20 10:41:11 +0000 |
|---|---|---|
| committer | Matteo Gmür <matteo.gmuer1@ost.ch> | 2025-02-20 10:41:11 +0000 |
| commit | 6c4ce82c3f9cc920bcde74fc10fdfd39b477b9f4 (patch) | |
| tree | 03465649821a73db88489e4b1a0adc1f298bf64c /arch | |
| parent | bff6c39a8d4571cd5c41e3926d5fc1428916f32c (diff) | |
| download | teachos-6c4ce82c3f9cc920bcde74fc10fdfd39b477b9f4.tar.xz teachos-6c4ce82c3f9cc920bcde74fc10fdfd39b477b9f4.zip | |
Fix compilation issues
Diffstat (limited to 'arch')
| -rw-r--r-- | arch/x86_64/CMakeLists.txt | 1 | ||||
| -rw-r--r-- | arch/x86_64/include/arch/memory/heap/global_heap_allocator.hpp | 33 | ||||
| -rw-r--r-- | arch/x86_64/src/kernel/main.cpp | 28 | ||||
| -rw-r--r-- | arch/x86_64/src/memory/heap/global_heap_allocator.cpp | 40 |
4 files changed, 48 insertions, 54 deletions
diff --git a/arch/x86_64/CMakeLists.txt b/arch/x86_64/CMakeLists.txt index c5624d8..9665846 100644 --- a/arch/x86_64/CMakeLists.txt +++ b/arch/x86_64/CMakeLists.txt @@ -59,6 +59,7 @@ target_sources("_memory" PRIVATE "src/memory/heap/bump_allocator.cpp" "src/memory/heap/memory_block.cpp" "src/memory/heap/linked_list_allocator.cpp" + "src/memory/heap/global_heap_allocator.cpp" "src/shared/mutex.cpp" ) 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 index b7b2073..871f4f8 100644 --- a/arch/x86_64/include/arch/memory/heap/global_heap_allocator.hpp +++ b/arch/x86_64/include/arch/memory/heap/global_heap_allocator.hpp @@ -10,37 +10,22 @@ namespace teachos::arch::memory::heap static auto allocate(std::size_t size) -> void *; static auto deallocate(void * pointer, std::size_t size) -> void; + + private: + static linked_list_allocator allocator; }; } // 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 new(std::size_t size) -> void *; -auto operator delete(void * pointer) noexcept -> void -{ - teachos::arch::memory::heap::global_heap_allocator::deallocate(pointer, 64); -} +auto operator delete(void * pointer) noexcept -> void; -auto operator delete(void * pointer, std::size_t size) noexcept -> void -{ - teachos::arch::memory::heap::global_heap_allocator::deallocate(pointer, size); -} +auto operator delete(void * pointer, std::size_t size) noexcept -> void; -auto operator new[](std::size_t size) -> void * -{ - return teachos::arch::memory::heap::global_heap_allocator::allocate(size); -} +auto operator new[](std::size_t size) -> void *; -auto operator delete[](void * pointer) noexcept -> void -{ - teachos::arch::memory::heap::global_heap_allocator::deallocate(pointer, 64); -} +auto operator delete[](void * pointer) noexcept -> void; -auto operator delete[](void * pointer, std::size_t size) noexcept -> void -{ - teachos::arch::memory::heap::global_heap_allocator::deallocate(pointer, size); -} +auto operator delete[](void * pointer, std::size_t size) noexcept -> void; #endif // TEACHOS_ARCH_X86_64_MEMORY_HEAP_GLOBAL_HEAP_ALLOCATOR_HPP diff --git a/arch/x86_64/src/kernel/main.cpp b/arch/x86_64/src/kernel/main.cpp index f88ea41..ed9fc58 100644 --- a/arch/x86_64/src/kernel/main.cpp +++ b/arch/x86_64/src/kernel/main.cpp @@ -22,12 +22,8 @@ namespace teachos::arch::kernel auto heap_test() -> void { - /*memory::heap::linked_list_allocator heap_allocator{memory::heap::HEAP_START, - memory::heap::HEAP_START + memory::heap::HEAP_SIZE}; - auto test = heap_allocator.allocate(1024); - auto test2 = new (test) memory::multiboot::memory_information{}; - auto test3 = new (static_cast<void *>(static_cast<memory::multiboot::memory_information *>(test) + 1)) - memory::multiboot::memory_information{}; + auto test2 = new memory::multiboot::memory_information{}; + auto test3 = new memory::multiboot::memory_information{}; auto test4 = *test2; auto test5 = *test3; test4.kernel_end = 5000; @@ -42,24 +38,8 @@ namespace teachos::arch::kernel test2->kernel_end = 2000; test2->kernel_start = 1000; test2->multiboot_start = 2000; - heap_allocator.deallocate(test, 1024); - - auto test9 = heap_allocator.allocate(1024); - auto test10 = heap_allocator.allocate(1024); - auto test11 = heap_allocator.allocate(1024); - heap_allocator.deallocate(test9, 1024); - auto test12 = heap_allocator.allocate(1024); - auto test13 = heap_allocator.allocate(1024); - heap_allocator.deallocate(test11, 1024); - heap_allocator.deallocate(test10, 1024); - heap_allocator.deallocate(test13, 1024); - heap_allocator.deallocate(test12, 1024);*/ - - int * test = new int(); - - if (test == nullptr) - { - } + delete test2; + delete test3; } auto main() -> void 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 6c31de0..11848ed 100644 --- a/arch/x86_64/src/memory/heap/global_heap_allocator.cpp +++ b/arch/x86_64/src/memory/heap/global_heap_allocator.cpp @@ -5,14 +5,42 @@ namespace teachos::arch::memory::heap { - auto global_heap_allocator::allocate(std::size_t size) -> void * - { - static linked_list_allocator allocator{HEAP_START, HEAP_START + HEAP_SIZE}; - return allocator.allocate(size); - } + static global_heap_allocator::allocator = linked_list_allocator{HEAP_START, HEAP_START + HEAP_SIZE}; + + auto global_heap_allocator::allocate(std::size_t size) -> void * { return allocator.allocate(size); } auto global_heap_allocator::deallocate(void * pointer, std::size_t size) -> void { - // allocator.deallocate(pointer, size); + allocator.deallocate(pointer, size); } } // 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); +} |
