Ark Server API (ASA) - Wiki
Loading...
Searching...
No Matches
FGenericPlatformMallocCrash Struct Referencefinal

#include <GenericPlatformMallocCrash.h>

+ Inheritance diagram for FGenericPlatformMallocCrash:
+ Collaboration diagram for FGenericPlatformMallocCrash:

Public Types

enum  {
  LARGE_MEMORYPOOL_SIZE = 2 * 1024 * 1024 , REQUIRED_ALIGNMENT = 16 , NUM_POOLS = 14 , MAX_NUM_ALLOCS_IN_POOL = 2048 ,
  MEM_TAG = 0xfe , MEM_WIPETAG = 0xcd
}
 

Public Member Functions

 FGenericPlatformMallocCrash (FMalloc *MainMalloc)
 
virtual ~FGenericPlatformMallocCrash ()
 
void SetAsGMalloc ()
 
virtual voidMalloc (SIZE_T Size, uint32 Alignment) override
 
virtual voidRealloc (void *Ptr, SIZE_T NewSize, uint32 Alignment) override
 
virtual void Free (void *) override
 
virtual bool GetAllocationSize (void *Original, SIZE_T &SizeOut) override
 
virtual bool IsInternallyThreadSafe () const override
 
virtual bool ValidateHeap () override
 
virtual const TCHAR * GetDescriptiveName () override
 
void PrintPoolsUsage ()
 
- Public Member Functions inherited from FMalloc
virtual voidTryMalloc (SIZE_T Count, uint32 Alignment=DEFAULT_ALIGNMENT)
 
virtual voidTryRealloc (void *Original, SIZE_T Count, uint32 Alignment=DEFAULT_ALIGNMENT)
 
virtual SIZE_T QuantizeSize (SIZE_T Count, uint32 Alignment)
 
virtual void Trim (bool bTrimThreadCaches)
 
virtual void SetupTLSCachesOnCurrentThread ()
 
virtual void ClearAndDisableTLSCachesOnCurrentThread ()
 
virtual void InitializeStatsMetadata ()
 
virtual void UpdateStats ()
 
virtual void GetAllocatorStats (FGenericMemoryStats &out_Stats)
 
virtual void DumpAllocatorStats (class FOutputDevice &Ar)
 
virtual void OnMallocInitialized ()
 
virtual void OnPreFork ()
 
virtual void OnPostFork ()
 
- Public Member Functions inherited from FUseSystemMallocForNew
voidoperator new (size_t Size)
 
void operator delete (void *Ptr)
 
voidoperator new[] (size_t Size)
 
void operator delete[] (void *Ptr)
 
- Public Member Functions inherited from FExec
virtual ~FExec ()
 
virtual bool Exec (UWorld *InWorld, const TCHAR *Cmd, FOutputDevice &Ar)
 

Static Public Member Functions

static FGenericPlatformMallocCrashGet (FMalloc *MainMalloc=nullptr)
 

Protected Member Functions

bool IsOnCrashedThread () const
 
bool IsPtrInLargePool (void *Ptr) const
 
bool IsPtrInSmallPool (void *Ptr) const
 
const FPoolDescGetPoolDesc (uint32 Index) const
 
uint32 CalculateSmallPoolTotalSize () const
 
uint32 CalculateBookkeepingPoolTotalSize () const
 
void InitializeSmallPools ()
 
FMallocCrashPoolChoosePoolForSize (uint32 AllocationSize) const
 
FMallocCrashPoolFindPoolForAlloc (void *Ptr) const
 
uint8AllocateFromBookkeeping (uint32 AllocationSize)
 
uint8AllocateFromSmallPool (uint32 AllocationSize)
 
uint64 GetAllocationSize (void *Original)
 
- Protected Member Functions inherited from FExec
virtual bool Exec_Dev (UWorld *InWorld, const TCHAR *Cmd, FOutputDevice &Ar)
 
virtual bool Exec_Editor (UWorld *InWorld, const TCHAR *Cmd, FOutputDevice &Ar)
 

Static Protected Member Functions

static uint32 SafePageSize ()
 

Protected Attributes

FCriticalSection InternalLock
 
int32 CrashedThreadId = 0
 
uint8LargeMemoryPool = nullptr
 
uint32 LargeMemoryPoolOffset = 0
 
uint8SmallMemoryPool = nullptr
 
uint32 SmallMemoryPoolOffset = 0
 
uint32 SmallMemoryPoolSize = 0
 
uint8BookkeepingPool = nullptr
 
