ReXGlue SDK
Loading...
Searching...
No Matches
rex::kernel::PhysicalHeap Class Reference

#include <rex/kernel/heap.h>

Inheritance diagram for rex::kernel::PhysicalHeap:
[legend]

Classes

struct  SystemPageFlagsBlock

Public Member Functions

void Initialize (kernel::GuestAddressSpace *memory, u8 *membase, HeapType heap_type, u32 heap_base, u32 heap_size, u32 page_size, VirtualHeap *parent_heap)
bool Alloc (u32 size, u32 alignment, u32 allocation_type, u32 protect, bool top_down, u32 *out_address) override
bool AllocFixed (u32 base_address, u32 size, u32 alignment, u32 allocation_type, u32 protect) override
bool AllocRange (u32 low_address, u32 high_address, u32 size, u32 alignment, u32 allocation_type, u32 protect, bool top_down, u32 *out_address) override
bool AllocSystemHeap (u32 size, u32 alignment, u32 allocation_type, u32 protect, bool top_down, u32 *out_address) override
bool Decommit (u32 address, u32 size) override
bool Release (u32 base_address, u32 *out_region_size=nullptr) override
bool Protect (u32 address, u32 size, u32 protect, u32 *old_protect=nullptr) override
void EnableAccessCallbacks (u32 physical_address, u32 length, bool enable_invalidation_notifications, bool enable_data_providers)
bool TriggerCallbacks (u32 virtual_address, u32 length, bool is_write, bool unwatch_exact_range, bool unprotect=true)
bool TriggerCallbacksLocked (u32 virtual_address, u32 length, bool is_write, bool unwatch_exact_range, bool unprotect=true)
u32 GetPhysicalAddress (u32 address) const
Public Member Functions inherited from rex::kernel::BaseHeap
virtual ~BaseHeap ()
u32 GetHeapBase () const
u32 GetHeapSize () const
u32 GetPageSize () const
HeapType GetHeapType () const
u32 GetHostAddressOffset () const
template<typename T = u8*>
T TranslateRelative (size_t relative_address) const
virtual void Dispose ()
u32 GetTotalPageCount () const
u32 GetUnreservedPageCount () const
u32 GetReservedPageCount () const
u32 GetCommittedPages () const
void PlotProfile () const
bool ReleaseRange (u32 address, u32 size, u32 *out_address, u32 *out_size)
bool QueryRegionInfo (u32 base_address, HeapAllocation *out_info)
bool QuerySize (u32 address, u32 *out_size)
bool QueryProtect (u32 address, u32 *out_protect)
rex::memory::PageAccess QueryRangeAccess (u32 low_address, u32 high_address)
rex::memory::PageAccess GetHostPageAccess (u32 host_page_number) const
bool ReapplyHostPageAccess (void *host_address, bool is_write)

Protected Member Functions

bool IsHostPageWriteWatched (u32 host_page_number) const override
std::unique_lock< rex::platform::RankedMutex > AcquireHostPageReconcileLock () const override
Protected Member Functions inherited from rex::kernel::BaseHeap
rex::memory::PageAccess GetHostPageGuestAccess (u32 host_page_number) const
bool SyncHostPageAccess (u32 start_page_number, u32 end_page_number)
u32 GetSystemRangeBase () const
bool AllocFixedLocked (u32 base_address, u32 size, u32 alignment, u32 allocation_type, u32 protect)
bool AllocRangeLocked (u32 low_address, u32 high_address, u32 size, u32 alignment, u32 allocation_type, u32 protect, bool top_down, u32 *out_address)
bool DecommitLocked (u32 address, u32 size)
bool ReleaseLocked (u32 address, u32 *out_region_size)
bool ReleaseRangeLocked (u32 address, u32 size, u32 *out_address, u32 *out_size)
bool ProtectLocked (u32 address, u32 size, u32 protect, u32 *old_protect)
bool CheckProtectRangeLocked (u32 address, u32 size, u32 *out_start_page, u32 *out_end_page)
void OnPageCommitted (u32 page_number)
void OnPageDecommitted (u32 page_number)
void Initialize (kernel::GuestAddressSpace *memory, u8 *membase, HeapType heap_type, u32 heap_base, u32 heap_size, u32 page_size, u32 host_address_offset=0)

Protected Attributes

VirtualHeap * parent_heap_
u32 system_page_size_
u32 system_page_count_
std::vector< SystemPageFlagsBlock > system_page_flags_
Protected Attributes inherited from rex::kernel::BaseHeap
kernel::GuestAddressSpace * memory_
u8 * membase_
HeapType heap_type_
u32 heap_base_
u32 heap_size_
u32 page_size_
u32 page_size_shift_ = 0
u32 host_address_offset_
u32 unreserved_page_count_ = 0
std::atomic< u32 > committed_pages_ {0}
const char * profile_pool_ = nullptr
const char * profile_plot_ = nullptr
std::recursive_mutex heap_mutex_
std::vector< PageEntry > page_table_

Detailed Description

A heap for memory mapped to physical ranges, used by hardware wired to memory. It allocates through a parent heap in the guest virtual address space, 1:1 with the physical address space.

Member Function Documentation

◆ AcquireHostPageReconcileLock()

std::unique_lock< rex::platform::RankedMutex > rex::kernel::PhysicalHeap::AcquireHostPageReconcileLock ( ) const
overrideprotectedvirtual

Takes the memory watch lock when this heap or its parent has guest pages smaller than host pages.

Returns
The held lock, or an empty lock when neither does.

Reimplemented from rex::kernel::BaseHeap.

◆ Alloc()

