#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 next; entry_t entries[255]; void forceEntry(entry_t entry); void cleanup(); void compact(); }; static_assert(sizeof(Page) == page_size); Page* storage; };