diff options
8 files changed, 14 insertions, 42 deletions
diff --git a/arch/x86_64/include/arch/memory/heap/linked_list_allocator.hpp b/arch/x86_64/include/arch/memory/heap/linked_list_allocator.hpp index 377533c..582b4af 100644 --- a/arch/x86_64/include/arch/memory/heap/linked_list_allocator.hpp +++ b/arch/x86_64/include/arch/memory/heap/linked_list_allocator.hpp @@ -111,10 +111,8 @@ namespace teachos::arch::memory::heap auto coalesce_free_memory_block(memory_block * previous_block, memory_block * current_block, void * pointer, std::size_t size) -> void; - std::size_t heap_start; ///< Start of the allocatable heap area. - std::size_t heap_end; ///< End of the allocatable heap area. - memory_block * first; ///< First free entry in our memory. - stl::mutex mutex; ///< Mutex to ensure only one thread calls allocate or deallocate at once. + memory_block * first; ///< First free entry in our memory. + stl::mutex mutex; ///< Mutex to ensure only one thread calls allocate or deallocate at once. }; } // namespace teachos::arch::memory::heap diff --git a/arch/x86_64/include/arch/memory/heap/user_heap_allocator.hpp b/arch/x86_64/include/arch/memory/heap/user_heap_allocator.hpp index cadec78..9c04718 100644 --- a/arch/x86_64/include/arch/memory/heap/user_heap_allocator.hpp +++ b/arch/x86_64/include/arch/memory/heap/user_heap_allocator.hpp @@ -14,12 +14,8 @@ namespace teachos::arch::memory::heap { /** * @brief Constructor. - * - * @param heap_start Start of the allocatable heap area - * @param heap_end End of the allocatable heap area (Start + Size) */ - [[gnu::section(".user_text")]] - user_heap_allocator(std::size_t heap_start, std::size_t heap_end); + user_heap_allocator() = default; /** * @copybrief heap_allocator::allocate @@ -126,10 +122,8 @@ namespace teachos::arch::memory::heap auto coalesce_free_memory_block(memory_block * previous_block, memory_block * current_block, void * pointer, std::size_t size) -> void; - std::size_t heap_start; ///< Start of the allocatable heap area. - std::size_t heap_end; ///< End of the allocatable heap area. - memory_block * first; ///< First free entry in our memory. - stl::mutex mutex; ///< Mutex to ensure only one thread calls allocate or deallocate at once. + memory_block * first = {}; ///< First free entry in our memory. + stl::mutex mutex = {}; ///< Mutex to ensure only one thread calls allocate or deallocate at once. }; } // namespace teachos::arch::memory::heap diff --git a/arch/x86_64/src/context_switching/syscall/syscall_handler.cpp b/arch/x86_64/src/context_switching/syscall/syscall_handler.cpp index 9ca03d9..7272e9e 100644 --- a/arch/x86_64/src/context_switching/syscall/syscall_handler.cpp +++ b/arch/x86_64/src/context_switching/syscall/syscall_handler.cpp @@ -21,11 +21,10 @@ namespace teachos::arch::context_switching::syscall auto expand_user_heap() -> error { - // TODO: use actual addresses instead of this constant! - memory::remap_heap(memory::heap::USER_HEAP_SIZE + memory::heap::USER_HEAP_SIZE, memory::heap::USER_HEAP_SIZE, - memory::paging::entry::USER_ACCESSIBLE); + static auto current_heap_end = memory::heap::USER_HEAP_START; + memory::remap_heap(current_heap_end, memory::heap::USER_HEAP_SIZE, memory::paging::entry::USER_ACCESSIBLE); - arguments args{}; + arguments args{current_heap_end, memory::heap::USER_HEAP_SIZE}; asm volatile("mov %[input], %%rdi" : /* no output from call */ : [input] "m"(args.arg_0) @@ -34,7 +33,8 @@ namespace teachos::arch::context_switching::syscall : /* no output from call */ : [input] "m"(args.arg_1) : "memory"); - return error::OUT_OF_MEMORY; + current_heap_end += memory::heap::USER_HEAP_SIZE; + return error::OK; } } // namespace 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 23e2458..e6c268a 100644 --- a/arch/x86_64/src/memory/heap/global_heap_allocator.cpp +++ b/arch/x86_64/src/memory/heap/global_heap_allocator.cpp @@ -41,7 +41,7 @@ namespace teachos::arch::memory::heap } [[gnu::section(".user_data")]] - static user_heap_allocator user_allocator{USER_HEAP_START, USER_HEAP_START + USER_HEAP_SIZE}; + static user_heap_allocator user_allocator{}; user_allocator_instance = &user_allocator; } diff --git a/arch/x86_64/src/memory/heap/linked_list_allocator.cpp b/arch/x86_64/src/memory/heap/linked_list_allocator.cpp index 5101ab2..63a6111 100644 --- a/arch/x86_64/src/memory/heap/linked_list_allocator.cpp +++ b/arch/x86_64/src/memory/heap/linked_list_allocator.cpp @@ -8,9 +8,7 @@ namespace teachos::arch::memory::heap { linked_list_allocator::linked_list_allocator(std::size_t heap_start, std::size_t heap_end) - : heap_start(heap_start) - , heap_end(heap_end) - , first(nullptr) + : first(nullptr) , mutex{stl::mutex{}} { auto const heap_size = heap_end - heap_start; diff --git a/arch/x86_64/src/memory/heap/memory_block.cpp b/arch/x86_64/src/memory/heap/memory_block.cpp index 9f1fea8..6ee675a 100644 --- a/arch/x86_64/src/memory/heap/memory_block.cpp +++ b/arch/x86_64/src/memory/heap/memory_block.cpp @@ -7,10 +7,10 @@ namespace teachos::arch::memory::heap memory_block::memory_block(std::size_t size, memory_block * next) { // TODO: Figure out why this memset fails - memset(static_cast<void *>(this), 0, size); + // memset(static_cast<void *>(this), 0, size); this->size = size; this->next = next; } - memory_block::~memory_block() { memset(static_cast<void *>(this), 0, sizeof(memory_block)); } + memory_block::~memory_block() { /*memset(static_cast<void *>(this), 0, sizeof(memory_block));*/ } } // namespace teachos::arch::memory::heap diff --git a/arch/x86_64/src/memory/heap/user_heap_allocator.cpp b/arch/x86_64/src/memory/heap/user_heap_allocator.cpp index ce8b0fa..9cb6c17 100644 --- a/arch/x86_64/src/memory/heap/user_heap_allocator.cpp +++ b/arch/x86_64/src/memory/heap/user_heap_allocator.cpp @@ -8,20 +8,6 @@ namespace teachos::arch::memory::heap { - user_heap_allocator::user_heap_allocator(std::size_t heap_start, std::size_t heap_end) - : heap_start(heap_start) - , heap_end(heap_end) - , first(nullptr) - , mutex{stl::mutex{}} - { - auto const heap_size = heap_end - heap_start; - exception_handling::assert( - heap_size > min_allocatable_size(), - "[Linked List Allocator] Total heap size can not be smaller than minimum of 16 bytes to hold " - "atleast one memory hole entry"); - // first = new (reinterpret_cast<void *>(heap_start)) memory_block(heap_size, nullptr); - } - auto user_heap_allocator::allocate(std::size_t size) -> void * { // Add size of size_t to the total allocated size, because we add a header that includes the size of the allocated diff --git a/arch/x86_64/src/memory/main.cpp b/arch/x86_64/src/memory/main.cpp index 595cb0d..5e671ac 100644 --- a/arch/x86_64/src/memory/main.cpp +++ b/arch/x86_64/src/memory/main.cpp @@ -69,11 +69,7 @@ namespace teachos::arch::memory video::vga::text::write("Kernel remapping successful", video::vga::text::common_attributes::green_on_black); video::vga::text::newline(); - // Remap kernel heap remap_heap(heap::KERNEL_HEAP_START, heap::KERNEL_HEAP_SIZE); - // Remap user heap - remap_heap(heap::USER_HEAP_SIZE, heap::USER_HEAP_SIZE, paging::entry::USER_ACCESSIBLE); - video::vga::text::write("Heap remapping successful", video::vga::text::common_attributes::green_on_black); video::vga::text::newline(); } |
