Kernel: Add basic fixed width allocator for userspace

We have to move process stacks to the general heap and maybe map
kernel to higher half.
This commit is contained in:
Bananymous
2023-05-06 18:10:38 +03:00
parent 9c07add00f
commit bcfd838131
10 changed files with 267 additions and 9 deletions

View File

@@ -0,0 +1,48 @@
#pragma once
#include <kernel/Memory/Heap.h>
namespace Kernel
{
class Process;
class FixedWidthAllocator
{
BAN_NON_COPYABLE(FixedWidthAllocator);
public:
FixedWidthAllocator(Process*, uint32_t);
FixedWidthAllocator(FixedWidthAllocator&&);
~FixedWidthAllocator();
vaddr_t allocate();
void deallocate(vaddr_t);
uint32_t allocation_size() const { return m_allocation_size; }
private:
struct node
{
node* prev { nullptr };
node* next { nullptr };
};
vaddr_t address_of(const node*) const;
void allocate_page_for_node_if_needed(const node*);
private:
static constexpr uint32_t m_min_allocation_size = 16;
Process* m_process;
const uint32_t m_allocation_size;
vaddr_t m_nodes_page { 0 };
vaddr_t m_allocated_pages { 0 };
node* m_free_list { nullptr };
node* m_used_list { nullptr };
uint32_t m_allocated { 0 };
};
}