42 lines
989 B
C++
42 lines
989 B
C++
#pragma once
|
|
#include <stdint.h>
|
|
|
|
class RangeAllocator
|
|
{
|
|
public:
|
|
void init(void* start_address, void* end_address);
|
|
void init_from_mmap();
|
|
|
|
void* request_page();
|
|
void* request_pages(
|
|
uint64_t count); // Please don't use this in kernelPMM. That's what KernelMemoryManager/KernelHeap do.
|
|
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;
|
|
|
|
uint64_t alloc_base;
|
|
};
|
|
|
|
extern RangeAllocator kernelPMM; |