![]() |
Max OS 0.3
|
Manages the virtual memory of the system and provides functions to allocate and free memory in the virtual address space. More...
#include <virtual.h>
Public Member Functions | |
| VirtualMemoryManager () | |
| Construct a new Virtual Memory Manager object and set up the initial page tables (kernel mapped into the hh) | |
| ~VirtualMemoryManager () | |
| Destroy the Virtual Memory Manager object and free all used pages. | |
| void * | allocate (size_t size, size_t flags) |
| Allocate a new chunk of virtual memory. | |
| void * | allocate (uint64_t address, size_t size, size_t flags) |
| Allocate a new chunk of virtual memory at a specific address (ie for mmap io devices) | |
| void | free (void *address) |
| Free a chunk of virtual memory. | |
| 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 * | load_shared_memory (const string &name) |
| Load shared memory into the VMM's address space. | |
| void * | load_shared_memory (uintptr_t physical_address, size_t size) |
| Load shared memory into the VMM's address space. | |
| uint64_t * | pml4_root_address () |
| Get the virtual address of the PML4 root. | |
| uint64_t * | pml4_root_address_physical () |
| Get the physical address of the PML4 root. | |
| size_t | memory_used () |
| Returns the amount of memory used. | |
Manages the virtual memory of the system and provides functions to allocate and free memory in the virtual address space.
| VirtualMemoryManager::VirtualMemoryManager | ( | ) |
Construct a new Virtual Memory Manager object and set up the initial page tables (kernel mapped into the hh)
Definition at line 22 of file virtual.cpp.
References MaxOS::memory::PhysicalMemoryManager::align_to_page(), ASSERT, MaxOS::memory::PhysicalMemoryManager::clean_page_table(), MaxOS::Logger::DEBUG(), MaxOS::memory::HIGHER_HALF_DIRECT_MAP, MaxOS::memory::PAGE_SIZE, MaxOS::memory::PRESENT, MaxOS::memory::PhysicalMemoryManager::s_current_manager, MaxOS::memory::MemoryManager::s_kernel_memory_manager, MaxOS::memory::PhysicalMemoryManager::to_dm_region(), MaxOS::memory::PhysicalMemoryManager::to_lower_region(), and MaxOS::memory::WRITE.
| VirtualMemoryManager::~VirtualMemoryManager | ( | ) |
Destroy the Virtual Memory Manager object and free all used pages.
Definition at line 81 of file virtual.cpp.
References MaxOS::memory::PAGE_SIZE, MaxOS::memory::PhysicalMemoryManager::s_current_manager, and MaxOS::memory::PhysicalMemoryManager::size_to_frames().
Allocate a new chunk of virtual memory.
| size | The size of the memory to allocate |
| flags | The flags to set on the memory |
Definition at line 119 of file virtual.cpp.
References allocate().
Referenced by allocate(), load_physical_into_address_space(), and MaxOS::memory::MemoryManager::MemoryManager().
Allocate a new chunk of virtual memory at a specific address (ie for mmap io devices)
| address | The address to allocate at |
| size | The size of the memory to allocate |
| flags | The flags to set on the memory |
Definition at line 133 of file virtual.cpp.
References MaxOS::memory::PhysicalMemoryManager::align_up_to_page(), ASSERT, MaxOS::memory::PhysicalMemoryManager::check_aligned(), MaxOS::memory::PAGE_SIZE, MaxOS::memory::PRESENT, MaxOS::memory::RESERVE, MaxOS::memory::PhysicalMemoryManager::s_current_manager, MaxOS::memory::PhysicalMemoryManager::size_to_frames(), and MaxOS::memory::WRITE.
Free a chunk of virtual memory.
| address | The address of the memory to free |
Definition at line 253 of file virtual.cpp.
References MaxOS::processes::GlobalScheduler::current_process().
| void * VirtualMemoryManager::load_physical_into_address_space | ( | uintptr_t | physical_address, |
| size_t | size, | ||
| size_t | flags | ||
| ) |
Load physical memory into the VMM's address space.
| physical_address | The physical address of the memory |
| size | The size of the memory |
| flags | The flags to set on the memory |
Definition at line 455 of file virtual.cpp.
References allocate(), MaxOS::memory::PAGE_SIZE, MaxOS::memory::PRESENT, MaxOS::memory::RESERVE, MaxOS::memory::PhysicalMemoryManager::s_current_manager, MaxOS::memory::PhysicalMemoryManager::size_to_frames(), and MaxOS::memory::WRITE.
Referenced by load_shared_memory().
Load shared memory into the VMM's address space.
| name | The name of the shared memory |
Definition at line 418 of file virtual.cpp.
References MaxOS::processes::GlobalScheduler::current_process(), and load_shared_memory().
Referenced by load_shared_memory().
Load shared memory into the VMM's address space.
| physical_address | The physical address of the shared memory |
| size | The size of the shared memory |
Definition at line 437 of file virtual.cpp.
References load_physical_into_address_space(), and MaxOS::memory::SHARED.
| size_t VirtualMemoryManager::memory_used | ( | ) |
Returns the amount of memory used.
Definition at line 320 of file virtual.cpp.
| uint64_t * VirtualMemoryManager::pml4_root_address | ( | ) |
Get the virtual address of the PML4 root.
Definition at line 521 of file virtual.cpp.
| uint64_t * VirtualMemoryManager::pml4_root_address_physical | ( | ) |
Get the physical address of the PML4 root.
Definition at line 407 of file virtual.cpp.