From 9438c9203b7be20147b990ff05e1d99190d18928 Mon Sep 17 00:00:00 2001 From: Fabian Imhof Date: Thu, 20 Feb 2025 09:38:28 +0000 Subject: added new and delete override --- arch/x86_64/src/kernel/main.cpp | 37 ++++++++++++++++--------------------- 1 file changed, 16 insertions(+), 21 deletions(-) (limited to 'arch/x86_64/src/kernel/main.cpp') diff --git a/arch/x86_64/src/kernel/main.cpp b/arch/x86_64/src/kernel/main.cpp index 681f960..a41132d 100644 --- a/arch/x86_64/src/kernel/main.cpp +++ b/arch/x86_64/src/kernel/main.cpp @@ -22,38 +22,33 @@ 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(static_cast(test) + 1)) - memory::multiboot::memory_information{}; + memory::heap::linked_list_allocator kernel_heap(memory::heap::HEAP_START, + memory::heap::HEAP_START + memory::heap::HEAP_SIZE); + + auto test2 = new memory::multiboot::memory_information{}; auto test4 = *test2; - auto test5 = *test3; test4.kernel_end = 5000; - test5.kernel_end = 3000; auto test6 = test4.kernel_end; - auto test7 = test5.kernel_end; auto test8 = memory::multiboot::read_multiboot2(); - if (test6 && test7 && test8.kernel_end) + if (test6 && test8.kernel_end) { video::vga::text::write("Heap test successful", video::vga::text::common_attributes::green_on_black); } test2->kernel_end = 2000; test2->kernel_start = 1000; test2->multiboot_start = 2000; - heap_allocator.deallocate(test, 1024); + delete test2; - 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); + // 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); } auto main() -> void -- cgit v1.2.3 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/x86_64/src/kernel/main.cpp | 45 +++++++++++++++++++++++++---------------- 1 file changed, 28 insertions(+), 17 deletions(-) (limited to 'arch/x86_64/src/kernel/main.cpp') diff --git a/arch/x86_64/src/kernel/main.cpp b/arch/x86_64/src/kernel/main.cpp index a41132d..f88ea41 100644 --- a/arch/x86_64/src/kernel/main.cpp +++ b/arch/x86_64/src/kernel/main.cpp @@ -2,7 +2,7 @@ #include "arch/memory/heap/bump_allocator.hpp" #include "arch/memory/heap/concept.hpp" -#include "arch/memory/heap/linked_list_allocator.hpp" +#include "arch/memory/heap/global_heap_allocator.hpp" #include "arch/memory/main.hpp" #include "arch/memory/multiboot/reader.hpp" #include "arch/video/vga/text.hpp" @@ -22,33 +22,44 @@ namespace teachos::arch::kernel auto heap_test() -> void { - memory::heap::linked_list_allocator kernel_heap(memory::heap::HEAP_START, - memory::heap::HEAP_START + memory::heap::HEAP_SIZE); - - auto test2 = new memory::multiboot::memory_information{}; + /*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(static_cast(test) + 1)) + memory::multiboot::memory_information{}; auto test4 = *test2; + auto test5 = *test3; test4.kernel_end = 5000; + test5.kernel_end = 3000; auto test6 = test4.kernel_end; + auto test7 = test5.kernel_end; auto test8 = memory::multiboot::read_multiboot2(); - if (test6 && test8.kernel_end) + if (test6 && test7 && test8.kernel_end) { video::vga::text::write("Heap test successful", video::vga::text::common_attributes::green_on_black); } test2->kernel_end = 2000; test2->kernel_start = 1000; test2->multiboot_start = 2000; - delete test2; + 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(); - // 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); + if (test == nullptr) + { + } } auto main() -> void -- cgit v1.2.3 From 6c4ce82c3f9cc920bcde74fc10fdfd39b477b9f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matteo=20Gm=C3=BCr?= Date: Thu, 20 Feb 2025 10:41:11 +0000 Subject: Fix compilation issues --- arch/x86_64/src/kernel/main.cpp | 28 ++++------------------------ 1 file changed, 4 insertions(+), 24 deletions(-) (limited to 'arch/x86_64/src/kernel/main.cpp') 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(static_cast(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 -- cgit v1.2.3 From 00fd8cf8f72d6c5c3d6150f3ec833ded9e34b2b1 Mon Sep 17 00:00:00 2001 From: Fabian Imhof Date: Thu, 20 Feb 2025 16:05:19 +0000 Subject: add heap_allocator base class --- arch/x86_64/src/kernel/main.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'arch/x86_64/src/kernel/main.cpp') diff --git a/arch/x86_64/src/kernel/main.cpp b/arch/x86_64/src/kernel/main.cpp index ed9fc58..7c03644 100644 --- a/arch/x86_64/src/kernel/main.cpp +++ b/arch/x86_64/src/kernel/main.cpp @@ -50,8 +50,10 @@ namespace teachos::arch::kernel video::vga::text::newline(); memory::initialize_memory_management(); - // stack_overflow_test(0); + + memory::heap::global_heap_allocator::register_heap_allocator_type(memory::heap::heap_allocator_type::LINKED_LIST); + heap_test(); } } // namespace teachos::arch::kernel -- cgit v1.2.3 From 405b5b1018397bff48e32c75e10a6b3b58bb6a20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matteo=20Gm=C3=BCr?= Date: Fri, 21 Feb 2025 14:13:39 +0000 Subject: Update factory method code --- arch/x86_64/src/kernel/main.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'arch/x86_64/src/kernel/main.cpp') diff --git a/arch/x86_64/src/kernel/main.cpp b/arch/x86_64/src/kernel/main.cpp index 7c03644..f102a3a 100644 --- a/arch/x86_64/src/kernel/main.cpp +++ b/arch/x86_64/src/kernel/main.cpp @@ -1,7 +1,6 @@ #include "arch/kernel/main.hpp" #include "arch/memory/heap/bump_allocator.hpp" -#include "arch/memory/heap/concept.hpp" #include "arch/memory/heap/global_heap_allocator.hpp" #include "arch/memory/main.hpp" #include "arch/memory/multiboot/reader.hpp" -- cgit v1.2.3 From 93cc8aa1c0e4ba991f0503c609702e1c63a240c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matteo=20Gm=C3=BCr?= Date: Fri, 21 Feb 2025 15:23:51 +0000 Subject: Add documentation to new components --- arch/x86_64/src/kernel/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'arch/x86_64/src/kernel/main.cpp') diff --git a/arch/x86_64/src/kernel/main.cpp b/arch/x86_64/src/kernel/main.cpp index f102a3a..f3518a8 100644 --- a/arch/x86_64/src/kernel/main.cpp +++ b/arch/x86_64/src/kernel/main.cpp @@ -51,7 +51,7 @@ namespace teachos::arch::kernel memory::initialize_memory_management(); // stack_overflow_test(0); - memory::heap::global_heap_allocator::register_heap_allocator_type(memory::heap::heap_allocator_type::LINKED_LIST); + memory::heap::global_heap_allocator::register_heap_allocator(memory::heap::heap_allocator_type::LINKED_LIST); heap_test(); } -- cgit v1.2.3 From fcc586a846562e024c1cd77042634494cf380bd8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matteo=20Gm=C3=BCr?= Date: Sun, 23 Feb 2025 10:27:46 +0000 Subject: Adjust linked list allocator to allow for deallocation without passing size parameter and with arbitrary size --- arch/x86_64/src/kernel/main.cpp | 3 +++ 1 file changed, 3 insertions(+) (limited to 'arch/x86_64/src/kernel/main.cpp') diff --git a/arch/x86_64/src/kernel/main.cpp b/arch/x86_64/src/kernel/main.cpp index f3518a8..472aed5 100644 --- a/arch/x86_64/src/kernel/main.cpp +++ b/arch/x86_64/src/kernel/main.cpp @@ -39,6 +39,9 @@ namespace teachos::arch::kernel test2->multiboot_start = 2000; delete test2; delete test3; + + auto test9 = new int(50); + delete test9; } auto main() -> void -- cgit v1.2.3