Luna/kernel/include/memory/RangeAllocator.h

38 lines
833 B
C++

#pragma once
#include <stdint.h>
class RangeAllocator
{
public:
void init(void* start_address, uint64_t count);
void init_from_mmap();
void* request_page();
void free_page(void* address);
void free_pages(void* address, uint64_t count);
void lock_page(void* address);
void lock_pages(void* address, uint64_t count);
uint64_t get_free();
uint64_t get_used();
uint64_t get_reserved();
private:
void reserve_page(void* address);
void reserve_pages(void* address, uint64_t count);
bool bitmap_read(uint64_t index);
void bitmap_set(uint64_t index, bool value);
uint64_t free_mem = 0;
uint64_t used_mem = 0;
uint64_t reserved_mem = 0;
char* bitmap_addr;
uint64_t bitmap_size;
uint64_t start_index = 0;
};
extern RangeAllocator physical_allocator;