#pragma once #include "init/multiboot2.h" #include "memory/pointer.h" #include "util/optional.h" constexpr const size_t page_size = 4096; struct PhysicalAllocator { struct allocation_t { paddr_t ptr; size_t page_count; }; enum class address_range_t : uint8_t { any, below_4gib, }; static void init(const multiboot::tag_mmap* multiboot_info); static PhysicalAllocator& getInstance(); optional allocPages( size_t page_count, size_t alignment_pages = 1, address_range_t range = address_range_t::any ); void free(allocation_t ptr); bool force(allocation_t ptr, bool free); private: struct page_t { page_t* next; page_t* prev; uint64_t count[510]; }; static_assert(sizeof(page_t) == page_size); page_t* storage; friend struct PhysicalAllocatorImpl; };