bool rex::kernel::PhysicalHeap::Alloc ( u32 size,
u32 alignment,
u32 allocation_type,
u32 protect,
bool top_down,
u32 * out_address )
overridevirtual

Allocates pages in the parent heap and maps them at the matching address of this heap.

Parameters
allocation_typeMemoryAllocationFlag bits.
protectMemoryProtectFlag bits.
top_downIgnored, allocation always runs from the top of the heap.
out_addressReceives the allocated guest address.

Reimplemented from rex::kernel::BaseHeap.

◆ AllocFixed()

bool rex::kernel::PhysicalHeap::AllocFixed ( u32 base_address,
u32 size,
u32 alignment,
u32 allocation_type,
u32 protect )
overridevirtual

Allocates pages at the given address in the parent heap and in this heap.

Parameters
base_addressGuest address to allocate at.
allocation_typeMemoryAllocationFlag bits.
protectMemoryProtectFlag bits.

Reimplemented from rex::kernel::BaseHeap.

◆ AllocRange()

bool rex::kernel::PhysicalHeap::AllocRange ( u32 low_address,
u32 high_address,
u32 size,
u32 alignment,
u32 allocation_type,
u32 protect,
bool top_down,
u32 * out_address )
overridevirtual

Allocates pages within an address range in the parent heap and in this heap.

Parameters
allocation_typeMemoryAllocationFlag bits.
protectMemoryProtectFlag bits.
top_downTrue to allocate from the top of the range.
out_addressReceives the allocated guest address.

Reimplemented from rex::kernel::BaseHeap.

◆ AllocSystemHeap()

bool rex::kernel::PhysicalHeap::AllocSystemHeap ( u32 size,
u32 alignment,
u32 allocation_type,
u32 protect,
bool top_down,
u32 * out_address )
overridevirtual

Allocates with Alloc, as physical heaps have no system portion.

Parameters
allocation_typeMemoryAllocationFlag bits.
protectMemoryProtectFlag bits.
top_downIgnored, allocation always runs from the top of the heap.
out_addressReceives the allocated guest address.

Reimplemented from rex::kernel::BaseHeap.

◆ Decommit()

bool rex::kernel::PhysicalHeap::Decommit ( u32 address,
u32 size )
overridevirtual

Decommits pages in the parent heap and in this heap, invalidating watched pages.

Reimplemented from rex::kernel::BaseHeap.

◆ EnableAccessCallbacks()

void rex::kernel::PhysicalHeap::EnableAccessCallbacks ( u32 physical_address,
u32 length,
bool enable_invalidation_notifications,
bool enable_data_providers )

Enables write invalidation notifications for the system pages of a physical range.

Parameters
enable_invalidation_notificationsTrue to notify when the title writes the range.
enable_data_providersTrue to enable data providers, which are unsupported.

◆ GetPhysicalAddress()

u32 rex::kernel::PhysicalHeap::GetPhysicalAddress ( u32 address) const

Translates a guest address in this heap to its physical address.

Returns
The physical address, offset by 0x1000 in the 0xE0000000 view.

◆ Initialize()

void rex::kernel::PhysicalHeap::Initialize ( kernel::GuestAddressSpace * memory,
u8 * membase,
HeapType heap_type,
u32 heap_base,
u32 heap_size,
u32 page_size,
VirtualHeap * parent_heap )

Initializes the heap properties and allocates the page table.

Parameters
heap_baseThe heap offset relative to membase.
parent_heapThe heap that performs allocation in the guest virtual address space.

◆ IsHostPageWriteWatched()

bool rex::kernel::PhysicalHeap::IsHostPageWriteWatched ( u32 host_page_number) const
overrideprotectedvirtual

Reports whether a host page is write watched, so SyncHostPageAccess must not restore write access to it. Only PhysicalHeap tracks this.

Returns
True when the page is watched.

Reimplemented from rex::kernel::BaseHeap.

◆ Protect()

bool rex::kernel::PhysicalHeap::Protect ( u32 address,
u32 size,
u32 protect,
u32 * old_protect = nullptr )
overridevirtual

Changes protection in the parent heap and in this heap, invalidating watched pages when the range becomes writable.

Parameters
protectMemoryProtectFlag bits.
old_protectReceives the previous protection.

Reimplemented from rex::kernel::BaseHeap.

◆ Release()

bool rex::kernel::PhysicalHeap::Release ( u32 base_address,
u32 * out_region_size = nullptr )
overridevirtual

Releases the region in the parent heap and in this heap, invalidating watched pages.

Parameters
out_region_sizeReceives the size of the released region.

Reimplemented from rex::kernel::BaseHeap.

◆ TriggerCallbacks()

bool rex::kernel::PhysicalHeap::TriggerCallbacks ( u32 virtual_address,
u32 length,
bool is_write,
bool unwatch_exact_range,
bool unprotect = true )

Triggers the physical memory access callbacks of the watched pages in a range.

Parameters
unwatch_exact_rangeTrue to unwatch only the requested range.
unprotectTrue to restore host write access.
Returns
True when any page in the range was watched.

Member Data Documentation

◆ parent_heap_

VirtualHeap* rex::kernel::PhysicalHeap::parent_heap_
protected

Virtual heap whose pages back this physical heap.

◆ system_page_count_

u32 rex::kernel::PhysicalHeap::system_page_count_
protected

Number of host pages that cover the heap including host_address_offset_.

◆ system_page_flags_

std::vector<SystemPageFlagsBlock> rex::kernel::PhysicalHeap::system_page_flags_
protected

The documentation for this class was generated from the following file: