Skip to main content

Overview

The memory_interface class provides methods for reading and writing emulator memory. It supports both raw memory operations and templated type-safe operations.

Class Definition

Source: memory_interface.hpp:12

Core Virtual Methods

read_memory()

Reads memory from the emulator.
uint64_t
required
Memory address to read from
void*
required
Pointer to buffer to store the read data
size_t
required
Number of bytes to read
Throws: Exception if memory cannot be read Source: memory_interface.hpp:19

try_read_memory()

Attempts to read memory without throwing exceptions.
uint64_t
required
Memory address to read from
void*
required
Pointer to buffer to store the read data
size_t
required
Number of bytes to read
Returns: true if read succeeded, false if memory is inaccessible Source: memory_interface.hpp:20

write_memory()

Writes memory to the emulator.
uint64_t
required
Memory address to write to
const void*
required
Pointer to data to write
size_t
required
Number of bytes to write
Throws: Exception if memory cannot be written Source: memory_interface.hpp:21

try_write_memory()

Attempts to write memory without throwing exceptions.
uint64_t
required
Memory address to write to
const void*
required
Pointer to data to write
size_t
required
Number of bytes to write
Returns: true if write succeeded, false if memory is inaccessible Source: memory_interface.hpp:22

Template Methods

read_memory<T>() - Single Value

Reads a typed value from memory.
uint64_t
required
Memory address to read from
Template Parameters:
  • T - Type of value to read (e.g., uint32_t, int64_t, custom struct)
Returns: The value read from memory Source: memory_interface.hpp:32 Example:

read_memory<T>() - From Pointer

Reads a typed value from a pointer address.
const void*
required
Pointer to memory address
Returns: The value read from memory Source: memory_interface.hpp:40

read_memory() - Vector

Reads a buffer of bytes into a vector.
uint64_t
required
Memory address to read from
size_t
required
Number of bytes to read
Returns: Vector containing the read bytes Source: memory_interface.hpp:46 Example:

write_memory<T>() - Single Value

Writes a typed value to memory.
uint64_t
required
Memory address to write to
const T&
required
Value to write
Template Parameters:
  • T - Type of value to write
Source: memory_interface.hpp:61 Example:

write_memory<T>() - To Pointer

Writes a typed value to a pointer address.
void*
required
Pointer to memory address
const T&
required
Value to write
Source: memory_interface.hpp:67

write_memory() - Buffer to Pointer

Writes a buffer to a pointer address.
void*
required
Pointer to memory address
const void*
required
Pointer to data to write
size_t
required
Number of bytes to write
Source: memory_interface.hpp:73

Memory Operations

move_memory()

Moves memory from one location to another, handling overlapping regions correctly.
uint64_t
required
Destination address
uint64_t
required
Source address
size_t
required
Number of bytes to move
Source: memory_interface.hpp:78 Notes:
  • Handles overlapping source and destination correctly
  • Copies from end to start if src < dst to prevent data corruption
  • No-op if dst == src or size == 0

Private Virtual Methods

These methods are used internally by memory_manager and not intended for direct use:

map_mmio()

Maps a memory-mapped I/O region with custom read/write callbacks. Source: memory_interface.hpp:25

map_memory()

Maps a memory region with specified permissions. Source: memory_interface.hpp:26

unmap_memory()

Unmaps a previously mapped memory region. Source: memory_interface.hpp:27

apply_memory_protection()

Changes memory protection on an existing mapping. Source: memory_interface.hpp:29

memory_permission

Memory permission flags that can be combined with bitwise OR.

MMIO Callbacks

Callback types for memory-mapped I/O operations.

Usage Examples

Reading and Writing Values

Reading Buffers

Safe Memory Access

Moving Memory

Notes

  • All addresses are 64-bit virtual addresses
  • Memory reads/writes may throw if the memory is unmapped or protected
  • Use try_* variants for non-throwing operations
  • Template methods use sizeof(T) to determine the size automatically
  • The move_memory() function correctly handles overlapping regions
  • MMIO operations are typically managed by memory_manager, not called directly