Overview
TheMemory class models the entire Xbox 360 guest memory system, providing interfaces to both virtual and physical memory with TLB and page table management for allocation, mapping, and protection.
The memory is backed by a memory-mapped file and placed at a stable fixed host address (typically
0x100000000). This allows efficient guest-to-host address translation and easy sharing across subsystems.Memory Layout
The guest memory address space is split into several ranges with varying properties:- Virtual Heaps: Standard guest virtual address ranges
- Physical Heaps: Hardware-mapped memory for audio/graphics subsystems
- Each range has its own page size, caching strategy, and protection settings
Class Definition
Initialization
Memory()
Constructs a new Memory instance.Initialize()
Initializes the memory system by reserving host address space and setting up the memory-mapped file.true on success, false if host address space reservation or file mapping fails
Reset()
Resets all memory to zero and clears all allocations.Address Translation
TranslateVirtual()
Translates a guest virtual address to a host pointer.guest_address- Guest virtual address to translate
The contents at the translated host address are in big-endian byte order.
TranslatePhysical()
Translates a guest physical address to a host pointer.guest_address- Guest physical address to translate
HostToGuestVirtual()
Translates a host address back to a guest virtual address.host_address- Host pointer to translate
GetPhysicalAddress()
Returns the guest physical address for a given guest virtual address.address- Guest virtual address
UINT32_MAX if unavailable
Memory Operations
Zero()
Zeros out a range of guest memory.address- Starting guest addresssize- Number of bytes to zero
Fill()
Fills a range of guest memory with a byte value.address- Starting guest addresssize- Number of bytes to fillvalue- Byte value to write
Copy()
Copies a non-overlapping range of guest memory.dest- Destination guest addresssrc- Source guest addresssize- Number of bytes to copy
SearchAligned()
Searches for a sequence of dword values in big-endian order.start- Starting guest addressend- Ending guest addressvalues- Array of dword values to search forvalue_count- Number of values in the array
System Heap Allocation
SystemHeapAlloc()
Allocates virtual memory from the system heap for kernel structures and internal allocations.size- Number of bytes to allocatealignment- Alignment requirement (default: 32 bytes)system_heap_flags- Allocation flags (seeSystemHeapFlag)
SystemHeapFree()
Frees memory allocated withSystemHeapAlloc().
address- Guest address to free
Heap Management
LookupHeap()
Gets the heap containing the given address.address- Guest address to lookup
nullptr if not found
LookupHeapByType()
Gets a heap with specific properties.physical-truefor physical heap,falsefor virtualpage_size- Required page size
nullptr
GetPhysicalHeap()
Gets the physical base heap.MMIO (Memory-Mapped I/O)
AddVirtualMappedRange()
Defines an MMIO virtual address range with read/write callbacks.virtual_address- Starting virtual addressmask- Address masksize- Size of the rangecontext- User context pointer passed to callbacksread_callback- Callback for read operationswrite_callback- Callback for write operations
true on success
LookupVirtualMappedRange()
Gets the MMIO range for a virtual address.virtual_address- Address to lookup
nullptr
Physical Memory Callbacks
RegisterPhysicalMemoryInvalidationCallback()
Registers a callback for physical memory invalidation events.callback- Callback functioncallback_context- User context pointer
UnregisterPhysicalMemoryInvalidationCallback()
Unregisters a physical memory invalidation callback.callback_handle- Handle returned from registration
EnablePhysicalMemoryAccessCallbacks()
Enables physical memory access callbacks for a memory range.physical_address- Starting physical addresslength- Length of the rangeenable_invalidation_notifications- Enable write invalidation callbacksenable_data_providers- Enable data provider callbacks
Function Table API
These methods support static recompilation by providing a function dispatch table stored in guest memory at
IMAGE_BASE + IMAGE_SIZE.InitializeFunctionTable()
Initializes the function table region for recompiled code dispatch.code_base- Base address of code sectioncode_size- Size of code sectionimage_base- Base address of executable imageimage_size- Size of executable image
true on success, false if allocation fails
SetFunction()
Registers a host function for a guest address.guest_address- Guest address to maphost_function- Host function pointer
GetFunction()
Gets the registered host function for a guest address.guest_address- Guest address to lookup
nullptr if not registered
HasFunctionTable()
Checks if the function table has been initialized.true if initialized
Properties
file_name()
Gets the path to the memory-mapped backing file.virtual_membase()
Gets the base address of virtual memory in host address space.This is typically
0x100000000 on 64-bit systems.physical_membase()
Gets the base address of physical memory in host address space.This is typically
0x200000000 on 64-bit systems.