uint32 BookkeepingPoolOffset = 0
 
uint32 BookkeepingPoolSize = 0
 
FMallocPreviousMalloc = nullptr
 

Friends

struct FPoolDesc
 
struct FMallocCrashPool
 

Additional Inherited Members

- Static Public Attributes inherited from FMalloc
static TAtomic< uint64MaxSingleAlloc
 

Detailed Description

Simple pooled memory allocator that uses preallocated memory. Instance of this class replaces GMalloc after a crash, so we can use dynamic memory allocation even if the app crashes due to OOM.

Definition at line 43 of file GenericPlatformMallocCrash.h.

Member Enumeration Documentation

◆ anonymous enum

Enumerator
LARGE_MEMORYPOOL_SIZE 
REQUIRED_ALIGNMENT 
NUM_POOLS 
MAX_NUM_ALLOCS_IN_POOL 
MEM_TAG 
MEM_WIPETAG 

Definition at line 48 of file GenericPlatformMallocCrash.h.

Constructor & Destructor Documentation

◆ FGenericPlatformMallocCrash()

FGenericPlatformMallocCrash::FGenericPlatformMallocCrash ( FMalloc * MainMalloc)

◆ ~FGenericPlatformMallocCrash()

virtual FGenericPlatformMallocCrash::~FGenericPlatformMallocCrash ( )
virtual

Member Function Documentation

◆ AllocateFromBookkeeping()

uint8 * FGenericPlatformMallocCrash::AllocateFromBookkeeping ( uint32 AllocationSize)
protected

◆ AllocateFromSmallPool()

uint8 * FGenericPlatformMallocCrash::AllocateFromSmallPool ( uint32 AllocationSize)
protected

◆ CalculateBookkeepingPoolTotalSize()

uint32 FGenericPlatformMallocCrash::CalculateBookkeepingPoolTotalSize ( ) const
protected

◆ CalculateSmallPoolTotalSize()

uint32 FGenericPlatformMallocCrash::CalculateSmallPoolTotalSize ( ) const
protected

◆ ChoosePoolForSize()

FMallocCrashPool * FGenericPlatformMallocCrash::ChoosePoolForSize ( uint32 AllocationSize) const
protected

◆ FindPoolForAlloc()

FMallocCrashPool * FGenericPlatformMallocCrash::FindPoolForAlloc ( void * Ptr) const
protected

◆ Free()

virtual void FGenericPlatformMallocCrash::Free ( void * Original)
overridevirtual

Free

Implements FMalloc.

◆ Get()

static FGenericPlatformMallocCrash & FGenericPlatformMallocCrash::Get ( FMalloc * MainMalloc = nullptr)
static

Creates a new instance.

◆ GetAllocationSize() [1/2]

uint64 FGenericPlatformMallocCrash::GetAllocationSize ( void * Original)
protected

◆ GetAllocationSize() [2/2]

virtual bool FGenericPlatformMallocCrash::GetAllocationSize ( void * Original,
SIZE_T & SizeOut )
overridevirtual

If possible determine the size of the memory allocated at the given address

Parameters
Original- Pointer to memory we are checking the size of
SizeOut- If possible, this value is set to the size of the passed in pointer
Returns
true if succeeded

Reimplemented from FMalloc.

◆ GetDescriptiveName()

virtual const TCHAR * FGenericPlatformMallocCrash::GetDescriptiveName ( )
inlineoverridevirtual

Gets descriptive name for logging purposes.

Returns
pointer to human-readable malloc name

Reimplemented from FMalloc.

Definition at line 100 of file GenericPlatformMallocCrash.h.

◆ GetPoolDesc()

const FPoolDesc & FGenericPlatformMallocCrash::GetPoolDesc ( uint32 Index) const
protected

◆ InitializeSmallPools()

void FGenericPlatformMallocCrash::InitializeSmallPools ( )
protected

◆ IsInternallyThreadSafe()

virtual bool FGenericPlatformMallocCrash::IsInternallyThreadSafe ( ) const
inlineoverridevirtual

Returns if the allocator is guaranteed to be thread-safe and therefore doesn't need a unnecessary thread-safety wrapper around it.

Reimplemented from FMalloc.

Definition at line 89 of file GenericPlatformMallocCrash.h.

◆ IsOnCrashedThread()

bool FGenericPlatformMallocCrash::IsOnCrashedThread ( ) const
protected

Whether it is safe to call crash malloc's methods.

◆ IsPtrInLargePool()

bool FGenericPlatformMallocCrash::IsPtrInLargePool ( void * Ptr) const
protected

◆ IsPtrInSmallPool()

bool FGenericPlatformMallocCrash::IsPtrInSmallPool ( void * Ptr) const
protected

◆ Malloc()

virtual void * FGenericPlatformMallocCrash::Malloc ( SIZE_T Count,
uint32 Alignment )
overridevirtual

Malloc

Implements FMalloc.

◆ PrintPoolsUsage()

void FGenericPlatformMallocCrash::PrintPoolsUsage ( )

◆ Realloc()

virtual void * FGenericPlatformMallocCrash::Realloc ( void * Original,
SIZE_T Count,
uint32 Alignment )
overridevirtual

Realloc

Implements FMalloc.

◆ SafePageSize()

static uint32 FGenericPlatformMallocCrash::SafePageSize ( )
staticprotected
Returns
page size, if page size is not initialized, returns 64k.

◆ SetAsGMalloc()

void FGenericPlatformMallocCrash::SetAsGMalloc ( )

Sets as GMalloc. This method locks to the thread that crashed. Any next calls to this method or GMalloc from other threads will dead-lock those threads, but this is ok, because we are shutting down. This also fixes a lot of potential issues of using dynamic allocation during crash dumping.

Warning
This is not super safe, may interfere with other allocations, ie. replacing vtable during running the code from the previous malloc will probably crash other threads.

◆ ValidateHeap()

virtual bool FGenericPlatformMallocCrash::ValidateHeap ( )
inlineoverridevirtual

Validates the allocator's heap

Reimplemented from FMalloc.

Definition at line 94 of file GenericPlatformMallocCrash.h.

Friends And Related Symbol Documentation

◆ FMallocCrashPool

friend struct FMallocCrashPool
friend

Definition at line 46 of file GenericPlatformMallocCrash.h.

◆ FPoolDesc

friend struct FPoolDesc
friend

Definition at line 45 of file GenericPlatformMallocCrash.h.

Member Data Documentation

◆ BookkeepingPool

uint8* FGenericPlatformMallocCrash::BookkeepingPool = nullptr
protected

Preallocated memory pool for bookkeeping.

Definition at line 155 of file GenericPlatformMallocCrash.h.

◆ BookkeepingPoolOffset

uint32 FGenericPlatformMallocCrash::BookkeepingPoolOffset = 0
protected

Current position in the bookkeeping pool.

Definition at line 158 of file GenericPlatformMallocCrash.h.

◆ BookkeepingPoolSize

uint32 FGenericPlatformMallocCrash::BookkeepingPoolSize = 0
protected

Definition at line 159 of file GenericPlatformMallocCrash.h.

◆ CrashedThreadId

int32 FGenericPlatformMallocCrash::CrashedThreadId = 0
protected

The id of the thread that crashed.

Definition at line 139 of file GenericPlatformMallocCrash.h.

◆ InternalLock

FCriticalSection FGenericPlatformMallocCrash::InternalLock
protected

Used to lock crash malloc to one thread.

Definition at line 136 of file GenericPlatformMallocCrash.h.

◆ LargeMemoryPool

uint8* FGenericPlatformMallocCrash::LargeMemoryPool = nullptr
protected

Preallocated memory pool for large allocations.

Definition at line 142 of file GenericPlatformMallocCrash.h.

◆ LargeMemoryPoolOffset

uint32 FGenericPlatformMallocCrash::LargeMemoryPoolOffset = 0
protected

Current position in the large memory pool.

Definition at line 145 of file GenericPlatformMallocCrash.h.

◆ PreviousMalloc

FMalloc* FGenericPlatformMallocCrash::PreviousMalloc = nullptr
protected

Previously used malloc.

Definition at line 162 of file GenericPlatformMallocCrash.h.

◆ SmallMemoryPool

uint8* FGenericPlatformMallocCrash::SmallMemoryPool = nullptr
protected

Preallocated memory pool for small allocations.

Definition at line 148 of file GenericPlatformMallocCrash.h.

◆ SmallMemoryPoolOffset

uint32 FGenericPlatformMallocCrash::SmallMemoryPoolOffset = 0
protected

Current position in the small memory pool.

Definition at line 151 of file GenericPlatformMallocCrash.h.

◆ SmallMemoryPoolSize

uint32 FGenericPlatformMallocCrash::SmallMemoryPoolSize = 0
protected

Definition at line 152 of file GenericPlatformMallocCrash.h.


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