|
ReXGlue SDK
|
#include <rex/kernel/heap.h>
Public Types | |
| using | PhysicalMemoryInvalidationCallback |
Public Member Functions | |
| GuestAddressSpace () | |
| bool | Initialize () |
| const std::filesystem::path & | GetFileName () const |
| u8 * | GetVirtualMembase () const |
| rex::memory::GuestMembase | GetMembase () const |
| template<typename T = u8*> | |
| T | TranslateVirtual (u32 guest_address) const |
| template<typename T = u8*> | |
| T | TryTranslateVirtual (u32 guest_address, u32 required=kMemoryProtectRead) const |
| u8 * | GetPhysicalMembase () const |
| template<typename T = u8*> | |
| T | TranslatePhysical (u32 guest_address) const |
| u32 | HostToGuestVirtual (const void *host_address) const |
| u32 | GetPhysicalAddress (u32 address) const |
| void | Zero (u32 address, u32 size) const |
| void | Fill (u32 address, u32 size, u8 value) const |
| void | Copy (u32 dest, u32 src, u32 size) const |
| AccessViolationResult | HandleAccessViolation (void *host_address, bool is_write) |
| void * | RegisterPhysicalMemoryInvalidationCallback (PhysicalMemoryInvalidationCallback callback, void *callback_context) |
| void | UnregisterPhysicalMemoryInvalidationCallback (void *callback_handle) |
| void | EnablePhysicalMemoryAccessCallbacks (u32 physical_address, u32 length, bool enable_invalidation_notifications, bool enable_data_providers) |
| u32 | SystemHeapAlloc (u32 size, u32 alignment=0x20, u32 system_heap_flags=kSystemHeapDefault) override |
| void | SystemHeapFree (u32 address, u32 *out_region_size=nullptr) override |
| u32 | AllocPhysical (u32 size, u32 page_size, u32 protect, u32 min_address, u32 max_address, u32 alignment) override |
| bool | IsAddressMapped (u32 address) const override |
| const BaseHeap * | LookupHeap (u32 address) const |
| BaseHeap * | LookupHeap (u32 address) |
| BaseHeap * | LookupHeapByType (bool physical, u32 page_size) |
| void | GetHeapsPageStats (const BaseHeap *const *provided_heaps, size_t heaps_count, u32 &unreserved_pages, u32 &reserved_pages, u32 &used_pages, u32 &reserved_bytes) |
| VirtualHeap * | GetPhysicalHeap () |
| void | SetBudget (u32 megabytes) |
| u32 | GetTitlePages () const |
| u32 | GetBudgetPages () const |
| void | PlotProfile () |
| bool | InitializeFunctionTable (u32 code_base, u32 code_size, u32 image_base, u32 image_size) |
| bool | DestroyFunctionTable (u32 code_base) |
| bool | SetFunction (u32 guest_address, PPCFunc *host_function) |
| std::unique_lock< rex::platform::RankedMutex > | LockWatches () |
Friends | |
| class | BaseHeap |
| class | GuestAllocator |
| class | WorkspaceHeap |
| class | PhysicalHeap |
The guest address space, backed by a memory mapped file at a fixed host address. It is split into ranges, each a BaseHeap that is a VirtualHeap or a PhysicalHeap.
Callback for physical memory invalidation notifications. Callbacks are one shot, may fire spuriously or more than once, and fire only for accesses through the guest virtual views of physical memory, so a handler ignores pages it does not track and data providers write through the host physical heap. A triggered page is unwatched in one guest view until requested again. The granularity is 1 page, so a handler invalidates all data in every page from the one holding the first written byte to the one holding the last. A write fault unprotects the shortest range the callbacks return.
| context_ptr | The context given at registration. |
| length | The length of the watched region in bytes. |
| exact_range | True when only the exact range is being unwatched. |
| rex::kernel::GuestAddressSpace::GuestAddressSpace | ( | ) |
Constructs the memory system and registers it as the active instance.
|
overridevirtual |
Allocates contiguous physical memory for the title. SystemHeapFree releases it.
| size | The size in bytes, rounded up to the page size. |
| page_size | The page size in bytes: 4 KiB, 64 KiB or 16 MiB. |
| protect | MemoryProtectFlag bits. |
| min_address | The lowest acceptable physical address. |
| max_address | The highest acceptable physical address. |
| alignment | The alignment in bytes, rounded up to the page size. |
Implements rex::kernel::ISystemHeap.
| void rex::kernel::GuestAddressSpace::Copy | ( | u32 | dest, |
| u32 | src, | ||
| u32 | size ) const |
Copies a non overlapping range of guest memory, like memcpy.
| bool rex::kernel::GuestAddressSpace::DestroyFunctionTable | ( | u32 | code_base | ) |
Removes the function table of a module and releases its pages.
| code_base | The first guest address of the code, as given to InitializeFunctionTable. |
| void rex::kernel::GuestAddressSpace::EnablePhysicalMemoryAccessCallbacks | ( | u32 | physical_address, |
| u32 | length, | ||
| bool | enable_invalidation_notifications, | ||
| bool | enable_data_providers ) |
Enables physical memory access callbacks for a memory range, snapped to system page boundaries.
|
nodiscard |
|
inline |
Returns the path of the memory mapped file that backs all memory.
| void rex::kernel::GuestAddressSpace::GetHeapsPageStats | ( | const BaseHeap *const * | provided_heaps, |
| size_t | heaps_count, | ||
| u32 & | unreserved_pages, | ||
| u32 & | reserved_pages, | ||
| u32 & | used_pages, | ||
| u32 & | reserved_bytes ) |
| unreserved_pages | Receives the unreserved page count. |
| reserved_pages | Receives the reserved page count. |
| used_pages | Receives the used page count. |
| reserved_bytes | Receives the reserved size in bytes. |
|
inline |
Returns the translator for guest virtual addresses, which does not depend on this object.
| u32 rex::kernel::GuestAddressSpace::GetPhysicalAddress | ( | u32 | address | ) | const |
Returns the guest physical address for a guest virtual address, or UINT32_MAX when it cannot be obtained.
|
nodiscard |
Returns the title pages counted against the budget. The count is in 4 KB units.
| AccessViolationResult rex::kernel::GuestAddressSpace::HandleAccessViolation | ( | void * | host_address, |
| bool | is_write ) |
Resolves a host access violation inside guest memory.
| host_address | The host address the access faulted on. |
| is_write | True when the access was a write. |
| u32 rex::kernel::GuestAddressSpace::HostToGuestVirtual | ( | const void * | host_address | ) | const |
Translates a host address to a guest virtual address.
| bool rex::kernel::GuestAddressSpace::Initialize | ( | ) |
Initializes the memory system.
| bool rex::kernel::GuestAddressSpace::InitializeFunctionTable | ( | u32 | code_base, |
| u32 | code_size, | ||
| u32 | image_base, | ||
| u32 | image_size ) |
Initializes the per module function dispatch table at IMAGE_BASE + IMAGE_SIZE, indexed by (guest_addr - code_base) * 2. The function table calls are internally locked and may be made from any thread.
| code_base | The first guest address of the code. |
|
inlineoverridevirtual |
Implements rex::kernel::ISystemHeap.
|
inlinenodiscard |
Takes the lock that guards the physical memory watch state of the heaps and of every registered invalidation callback client. It is a Leaf lock held while callbacks run, so callbacks take no other ranked lock.
| void rex::kernel::GuestAddressSpace::PlotProfile | ( | ) |
Plots heap, allocator pool and title memory use on the profiler graphs. Call it once per frame.
| void * rex::kernel::GuestAddressSpace::RegisterPhysicalMemoryInvalidationCallback | ( | PhysicalMemoryInvalidationCallback | callback, |
| void * | callback_context ) |
Registers a physical memory invalidation callback.
| void rex::kernel::GuestAddressSpace::SetBudget | ( | u32 | megabytes | ) |
Sets the title memory budget.
| megabytes | Budget in MiB, 0 for no cap. |
| bool rex::kernel::GuestAddressSpace::SetFunction | ( | u32 | guest_address, |
| PPCFunc * | host_function ) |
Sets the host function for a guest address.
|
overridevirtual |
Allocates virtual memory from the system heap, kept apart from title memory but reachable with normal guest virtual addresses.
| system_heap_flags | SystemHeapFlag bits. |
Implements rex::kernel::ISystemHeap.
|
overridevirtual |
Frees memory allocated with SystemHeapAlloc.
| out_region_size | Receives the size of the freed region. |
Implements rex::kernel::ISystemHeap.
|
inline |
Translates a guest physical address to a host pointer. The contents are big endian.
|
inline |
Translates a guest virtual address to a host address, with the arithmetic recompiled code uses. The contents at the host address are big endian.
|
inline |
Translates a guest virtual address to a host pointer only when the title could access it.
| required | The kMemoryProtect bits the page must grant, the read bit by default. |
| void rex::kernel::GuestAddressSpace::UnregisterPhysicalMemoryInvalidationCallback | ( | void * | callback_handle | ) |
Unregisters a callback added with RegisterPhysicalMemoryInvalidationCallback.
| callback_handle | The handle returned at registration. |