Public Types | |
using | pointer = T * |
using | integer_pointer = uintptr_t |
using | size_type = size_t |
using | element_type = T |
Unique Map
Like std::unique_ptr, unique_map_ptr_x64 is a smart map that owns and manages the mapping between virtual and physical memory. Memory is mapped when the unique_map_ptr_x64 is first created, and unmapped when the unique_map_ptr_x64 is destroyed.
Although this class can be used directly, it should be created using make_unique_map_x64, which allocates the virtual memory for you as shown in this example:
Example:
Unlike std::unique_pointer, unique_map_ptr_x64 takes additional arguments and doesn't support an array syntax. It should also be noted that this class provides some additional helpers specific to a map including a way to get it's size, as well as a means to flush TLB entries associated with this map if needed (although when the map is created, the local TLB is flushed for you, and thus this should only be needed if you share this map with another core)
Definition at line 54 of file map_ptr_x64.h.
using bfn::unique_map_ptr_x64< T >::pointer = T* |
Definition at line 343 of file map_ptr_x64.h.
using bfn::unique_map_ptr_x64< T >::integer_pointer = uintptr_t |
Definition at line 344 of file map_ptr_x64.h.
using bfn::unique_map_ptr_x64< T >::size_type = size_t |
Definition at line 345 of file map_ptr_x64.h.
using bfn::unique_map_ptr_x64< T >::element_type = T |
Definition at line 346 of file map_ptr_x64.h.
|
inline |
Default Map
This constructor can be used to create a default map that maps to nothing
Definition at line 353 of file map_ptr_x64.h.
|
inline |
Invalid Map
This constructor can be used to create an invalid map that maps to nothing
Definition at line 364 of file map_ptr_x64.h.
|
inline |
Release Map
This constructor can be used to create a map that maps to an exist virtual address and size. Note that this should be used with case as the original map must be released. Otherwise you will have two owners.
Definition at line 377 of file map_ptr_x64.h.
|
inline |
Map Single Page
This constructor can be used to map a single virtual memory page to a single physical memory page.
Example:
vmap | the virtual address to map the physical address to |
phys | the physical address to map |
attr | defines how to map the memory. Defaults to map_read_write |
Definition at line 404 of file map_ptr_x64.h.
|
inline |
Map Physically Contiguous / Non-Contiguous Range
This constructor can be used to map both physically contiguous, and physically non-contiguous memory by providing a list of physical pages to map. The list consists of std::pairs, each containing a physical address, and a size. A physically contiguous memory range would consist of a list of one std::pair contains the physical address and it's size. A physically non-contiguous range would consist of a list of each page range that makes up the memory to be mapped (similar to a Windows MDL). In either case the total number of bytes mapped is equal to the total of each size field in each std::pair in the list provided.
Example:
vmap | the virtual address to map the physical address to |
list | list of std::pairs, each containing a physical address and a size, defining a physical address range to add to the virtual address mapping |
attr | defines how to map the memory. Defaults to map_read_write |
Definition at line 469 of file map_ptr_x64.h.
|
inline |
Map Physically Contiguous / Non-Contiguous Range With CR3
This constructor can be used to map both physically contiguous, and physically non-contiguous memory by providing an existing virtually contiguous memory range address and size, as well as the CR3 value that defines the existing virtual to physical memory mappings. This is useful when mapping guest memory into VMM, and caution should be taken if mapping executable memory.
Example:
vmap | the virtual address to map the range to |
virt | the virtual address containing the existing mapping |
cr3 | the root page table containing the existing virtual to physical memory mappings |
size | the number of bytes to map |
pat | the pat msr associated with the provided cr3 |
Definition at line 542 of file map_ptr_x64.h.
|
inlinenoexcept |
Move Constructor
Like std::unique_ptr, this is equivalent to
Example:
The unique_map_ptr_x64 provided will no longer be valid, and the new unique_map_ptr_x64 will have the mapping provided. Note that this should be a fast operation, and no mapping / unmapping occurs. If the existing mapping is invalid, or already unmapped, the resulting unique_map_ptr_x64 will also be invalid / unmapped.
other | the unique_map_ptr_x64 to move |
Definition at line 579 of file map_ptr_x64.h.
|
inlinevirtualnoexcept |
Destructor
Unmaps any existing map this unique_map_ptr_x64 holds. Note that if an occurs while attempting to unmap, exceptions are caught and execution continues. If this occurs, the results are undefined.
Definition at line 594 of file map_ptr_x64.h.
|
delete |
|
inlinenoexcept |
Copy Operator
Like std::unique_ptr, this is equivalent to
Example:
The unique_map_ptr_x64 provided will no longer be valid, and the new unique_map_ptr_x64 will have the mapping provided. Note that this should be a fast operation, and no mapping / unmapping occurs. If the existing mapping is invalid, or already unmapped, the resulting unique_map_ptr_x64 will also be invalid / unmapped.
other | the unique_map_ptr_x64 to copy |
Definition at line 625 of file map_ptr_x64.h.
|
inlinenoexcept |
Copy Operator (reset)
Like std::unique_ptr, this is equivalent to
Example:
The result of this operation is the current unique_map_ptr_x64 will be unmapped and invalid.
dontcare | nullptr |
Definition at line 649 of file map_ptr_x64.h.
|
inline |
Dereference
Returns *T. Note that if the map is invalid, this operation will likely segfault.
Definition at line 667 of file map_ptr_x64.h.
|
inlinenoexcept |
Dereference
Returns *T. Note that if the map is invalid, this operation will likely segfault.
Definition at line 680 of file map_ptr_x64.h.
|
inlinevirtualnoexcept |
Get *T
Returns *T. Note that if the map is invalid, any use of the result will likely segfault.
Definition at line 693 of file map_ptr_x64.h.
|
inlinenoexcept |
Check Validity
Definition at line 703 of file map_ptr_x64.h.
|
inlinevirtualnoexcept |
Size
Definition at line 714 of file map_ptr_x64.h.
|
inlinenoexcept |
Release
Like std::unique_ptr, this releases the map from this unique_map_ptr_x64 and returns a std::tuple containing the virtual address and size of the map. It is left to the user of this function to either deliver the std::tuple to another unique_map_ptr_x64 via reset(), or manually unmap / free the virtual address
Definition at line 733 of file map_ptr_x64.h.
|
inlinenoexcept |
Reset
Like std::unique_ptr, this resets the unique_map_ptr_x64. If no args are provide, this function unmaps / frees the unique_map_ptr_x64 and the mapped memory becomes invalid. If a valid virtual address and size are provided, the current unique_map_ptr_x64 is unmapped and freed, and the newly provided virtual address and size are used in it's place.
ptr | pointer to virtual memory to use. Defaults to nullptr |
size | the size of the virtual memory provided in bytes. Defaults to 0 |
unaligned_size | the unaligned size of the virtual memory provided in bytes. Defaults to 0. In most cases this is the same thing as size, but if your using a map from CR3, and the virtual address is not page aligned, you must add lower(virt) |
Definition at line 768 of file map_ptr_x64.h.
|
inlinenoexcept |
Reset
Like std::unique_ptr, this resets the unique_map_ptr_x64. If no args are provide, this function unmaps / frees the unique_map_ptr_x64 and the mapped memory becomes invalid. If a valid virtual address and size are provided, the current unique_map_ptr_x64 is unmapped and freed, and the newly provided virtual address and size are used in it's place.
p | std::tuple containing the virtual memory address and size in bytes of the new mapping to use. |
Definition at line 797 of file map_ptr_x64.h.
|
inlinenoexcept |
Swap
Swaps the mappings of one unique_map_ptr_x64 with another
other | the unique_map_ptr_x64 to swap with |
Definition at line 809 of file map_ptr_x64.h.
|
inlinenoexcept |
Flush
Flushes the TLB entries associated with the virtual address ranges this unique_map_ptr_x64 holds. This is done automatically when mapping memory, but might be needed if this map is shared with another core whose TLB has not been properly flushed.
Definition at line 826 of file map_ptr_x64.h.
|
inlinenoexcept |
Cache Flush
Flushes the Cache associated with the virtual address ranges this unique_map_ptr_x64 holds. This is done automatically when unmapping memory, but might be needed manually by users
Definition at line 842 of file map_ptr_x64.h.
|
delete |