feat: start adding physical memory allocator
This commit is contained in:
parent
8dc53f662e
commit
e2ea22ad53
15 changed files with 440 additions and 38 deletions
37
kernel/include/memory/allocator.h
Normal file
37
kernel/include/memory/allocator.h
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
#pragma once
|
||||
|
||||
#include "memory/pointer.h"
|
||||
#include "process/process.h"
|
||||
#include "util/optional.h"
|
||||
#include "init/multiboot2.h"
|
||||
|
||||
constexpr const size_t page_size = 4096;
|
||||
|
||||
struct PhysicalAllocator {
|
||||
public:
|
||||
struct allocation_t {
|
||||
paddr_t ptr;
|
||||
size_t page_count;
|
||||
};
|
||||
struct entry_t {
|
||||
uint64_t page_count;
|
||||
pid_t owner;
|
||||
};
|
||||
static void init(const multiboot::tag_mmap* multiboot_info);
|
||||
static PhysicalAllocator& getInstance();
|
||||
allocation_t allocPages(size_t page_count, pid_t owner);
|
||||
void free(allocation_t ptr);
|
||||
void force(allocation_t ptr, pid_t owner);
|
||||
entry_t getOwner(paddr_t from);
|
||||
private:
|
||||
struct Page {
|
||||
optional<Page*> next;
|
||||
entry_t entries[255];
|
||||
void forceEntry(entry_t entry);
|
||||
void cleanup();
|
||||
void compact();
|
||||
};
|
||||
static_assert(sizeof(Page) == page_size);
|
||||
Page* storage;
|
||||
};
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue