Kernel: Add barebones GeneralAllocator for >4096B

This commit is contained in:
Bananymous
2023-05-08 22:10:49 +03:00
parent f1667b398a
commit 512be884ed
8 changed files with 169 additions and 13 deletions

View File

@@ -0,0 +1,34 @@
#pragma once
#include <BAN/LinkedList.h>
#include <kernel/Memory/Heap.h>
#include <kernel/Memory/MMU.h>
namespace Kernel
{
class GeneralAllocator
{
BAN_NON_COPYABLE(GeneralAllocator);
BAN_NON_MOVABLE(GeneralAllocator);
public:
GeneralAllocator(MMU&);
~GeneralAllocator();
vaddr_t allocate(size_t);
bool deallocate(vaddr_t);
private:
struct Allocation
{
vaddr_t address { 0 };
BAN::Vector<paddr_t> pages;
};
private:
MMU& m_mmu;
BAN::LinkedList<Allocation> m_allocations;
};
}

View File

@@ -24,10 +24,10 @@ namespace Kernel
~MMU();
void identity_map_page(paddr_t, flags_t);
void identity_map_range(paddr_t, size_t, flags_t);
void identity_map_range(paddr_t, size_t bytes, flags_t);
void unmap_page(vaddr_t);
void unmap_range(vaddr_t, size_t);
void unmap_range(vaddr_t, size_t bytes);
void map_page_at(paddr_t, vaddr_t, flags_t);
@@ -35,10 +35,10 @@ namespace Kernel
flags_t get_page_flags(vaddr_t) const;
bool is_page_free(vaddr_t) const;
bool is_range_free(vaddr_t, size_t) const;
bool is_range_free(vaddr_t, size_t bytes) const;
vaddr_t get_free_page() const;
vaddr_t get_free_contiguous_pages(uint32_t) const;
vaddr_t get_free_contiguous_pages(size_t page_count) const;
void load();

View File

@@ -5,6 +5,7 @@
#include <BAN/Vector.h>
#include <kernel/FS/Inode.h>
#include <kernel/Memory/FixedWidthAllocator.h>
#include <kernel/Memory/GeneralAllocator.h>
#include <kernel/Memory/Heap.h>
#include <kernel/Memory/MMU.h>
#include <kernel/SpinLock.h>
@@ -95,6 +96,7 @@ namespace Kernel
BAN::Vector<Thread*> m_threads;
BAN::LinkedList<FixedWidthAllocator> m_fixed_width_allocators;
GeneralAllocator* m_general_allocator;
MMU* m_mmu { nullptr };
TTY* m_tty { nullptr };