#include <memory_manager.hpp>
Static Public Member Functions | |
| static std::unique_ptr< MemoryManager > | initialize (std::weak_ptr< Arion > arion) |
Public Attributes | |
| std::unique_ptr< MemoryRecorder > | recorder |
| Used to record memory accesses to the associated Arion instance. | |
Private Member Functions | |
| uint32_t | to_uc_perms (PROT_FLAGS perms) |
| void | insert_mapping (std::shared_ptr< ARION_MAPPING > mapping) |
| void | remove_mapping (std::shared_ptr< ARION_MAPPING > mapping) |
| void | merge_uc_mappings (ADDR start, ADDR end) |
| void | merge_contiguous_uc_mappings () |
Private Attributes | |
| std::weak_ptr< Arion > | arion |
| The Arion instance associated with this instance. | |
| size_t | page_sz |
| The size of a memory page in bytes. Used when allocating new pages. | |
| ADDR | brk = 0 |
| The current break address (brk). This is used to determine where new memory should be allocated. | |
| std::vector< std::shared_ptr< ARION_MAPPING > > | mappings |
| A vector of all mappings currently present within the Arion instance. | |
This class is responsible for managing memory mappings within an Arion emulation session. It allows the user to map and unmap memory regions, change their protection flags, and read/write from/to arbitrary addresses.
Builder for MemoryManager instances.
| [in] | arion | The Arion instance associated with this instance. |
| [in] | page_sz | The size of a memory page in bytes. Used when allocating new pages. |
Aligns a given address to the next page boundary.
| [in] | addr | Address to align. |
Checks whether a memory region can be mapped at a given address and size.
| [in] | addr | Desired starting address. |
| [in] | sz | Size of the region to map. |
| ADDR arion::MemoryManager::get_brk | ( | ) |
Retrieves the current program break (brk).
| std::shared_ptr< ARION_MAPPING > arion::MemoryManager::get_mapping_at | ( | ADDR | addr | ) |
Retrieves the mapping that contains a given address.
| [in] | addr | The address to look up. |
| std::shared_ptr< ARION_MAPPING > arion::MemoryManager::get_mapping_by_info | ( | std::string | info | ) |
Retrieves a mapping by its info string.
| [in] | info | The info string identifying the mapping. |
| std::vector< std::shared_ptr< ARION_MAPPING > > arion::MemoryManager::get_mappings | ( | ) |
Returns a vector containing all currently active memory mappings.
| bool arion::MemoryManager::has_mapping | ( | std::shared_ptr< ARION_MAPPING > | mapping | ) |
Checks whether a mapping exists in the current Arion memory layout.
| [in] | mapping | The ARION_MAPPING to check. |
| bool arion::MemoryManager::has_mapping_with_info | ( | std::string | info | ) |
Checks if a mapping with a specific info string exists.
| [in] | info | The info string associated with a mapping. |
|
static |
Instanciates and initializes new MemoryManager objects with some parameters.
| [in] | arion | The Arion instance associated with this instance. |
|
private |
Inserts a new mapping in Arion memory.
| [in] | mapping | The ARION_MAPPING to insert. |
Checks whether a given address is mapped in Arion memory.
| [in] | addr | Address to check. |
| ADDR arion::MemoryManager::map | ( | ADDR | start_addr, |
| size_t | sz, | ||
| PROT_FLAGS | perms, | ||
| std::string | info = "" |
||
| ) |
Maps a memory region at a specific address.
| [in] | start_addr | The starting address for the mapping. |
| [in] | sz | Size of the region to map. |
| [in] | perms | Memory protection flags. |
| [in] | info | Optional string identifying the mapping. |
| ADDR arion::MemoryManager::map_anywhere | ( | ADDR | addr, |
| size_t | sz, | ||
| PROT_FLAGS | perms, | ||
| bool | asc = true, |
||
| std::string | info = "" |
||
| ) |
Maps a memory region near a specific address, automatically finding a suitable place.
| [in] | addr | Preferred starting address. |
| [in] | sz | Size of the region to map. |
| [in] | perms | Memory protection flags. |
| [in] | asc | If true, search upwards in memory; otherwise downwards. |
| [in] | info | Optional info string for the mapping. |
| ADDR arion::MemoryManager::map_anywhere | ( | size_t | sz, |
| PROT_FLAGS | perms, | ||
| bool | asc = true, |
||
| std::string | info = "" |
||
| ) |
Maps a memory region at any available location.
| [in] | sz | Size of the region to map. |
| [in] | perms | Memory protection flags. |
| [in] | asc | If true, search upwards in memory; otherwise downwards. |
| [in] | info | Optional info string for the mapping. |
| std::string arion::MemoryManager::mappings_str | ( | ) |
Returns a string representation of all mappings.
|
private |
Merges all contiguous memory mappings (expensive operation).
Merges contiguous memory mappings in a given range.
| [in] | start | Start memory address of the mappings that should be merged. |
| [in] | end | End memory address of the mappings that should be merged. |
| void arion::MemoryManager::protect | ( | ADDR | seg_addr, |
| PROT_FLAGS | perms | ||
| ) |
Changes protection flags for the mapping containing a specific address.
| [in] | seg_addr | Address within the mapping to modify. |
| [in] | perms | New protection flags. |
| void arion::MemoryManager::protect | ( | ADDR | start_addr, |
| ADDR | end_addr, | ||
| PROT_FLAGS | perms | ||
| ) |
Changes protection flags for a memory range.
| [in] | start_addr | Start of the range. |
| [in] | end_addr | End of the range. |
| [in] | perms | New protection flags. |
| void arion::MemoryManager::protect | ( | std::shared_ptr< ARION_MAPPING > | mapping, |
| ADDR | start_addr, | ||
| ADDR | end_addr, | ||
| PROT_FLAGS | perms | ||
| ) |
Changes protection flags for a specific region within a mapping.
| [in] | mapping | The mapping to modify. |
| [in] | start_addr | Start of the region. |
| [in] | end_addr | End of the region. |
| [in] | perms | New protection flags. |
| void arion::MemoryManager::protect | ( | std::shared_ptr< ARION_MAPPING > | mapping, |
| PROT_FLAGS | perms | ||
| ) |
Changes protection flags for an entire mapping.
| [in] | mapping | The mapping to modify. |
| [in] | perms | New protection flags. |
Reads raw bytes from memory.
| [in] | addr | Starting address. |
| [in] | data_sz | Number of bytes to read. |
Reads a memory region and returns its ASCII representation.
| [in] | addr | Starting address. |
| [in] | data_sz | Number of bytes to read. |
| std::string arion::MemoryManager::read_c_string | ( | ADDR | addr | ) |
Reads a null-terminated C string from memory.
| [in] | addr | Address of the string. |
Reads a file descriptor (int) from memory.
| [in] | addr | Address to read from. |
Reads memory as a hexadecimal string.
| [in] | addr | Starting address. |
| [in] | data_sz | Number of bytes to read. |
| [in] | sep | Optional separator character between bytes. |
Disassembles a number of instructions from a given address.
| [in] | addr | Starting address. |
| [in] | count | Number of instructions to read. |
Reads a pointer-sized value from memory.
| [in] | addr | Address to read from. |
Reads an array of pointers from memory.
| [in] | addr | Starting address of the array. |
Reads a size_t value from memory.
| [in] | addr | Address to read from. |
Reads an integer value of a given size from memory.
| [in] | addr | Address to read from. |
| [in] | n | Number of bytes to read. |
|
private |
Removes a mapping from Arion memory.
| [in] | mapping | The ARION_MAPPING to remove. |
Resizes the mapping containing a specific address.
| [in] | seg_addr | Address within the mapping. |
| [in] | start_addr | New start address. |
| [in] | end_addr | New end address. |
| void arion::MemoryManager::resize_mapping | ( | std::shared_ptr< ARION_MAPPING > | mapping, |
| ADDR | start_addr, | ||
| ADDR | end_addr | ||
| ) |
Resizes an existing mapping to a new range.
| [in] | mapping | The mapping to resize. |
| [in] | start_addr | New start address. |
| [in] | end_addr | New end address. |
Sets the current program break (brk).
| [in] | brk | New break address. |
| void arion::MemoryManager::stack_align | ( | ) |
Aligns the emulated stack pointer to the current word or ABI boundary.
| uint64_t arion::MemoryManager::stack_pop | ( | ) |
Pops a 64-bit value from the emulated stack.
Pushes a 64-bit value onto the emulated stack.
| [in] | val | Value to push. |
Pushes raw bytes onto the emulated stack.
| [in] | data | Pointer to the data to push. |
| [in] | data_sz | Size of the data in bytes. |
| void arion::MemoryManager::stack_push_string | ( | std::string | data | ) |
Pushes a string onto the emulated stack.
| [in] | data | String to push. |
|
private |
Unmaps the mapping containing a specific address.
| [in] | seg_addr | Any address within the mapping to remove. |
Unmaps a range of memory.
| [in] | start_addr | Start address of the region to unmap. |
| [in] | end_addr | End address of the region to unmap. |
| void arion::MemoryManager::unmap | ( | std::shared_ptr< ARION_MAPPING > | mapping | ) |
Unmaps an entire mapping.
| [in] | mapping | The mapping to unmap. |
| void arion::MemoryManager::unmap | ( | std::shared_ptr< ARION_MAPPING > | mapping, |
| ADDR | start_addr, | ||
| ADDR | end_addr | ||
| ) |
Unmaps a memory range from an existing mapping.
| [in] | mapping | The mapping to unmap from. |
| [in] | start_addr | Start of the range to unmap. |
| [in] | end_addr | End of the range to unmap. |
| void arion::MemoryManager::unmap_all | ( | ) |
Unmaps all memory regions.
Writes raw bytes to memory.
| [in] | addr | Destination address. |
| [in] | data | Pointer to the data. |
| [in] | data_sz | Size of the data. |
Writes a file descriptor (int) to memory.
| [in] | addr | Destination address. |
| [in] | fd | File descriptor to write. |
Writes a pointer to memory.
| [in] | addr | Destination address. |
| [in] | ptr | Pointer value to write. |
Writes a string to memory (without null-termination unless included).
| [in] | addr | Destination address. |
| [in] | data | The string to write. |
Writes a size_t value to memory.
| [in] | addr | Destination address. |
| [in] | sz | Size value to write. |
Writes a fixed-size integer value to memory.
| [in] | addr | Destination address. |
| [in] | val | The value to write. |
| [in] | n | Number of bytes to write. |
|
private |
The Arion instance associated with this instance.
|
private |
The current break address (brk). This is used to determine where new memory should be allocated.
|
private |
A vector of all mappings currently present within the Arion instance.
|
private |
The size of a memory page in bytes. Used when allocating new pages.
| std::unique_ptr<MemoryRecorder> arion::MemoryManager::recorder |
Used to record memory accesses to the associated Arion instance.