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

#include <rex/kernel/guest_allocator.h>

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

Classes

struct  AllocatorStats

Public Member Functions

 GuestAllocator (Key, GuestAddressSpace &memory, u32 base, u32 size, void *state, GuestPool pool)
u32 GetBase () const
u32 GetSize () const
GuestPool GetPool () const
bool Contains (u32 address) const
void * Allocate (u32 size)
void * Reallocate (void *block, u32 size)
void Free (void *block)
AllocatorStats GetStats () const
bool IsConsistent () const

Static Public Member Functions

static Result< std::unique_ptr< GuestAllocator > > Create (rex::kernel::GuestMemory &memory, u32 size, u32 alignment, bool physical, u32 page_size, u32 flags, GuestPool pool)
static const char * GetPoolPlotName (GuestPool pool)

Static Public Attributes

static constexpr u32 kBlockAlignment = 16

Friends

class rex::kernel::shim::GuestHeap

Additional Inherited Members

Protected Member Functions inherited from rex::NonCopyable
 NonCopyable (const NonCopyable &)=delete
NonCopyable & operator= (const NonCopyable &)=delete

Detailed Description

Reserves and commits a range of guest memory and serves blocks from it. The shim heap is its user.

Constructor & Destructor Documentation

◆ GuestAllocator()

rex::kernel::GuestAllocator::GuestAllocator ( Key ,
GuestAddressSpace & memory,
u32 base,
u32 size,
void * state,
GuestPool pool )

Wraps a committed range. Only Create can make the key.

Parameters
stateThe allocator state that Create built over the range.
poolThe pool the blocks are reported to.

Member Function Documentation

◆ Allocate()

void * rex::kernel::GuestAllocator::Allocate ( u32 size)
nodiscard

Allocates a block.

Returns
The host pointer of the block, or null when the range is exhausted.

◆ Create()

Result< std::unique_ptr< GuestAllocator > > rex::kernel::GuestAllocator::Create ( rex::kernel::GuestMemory & memory,
u32 size,
u32 alignment,
bool physical,
u32 page_size,
u32 flags,
GuestPool pool )
staticnodiscard

Reserves and commits a range and starts the allocator over it.

Parameters
memoryGuest memory, which must outlive the allocator.
physicalTrue to take the range from the physical heap, false for the virtual heap.
page_sizeThe page size that selects the heap, in bytes.
flagsAllocation type flags added to reserve and commit.
poolThe pool the blocks are reported to.
Returns
An error when the range cannot be committed or the allocator cannot start.

◆ Free()

void rex::kernel::GuestAllocator::Free ( void * block)

Frees a block.

Parameters
blockA pointer from Allocate, null for none.

◆ GetPoolPlotName()

const char * rex::kernel::GuestAllocator::GetPoolPlotName ( GuestPool pool)
staticnodiscard

Returns the name of the profiler graph that plots a pool, a string with static storage.

◆ Reallocate()

void * rex::kernel::GuestAllocator::Reallocate ( void * block,
u32 size )
nodiscard

Resizes a block, moving it when it cannot grow in place.

Parameters
blockA pointer from Allocate.
Returns
The host pointer of the resized block, or null when the range is exhausted and the block is left as it was.

Member Data Documentation

◆ kBlockAlignment

u32 rex::kernel::GuestAllocator::kBlockAlignment = 16
staticconstexpr

Alignment of every block in bytes.


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