![]() |
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 (size_t requested_size, size_t &actual_size, size_t flags) |
| Allocate a new chunk of virtual memory. | |
| void * | allocate (uint64_t address, size_t requested_size, size_t &actual_size, size_t flags) |
| Allocate a new chunk of virtual memory at a specific address (ie for mmap io devices) | |
| void | free (void *address, bool reusable_pages=true) |
| 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_range_from_process (VirtualMemoryManager *other_vmm, const void *start_address, size_t size) |
| Loads the pages from a virtual memory region in another vmm into this one. | |
| void | unload_range_from_process (const void *start_address, size_t size) |
| Unload a shared range of pages from this vmm. | |
| 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 25 of file virtual.cpp.
References MaxOS::memory::PhysicalMemoryManager::clean_page_table(), MaxOS::memory::HIGHER_HALF_DIRECT_MAP, MaxOS::memory::PhysicalMemoryManager::memory_size(), MaxOS::memory::PAGE_SIZE, MaxOS::memory::PhysicalMemoryManager::pml4_root_address(), 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(), MaxOS::memory::VMM_RESERVED, and MaxOS::memory::WRITE.
| VirtualMemoryManager::~VirtualMemoryManager | ( | ) |
Destroy the Virtual Memory Manager object and free all used pages.
Definition at line 71 of file virtual.cpp.
References MaxOS::memory::CHUNKS_PER_PAGE, MaxOS::memory::PhysicalMemoryManager::free_frame(), MaxOS::memory::PhysicalMemoryManager::get_physical_address(), MaxOS::memory::PAGE_SIZE, MaxOS::memory::PhysicalMemoryManager::s_current_manager, MaxOS::memory::SHARED, and MaxOS::memory::PhysicalMemoryManager::size_to_frames().
| void * VirtualMemoryManager::allocate | ( | size_t | requested_size, |
| size_t & | actual_size, | ||
| size_t | flags | ||
| ) |
Allocate a new chunk of virtual memory.
| requested_size | The size of the memory to allocate |
| actual_size | The size of the memory allocated (>= requested size) |
| flags | The flags to set on the memory |
Definition at line 127 of file virtual.cpp.
References allocate().
Referenced by allocate().
| void * VirtualMemoryManager::allocate | ( | size_t | requested_size, |
| size_t | flags | ||
| ) |
Allocate a new chunk of virtual memory.
| requested_size | The size of the memory to allocate |
| flags | The flags to set on the memory |
Definition at line 113 of file virtual.cpp.
References allocate().
Referenced by allocate(), MaxOS::memory::BumpMemoryManager::BumpMemoryManager(), load_physical_into_address_space(), load_range_from_process(), and MaxOS::processes::GlobalScheduler::prepare_initrd().
| void * VirtualMemoryManager::allocate | ( | uint64_t | address, |
| size_t | requested_size, | ||
| size_t & | actual_size, | ||
| size_t | flags | ||
| ) |
Allocate a new chunk of virtual memory at a specific address (ie for mmap io devices)
| address | The address to allocate at |
| requested_size | The size of the memory to allocate |
| actual_size | The size of the memory allocated (>= requested size) |
| flags | The flags to set on the memory |
Definition at line 142 of file virtual.cpp.
References MaxOS::memory::PhysicalMemoryManager::align_up_to_page(), MaxOS::memory::PhysicalMemoryManager::allocate_frame(), MaxOS::memory::PhysicalMemoryManager::check_aligned(), MaxOS::memory::CHUNKS_PER_PAGE, MaxOS::memory::VirtualMemoryChunk::flags, MaxOS::memory::PhysicalMemoryManager::free_frame(), MaxOS::memory::PhysicalMemoryManager::get_physical_address(), MaxOS::memory::PhysicalMemoryManager::map(), MaxOS::memory::PAGE_SIZE, MaxOS::memory::PRESENT, MaxOS::memory::RESERVE, MaxOS::memory::PhysicalMemoryManager::s_current_manager, MaxOS::memory::VirtualMemoryChunk::size, MaxOS::memory::PhysicalMemoryManager::size_to_frames(), MaxOS::memory::VirtualMemoryChunk::start_address, MaxOS::memory::FreeChunk::start_address, MaxOS::memory::PhysicalMemoryManager::unmap(), and MaxOS::memory::WRITE.
| void VirtualMemoryManager::free | ( | void * | address, |
| bool | reusable_pages = true |
||
| ) |
Free a chunk of virtual memory.
| address | The address of the memory to free |
| reusable_pages | Can these pages be reused (chunk will be added to free list) |
Definition at line 282 of file virtual.cpp.
References MaxOS::memory::CHUNKS_PER_PAGE, MaxOS::processes::resources::ResourceManager::close_resource(), MaxOS::processes::GlobalScheduler::current_process(), MaxOS::memory::VirtualMemoryChunk::flags, MaxOS::memory::RESERVE, MaxOS::processes::Process::resource_manager, MaxOS::processes::resources::ResourceManager::resources(), MaxOS::memory::SHARED, MaxOS::memory::VirtualMemoryChunk::size, and MaxOS::memory::VirtualMemoryChunk::start_address.
Referenced by unload_range_from_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 524 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().
| void * VirtualMemoryManager::load_range_from_process | ( | VirtualMemoryManager * | other_vmm, |
| const void * | start_address, | ||
| size_t | size | ||
| ) |
Loads the pages from a virtual memory region in another vmm into this one.
| other_vmm | The vmm that contains the region |
| start_address | The starting virtual address of the region |
| size | The length in bytes of the region |
maybe move from void* to uint8* ??
take flags for mapping (ro)
Definition at line 552 of file virtual.cpp.
References MaxOS::memory::PhysicalMemoryManager::align_direct_to_page(), MaxOS::memory::PhysicalMemoryManager::align_up_to_page(), allocate(), MaxOS::memory::PhysicalMemoryManager::get_physical_address(), MaxOS::memory::PhysicalMemoryManager::map(), MaxOS::memory::PAGE_SIZE, pml4_root_address(), MaxOS::memory::PRESENT, MaxOS::memory::RESERVE, MaxOS::memory::PhysicalMemoryManager::s_current_manager, and MaxOS::memory::WRITE.
| void * VirtualMemoryManager::load_shared_memory | ( | const string & | name | ) |
Load shared memory into the VMM's address space.
| name | The name of the shared memory |
Definition at line 487 of file virtual.cpp.
References MaxOS::processes::GlobalScheduler::current_process(), MaxOS::processes::resources::ResourceManager::get_resource(), load_shared_memory(), and MaxOS::processes::Process::resource_manager.
Referenced by MaxOS::processes::resources::BridgeHandler::BridgeHandler(), load_shared_memory(), and MaxOS::processes::SharedMemory::open().
| void * VirtualMemoryManager::load_shared_memory | ( | uintptr_t | physical_address, |
| size_t | size | ||
| ) |
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 506 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 348 of file virtual.cpp.
References MaxOS::memory::CHUNKS_PER_PAGE.
| uint64_t * VirtualMemoryManager::pml4_root_address | ( | ) |
Get the virtual address of the PML4 root.
Definition at line 691 of file virtual.cpp.
Referenced by load_range_from_process().
| uint64_t * VirtualMemoryManager::pml4_root_address_physical | ( | ) |
Get the physical address of the PML4 root.
Definition at line 476 of file virtual.cpp.
Referenced by MaxOS::memory::BumpMemoryManager::switch_active_memory_manager().
| void VirtualMemoryManager::unload_range_from_process | ( | const void * | start_address, |
| size_t | size | ||
| ) |
Unload a shared range of pages from this vmm.
| start_address | The start of the range |
| size | The length of the range in bytes |
Definition at line 602 of file virtual.cpp.
References MaxOS::memory::PhysicalMemoryManager::align_direct_to_page(), MaxOS::memory::PhysicalMemoryManager::align_up_to_page(), free(), MaxOS::memory::PAGE_SIZE, MaxOS::memory::PhysicalMemoryManager::s_current_manager, MaxOS::memory::PhysicalMemoryManager::size_to_frames(), and MaxOS::memory::PhysicalMemoryManager::unmap().
Referenced by MaxOS::processes::resources::BridgeHandler::send_to_bridge().