Public Types | Public Member Functions | Static Public Member Functions
memory_manager_x64 Class Reference

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 >
 

Public Member Functions

virtual ~memory_manager_x64 ()=default
 
virtual pointer alloc (size_type size) noexcept
 
virtual pointer alloc_map (size_type size) noexcept
 
virtual void free (pointer ptr) noexcept
 
virtual void free_map (pointer ptr) noexcept
 
virtual size_type size (pointer ptr) const noexcept
 
virtual size_type size_map (pointer ptr) const noexcept
 
virtual integer_pointer virtint_to_physint (integer_pointer virt) const
 
virtual integer_pointer virtptr_to_physint (pointer virt) const
 
virtual pointer virtint_to_physptr (integer_pointer virt) const
 
virtual pointer virtptr_to_physptr (pointer virt) const
 
virtual integer_pointer physint_to_virtint (integer_pointer phys) const
 
virtual integer_pointer physptr_to_virtint (pointer phys) const
 
virtual pointer physint_to_virtptr (integer_pointer phys) const
 
virtual pointer physptr_to_virtptr (pointer phys) const
 
virtual attr_type virtint_to_attrint (integer_pointer virt) const
 
virtual attr_type virtptr_to_attrint (pointer virt) const
 
virtual void add_md (integer_pointer virt, integer_pointer phys, attr_type attr)
 
virtual void remove_md (integer_pointer virt) noexcept
 
virtual memory_descriptor_list descriptors () const
 
 memory_manager_x64 (const memory_manager_x64 &)=delete
 
memory_manager_x64operator= (const memory_manager_x64 &)=delete
 

Static Public Member Functions

static memory_manager_x64instance () noexcept
 

Detailed Description

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.

Member Typedef Documentation

◆ pointer

Definition at line 76 of file memory_manager_x64.h.

◆ integer_pointer

Definition at line 77 of file memory_manager_x64.h.

◆ size_type

using memory_manager_x64::size_type = std::size_t

Definition at line 78 of file memory_manager_x64.h.

◆ attr_type

Definition at line 79 of file memory_manager_x64.h.

◆ memory_descriptor_list

Definition at line 80 of file memory_manager_x64.h.

Constructor & Destructor Documentation

◆ ~memory_manager_x64()

virtual memory_manager_x64::~memory_manager_x64 ( )
virtualdefault

Default Destructor

Precondition
expects: none
Postcondition
ensures: none

◆ memory_manager_x64()

memory_manager_x64::memory_manager_x64 ( const memory_manager_x64 )
delete

Member Function Documentation

◆ instance()

memory_manager_x64 * memory_manager_x64::instance ( )
staticnoexcept

Get Singleton Instance

Get an instance to the singleton class.

Precondition
expects: none
Postcondition
ensures: ret != nullptr

Definition at line 57 of file memory_manager_x64.cpp.

◆ alloc()

memory_manager_x64::pointer memory_manager_x64::alloc ( size_type  size)
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.

Precondition
expects: none
Postcondition
ensures: none
Parameters
sizethe number of bytes to allocate
Returns
a pointer to the starting address of the memory allocated. The pointer is page aligned if size is a multiple of MAX_PAGE_SIZE. Returns 0 otherwise, or on error

Definition at line 66 of file memory_manager_x64.cpp.

◆ alloc_map()

memory_manager_x64::pointer memory_manager_x64::alloc_map ( size_type  size)
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.

Precondition
expects: none
Postcondition
ensures: none
Parameters
sizethe number of bytes to allocate
Returns
a pointer to the starting address of the memory allocated. Returns 0 otherwise, or on error

Definition at line 85 of file memory_manager_x64.cpp.

◆ free()

void memory_manager_x64::free ( pointer  ptr)
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.

Precondition
expects: none
Postcondition
ensures: none
Parameters
ptra pointer to memory previously allocated using alloc.

Definition at line 101 of file memory_manager_x64.cpp.

◆ free_map()

void memory_manager_x64::free_map ( pointer  ptr)
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.

Precondition
expects: none
Postcondition
ensures: none
Parameters
ptra pointer to memory previously allocated using alloc_map.

Definition at line 113 of file memory_manager_x64.cpp.

◆ size()

memory_manager_x64::size_type memory_manager_x64::size ( pointer  ptr) const
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.

Precondition
expects: none
Postcondition
ensures: none
Parameters
ptra pointer to memory previously allocated using alloc.

Definition at line 122 of file memory_manager_x64.cpp.

◆ size_map()

memory_manager_x64::size_type memory_manager_x64::size_map ( pointer  ptr) const
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.

Precondition
expects: none
Postcondition
ensures: none
Parameters
ptra pointer to memory previously allocated using alloc_map.

Definition at line 136 of file memory_manager_x64.cpp.

◆ virtint_to_physint()

memory_manager_x64::integer_pointer memory_manager_x64::virtint_to_physint ( integer_pointer  virt) const
virtual

Virtual Address To Physical Address

Given a virtual address, returns a physical address.

Precondition
expects: virt != 0
Postcondition
ensures: return != 0
Parameters
virtvirtual address to convert
Returns
physical address

Definition at line 147 of file memory_manager_x64.cpp.

