Kernel: Allocators are now stored in UniqPtr
This allows proper memory management, we had some memory leak
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <BAN/UniqPtr.h>
|
||||
#include <kernel/Memory/Heap.h>
|
||||
#include <kernel/Memory/PageTable.h>
|
||||
|
||||
@@ -12,10 +13,10 @@ namespace Kernel
|
||||
BAN_NON_MOVABLE(FixedWidthAllocator);
|
||||
|
||||
public:
|
||||
FixedWidthAllocator(PageTable&, uint32_t);
|
||||
static BAN::ErrorOr<BAN::UniqPtr<FixedWidthAllocator>> create(PageTable&, uint32_t);
|
||||
~FixedWidthAllocator();
|
||||
|
||||
BAN::ErrorOr<FixedWidthAllocator*> clone(PageTable&);
|
||||
BAN::ErrorOr<BAN::UniqPtr<FixedWidthAllocator>> clone(PageTable&);
|
||||
|
||||
vaddr_t allocate();
|
||||
bool deallocate(vaddr_t);
|
||||
@@ -26,6 +27,7 @@ namespace Kernel
|
||||
uint32_t max_allocations() const;
|
||||
|
||||
private:
|
||||
FixedWidthAllocator(PageTable&, uint32_t);
|
||||
bool allocate_page_if_needed(vaddr_t, uint8_t flags);
|
||||
|
||||
struct node
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <BAN/LinkedList.h>
|
||||
#include <BAN/UniqPtr.h>
|
||||
#include <kernel/Memory/Heap.h>
|
||||
#include <kernel/Memory/PageTable.h>
|
||||
|
||||
@@ -13,13 +14,16 @@ namespace Kernel
|
||||
BAN_NON_MOVABLE(GeneralAllocator);
|
||||
|
||||
public:
|
||||
GeneralAllocator(PageTable&);
|
||||
static BAN::ErrorOr<BAN::UniqPtr<GeneralAllocator>> create(PageTable&);
|
||||
~GeneralAllocator();
|
||||
|
||||
BAN::ErrorOr<BAN::UniqPtr<GeneralAllocator>> clone(PageTable&);
|
||||
|
||||
vaddr_t allocate(size_t);
|
||||
bool deallocate(vaddr_t);
|
||||
|
||||
BAN::ErrorOr<GeneralAllocator*> clone(PageTable&);
|
||||
private:
|
||||
GeneralAllocator(PageTable&);
|
||||
|
||||
private:
|
||||
struct Allocation
|
||||
|
||||
@@ -114,12 +114,12 @@ namespace Kernel
|
||||
BAN::String m_working_directory;
|
||||
BAN::Vector<Thread*> m_threads;
|
||||
|
||||
BAN::Vector<FixedWidthAllocator*> m_fixed_width_allocators;
|
||||
GeneralAllocator* m_general_allocator;
|
||||
BAN::Vector<BAN::UniqPtr<FixedWidthAllocator>> m_fixed_width_allocators;
|
||||
BAN::UniqPtr<GeneralAllocator> m_general_allocator;
|
||||
|
||||
userspace_entry_t m_userspace_entry;
|
||||
|
||||
PageTable* m_page_table { nullptr };
|
||||
BAN::UniqPtr<PageTable> m_page_table;
|
||||
TTY* m_tty { nullptr };
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user