10#define MAXOS_VIRTUAL_H
53 } virtual_memory_chunk_t;
70 static const size_t CHUNKS_PER_PAGE = PAGE_SIZE /
sizeof(virtual_memory_chunk_t) -
72 static const size_t VMM_RESERVED = 0x138000000;
88 } virtual_memory_region_t;
99 uint64_t* m_pml4_root_address;
100 uint64_t* m_pml4_root_physical_address;
104 size_t m_current_chunk = 0;
105 size_t m_next_available_address;
108 void add_free_chunk(uintptr_t start_address,
size_t size);
112 void fill_up_to_address(uintptr_t address,
size_t flags,
bool mark_used);
118 void*
allocate(
size_t size,
size_t flags);
119 void*
allocate(uint64_t address,
size_t size,
size_t flags);
120 void free(
void* address);
Manages the virtual memory of the system and provides functions to allocate and free memory in the vi...
VirtualMemoryManager()
Construct a new Virtual Memory Manager object and set up the initial page tables (kernel mapped into ...
void * load_physical_into_address_space(uintptr_t physical_address, size_t size, size_t flags)
Load physical memory into the VMM's address space.
void * allocate(size_t size, size_t flags)
Allocate a new chunk of virtual memory.
size_t memory_used()
Returns the amount of memory used.
uint64_t * pml4_root_address_physical()
Get the physical address of the PML4 root.
~VirtualMemoryManager()
Destroy the Virtual Memory Manager object and free all used pages.
uint64_t * pml4_root_address()
Get the virtual address of the PML4 root.
void free(void *address)
Free a chunk of virtual memory.
void * load_shared_memory(const string &name)
Load shared memory into the VMM's address space.
Defines a PhysicalMemoryManager class for managing physical memory allocation and deallocation of pag...
Defines a String class for dynamically sized strings with various operations.
A chunk of memory that has been freed and is available for allocation. A node in a linked list.
size_t size
*copydoc VirtualMemoryChunk::size
uintptr_t start_address
*copydoc VirtualMemoryChunk::start_address
struct FreeChunk * next
Pointer to the next free chunk in the list (not sequential in memory)
A container for a region of virtual memory that has been allocated by the Virtual Memory Manager.
size_t flags
The flags for the memory (see VirtualFlags)
uintptr_t start_address
The first virtual address that this chunk covers.
size_t size
The size of the chunk's memory region in bytes.
A region of virtual memory containing multiple chunks (should fit in one page).
struct VirtualMemoryRegion * next
Pointer to the next region in the list.
struct PACKED MaxOS::memory::VirtualMemoryRegion virtual_memory_region_t
Alias for VirtualMemoryRegion struct.
VirtualFlags
Flags for chunks used in virtual memory allocation.
@ RESERVE
Reserve the memory but do not map any physical memory to it.