◆ virtptr_to_physint()

memory_manager_x64::integer_pointer memory_manager_x64::virtptr_to_physint ( pointer  virt) const
virtual

Virtual Address To Physical Address

Given a virtual address, returns a physical address.

Precondition
expects: virt != nullptr
Postcondition
ensures: return != 0
Parameters
virtvirtual address to convert
Returns
physical address

Definition at line 157 of file memory_manager_x64.cpp.

◆ virtint_to_physptr()

memory_manager_x64::pointer memory_manager_x64::virtint_to_physptr ( integer_pointer  virt) const
virtual

Virtual Address To Physical Address

Given a virtual address, returns a physical address.

Precondition
expects: virt != 0
Postcondition
ensures: return != 0
Parameters
virtvirtual address to convert
Returns
physical address

Definition at line 161 of file memory_manager_x64.cpp.

◆ virtptr_to_physptr()

memory_manager_x64::pointer memory_manager_x64::virtptr_to_physptr ( pointer  virt) const
virtual

Virtual Address To Physical Address

Given a virtual address, returns a physical address.

Precondition
expects: virt != nullptr
Postcondition
ensures: return != 0
Parameters
virtvirtual address to convert
Returns
physical address

Definition at line 165 of file memory_manager_x64.cpp.

◆ physint_to_virtint()

memory_manager_x64::integer_pointer memory_manager_x64::physint_to_virtint ( integer_pointer  phys) const
virtual

Physical Address To Virtual Address

Given a physical address, returns a virtual address.

Precondition
expects: phys != 0
Postcondition
ensures: return != 0
Parameters
physphysical address to convert
Returns
virtual address

Definition at line 169 of file memory_manager_x64.cpp.

◆ physptr_to_virtint()

memory_manager_x64::integer_pointer memory_manager_x64::physptr_to_virtint ( pointer  phys) const
virtual

Physical Address To Virtual Address

Given a physical address, returns a virtual address.

Precondition
expects: phys != nullptr
Postcondition
ensures: return != 0
Parameters
physphysical address to convert
Returns
virtual address

Definition at line 179 of file memory_manager_x64.cpp.

◆ physint_to_virtptr()

memory_manager_x64::pointer memory_manager_x64::physint_to_virtptr ( integer_pointer  phys) const
virtual

Physical Address To Virtual Address

Given a physical address, returns a virtual address.

Precondition
expects: phys != 0
Postcondition
ensures: return != nullptr
Parameters
physphysical address to convert
Returns
virtual address

Definition at line 183 of file memory_manager_x64.cpp.

◆ physptr_to_virtptr()

memory_manager_x64::pointer memory_manager_x64::physptr_to_virtptr ( pointer  phys) const
virtual

Physical Address To Virtual Address

Given a physical address, returns a virtual address.

Precondition
expects: phys != nullptr
Postcondition
ensures: return != nullptr
Parameters
physphysical address to convert
Returns
virtual address

Definition at line 187 of file memory_manager_x64.cpp.

◆ virtint_to_attrint()

memory_manager_x64::attr_type memory_manager_x64::virtint_to_attrint ( integer_pointer  virt) const
virtual

Virtual Address To Attribute

Given a virtual address, returns the memory's attributes

Precondition
expects: virt != 0
Postcondition
ensures: none
Parameters
virtvirtual address for the attributes to fetch
Returns
attributes associated with virt

Definition at line 191 of file memory_manager_x64.cpp.

◆ virtptr_to_attrint()

memory_manager_x64::attr_type memory_manager_x64::virtptr_to_attrint ( pointer  virt) const
virtual

Virtual Address To Attribute

Given a virtual address, returns the memory's attributes

Precondition
expects: virt != nullptr
Postcondition
ensures: none
Parameters
virtvirtual address for the attributes to fetch
Returns
attributes associated with virt

Definition at line 200 of file memory_manager_x64.cpp.

◆ add_md()

void memory_manager_x64::add_md ( integer_pointer  virt,
integer_pointer  phys,
attr_type  attr 
)
virtual

Adds Memory Descriptor

Adds a memory descriptor to the memory manager.

Precondition
expects: virt != 0
expects: phys != 0
expects: type != 0
expects: virt & (page_size - 1) == 0
expects: phys & (page_size - 1) == 0
Postcondition
ensures: none
Parameters
virtvirtual address to add
physphysical address mapped to virt
attrhow the memory was mapped

Definition at line 204 of file memory_manager_x64.cpp.

◆ remove_md()

void memory_manager_x64::remove_md ( integer_pointer  virt)
virtualnoexcept

Remove Memory Descriptor

Removes a memory descriptor list to the memory manager.

Precondition
expects: none
Postcondition
ensures: none
Parameters
virtvirtual address to remove

Definition at line 229 of file memory_manager_x64.cpp.

◆ descriptors()

memory_manager_x64::memory_descriptor_list memory_manager_x64::descriptors ( ) const
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.

Precondition
expects: none
Postcondition
ensures: none
Returns
memory descriptor list

Definition at line 257 of file memory_manager_x64.cpp.

◆ operator=()

memory_manager_x64& memory_manager_x64::operator= ( const memory_manager_x64 )
delete

The documentation for this class was generated from the following files: