Public Types | |
using | pointer = void * |
using | integer_pointer = uintptr_t |
using | size_type = std::size_t |
using | attr_type = decltype(memory_descriptor::type) |
using | memory_descriptor_list = std::vector< memory_descriptor > |
Static Public Member Functions | |
static memory_manager_x64 * | instance () noexcept |
The memory manager has a couple specific functions:
To support alloc / free, the memory manager is given both heap memory and a page pool. If a alloc is requested whose size is a multiple of MAX_PAGE_SIZE, the page pool is used. All other requests come from the heap.
To support virt / phys mappings, the memory manager has an add_mdl function that is called by the driver entry. Each time the driver entry allocates memory for an ELF module, it must call add_mdl with a list of page mappings that tells the VMM how to convert from virt to phys and back. The memory manager uses this information to provide the VMM with the needed conversions.
Mapping / unmapping of virtual to physical memory is handled by providing two capabilities. First, the memory manager provides a means to alloc and free memory specific to mapping. This is virtual memory space that has not been consumed by the heap / page pool. Second, a map and unmap function are also provided that add / remove page mappings to the VMM's root page tables. This operation should not be done manually, but instead should be done using unique_map_ptr_x64.
Finally, this module also provides the libc functions that are needed by libc++ for new / delete. For this reason, this module is required to get libc++ working, which is needed by, pretty much the rest of the VMM including the serial code. Therefore, if there are issues with the memory manager, the process of debugging the memory manager is not simple, as you must get rid of all of the other modules, and work with the memory manager directly until it's working as needed (i.e. why unit testing can be very helpful here).
Definition at line 72 of file memory_manager_x64.h.
using memory_manager_x64::pointer = void * |
Definition at line 76 of file memory_manager_x64.h.
using memory_manager_x64::integer_pointer = uintptr_t |
Definition at line 77 of file memory_manager_x64.h.
using memory_manager_x64::size_type = std::size_t |
Definition at line 78 of file memory_manager_x64.h.
using memory_manager_x64::attr_type = decltype(memory_descriptor::type) |
Definition at line 79 of file memory_manager_x64.h.
using memory_manager_x64::memory_descriptor_list = std::vector<memory_descriptor> |
Definition at line 80 of file memory_manager_x64.h.
|
virtualdefault |
Default Destructor
|
delete |
|
staticnoexcept |
Get Singleton Instance
Get an instance to the singleton class.
Definition at line 57 of file memory_manager_x64.cpp.
|
virtualnoexcept |
Allocate Memory
Allocates memory. If the requested size is a multiple of MAX_PAGE_SIZE the page pool is used to allocate the memory which likely has more memory, and the resulting addresses are page aligned. All other requests come from the heap.
size | the number of bytes to allocate |
Definition at line 66 of file memory_manager_x64.cpp.
|
virtualnoexcept |
Allocate Map
Allocates virtual memory to be used for mapping. This memory has no backing until it has been mapped, so don't attempt to dereference it until then as that will result in undefined behavior.
size | the number of bytes to allocate |
Definition at line 85 of file memory_manager_x64.cpp.
|
virtualnoexcept |
Free Memory
Deallocates a block of memory previously allocated by a call to alloc or alloc_map, making it available again for further allocations. If ptr does not point to memory that was previously allocated, the call is ignored. If ptr == nullptr, the call is also ignored.
ptr | a pointer to memory previously allocated using alloc. |
Definition at line 101 of file memory_manager_x64.cpp.
|
virtualnoexcept |
Free Map
Deallocates a block of memory previously allocated by a call to alloc_map, making it available again for further allocations. If ptr does not point to memory that was previously allocated, the call is ignored. If ptr == nullptr, the call is also ignored.
ptr | a pointer to memory previously allocated using alloc_map. |
Definition at line 113 of file memory_manager_x64.cpp.
|
virtualnoexcept |
Size
Returns the size of previously allocated memory. If the provided pointer does not point to memory that has been allocated or is outside the bounds of the memory pool, this function returns 0.
ptr | a pointer to memory previously allocated using alloc. |
Definition at line 122 of file memory_manager_x64.cpp.
|
virtualnoexcept |
Size of Map
Returns the size of previously allocated map memory. If the provided pointer does not point to memory that has been allocated or is outside the bounds of the memory pool, this function returns 0.
ptr | a pointer to memory previously allocated using alloc_map. |
Definition at line 136 of file memory_manager_x64.cpp.
|
virtual |
Virtual Address To Physical Address
Given a virtual address, returns a physical address.
virt | virtual address to convert |
Definition at line 147 of file memory_manager_x64.cpp.
|
virtual |
Virtual Address To Physical Address
Given a virtual address, returns a physical address.
virt | virtual address to convert |
Definition at line 157 of file memory_manager_x64.cpp.
|
virtual |
Virtual Address To Physical Address
Given a virtual address, returns a physical address.
virt | virtual address to convert |
Definition at line 161 of file memory_manager_x64.cpp.
|
virtual |
Virtual Address To Physical Address
Given a virtual address, returns a physical address.
virt | virtual address to convert |
Definition at line 165 of file memory_manager_x64.cpp.
|
virtual |
Physical Address To Virtual Address
Given a physical address, returns a virtual address.
phys | physical address to convert |
Definition at line 169 of file memory_manager_x64.cpp.
|
virtual |
Physical Address To Virtual Address
Given a physical address, returns a virtual address.
phys | physical address to convert |
Definition at line 179 of file memory_manager_x64.cpp.
|
virtual |
Physical Address To Virtual Address
Given a physical address, returns a virtual address.
phys | physical address to convert |
Definition at line 183 of file memory_manager_x64.cpp.
|
virtual |
Physical Address To Virtual Address
Given a physical address, returns a virtual address.
phys | physical address to convert |
Definition at line 187 of file memory_manager_x64.cpp.
|
virtual |
Virtual Address To Attribute
Given a virtual address, returns the memory's attributes
virt | virtual address for the attributes to fetch |
Definition at line 191 of file memory_manager_x64.cpp.
|
virtual |
Virtual Address To Attribute
Given a virtual address, returns the memory's attributes
virt | virtual address for the attributes to fetch |
Definition at line 200 of file memory_manager_x64.cpp.
|
virtual |
Adds Memory Descriptor
Adds a memory descriptor to the memory manager.
virt | virtual address to add |
phys | physical address mapped to virt |
attr | how the memory was mapped |
Definition at line 204 of file memory_manager_x64.cpp.
|
virtualnoexcept |
Remove Memory Descriptor
Removes a memory descriptor list to the memory manager.
virt | virtual address to remove |
Definition at line 229 of file memory_manager_x64.cpp.
|
virtual |
Descriptor List
Returns a list of descriptors that have been added to the memory manager. Note that to limit the amount of memory that is needed for lookups, this function is expensive has it has to reconstruct the descriptors currently being stored.
Definition at line 257 of file memory_manager_x64.cpp.
|
delete |