PostgreSQL Source Code git master
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
llvm::backport::SectionMemoryManager Class Reference

#include <SectionMemoryManager.h>

Data Structures

struct  FreeMemBlock
 
struct  MemoryGroup
 
class  MemoryMapper
 

Public Types

enum class  AllocationPurpose { Code , ROData , RWData }
 

Public Member Functions

 SectionMemoryManager (MemoryMapper *MM=nullptr, bool ReserveAlloc=false)
 
 SectionMemoryManager (const SectionMemoryManager &)=delete
 
void operator= (const SectionMemoryManager &)=delete
 
 ~SectionMemoryManager () override
 
bool needsToReserveAllocationSpace () override
 Enable reserveAllocationSpace when requested. More...
 
virtual void reserveAllocationSpace (uintptr_t CodeSize, uint32_t CodeAlign, uintptr_t RODataSize, uint32_t RODataAlign, uintptr_t RWDataSize, uint32_t RWDataAlign) override
 
uint8_t * allocateCodeSection (uintptr_t Size, unsigned Alignment, unsigned SectionID, StringRef SectionName) override
 
uint8_t * allocateDataSection (uintptr_t Size, unsigned Alignment, unsigned SectionID, StringRef SectionName, bool IsReadOnly) override
 
bool finalizeMemory (std::string *ErrMsg=nullptr) override
 
virtual void invalidateInstructionCache ()
 

Private Member Functions

uint8_t * allocateSection (AllocationPurpose Purpose, uintptr_t Size, unsigned Alignment)
 
std::error_code applyMemoryGroupPermissions (MemoryGroup &MemGroup, unsigned Permissions)
 
bool hasSpace (const MemoryGroup &MemGroup, uintptr_t Size) const
 
void anchor () override
 

Private Attributes

MemoryGroup CodeMem
 
MemoryGroup RWDataMem
 
MemoryGroup RODataMem
 
MemoryMapperMMapper
 
std::unique_ptr< MemoryMapperOwnedMMapper
 
bool ReserveAllocation
 

Detailed Description

This is a simple memory manager which implements the methods called by the RuntimeDyld class to allocate memory for section-based loading of objects, usually those generated by the MCJIT execution engine.

This memory manager allocates all section memory as read-write. The RuntimeDyld will copy JITed section memory into these allocated blocks and perform any necessary linking and relocations.

Any client using this memory manager MUST ensure that section-specific page permissions have been applied before attempting to execute functions in the JITed object. Permissions can be applied either by calling MCJIT::finalizeObject or by calling SectionMemoryManager::finalizeMemory directly. Clients of MCJIT should call MCJIT::finalizeObject.

Definition at line 46 of file SectionMemoryManager.h.

Member Enumeration Documentation

◆ AllocationPurpose

This enum describes the various reasons to allocate pages from allocateMappedMemory.

Enumerator
Code 
ROData 
RWData 

Definition at line 50 of file SectionMemoryManager.h.

50 {
51 Code,
52 ROData,
53 RWData,
54 };

Constructor & Destructor Documentation

◆ SectionMemoryManager() [1/2]

llvm::backport::SectionMemoryManager::SectionMemoryManager ( MemoryMapper MM = nullptr,
bool  ReserveAlloc = false 
)

Creates a SectionMemoryManager instance with MM as the associated memory mapper. If MM is nullptr then a default memory mapper is used that directly calls into the operating system.

If ReserveAlloc is true all memory will be pre-allocated, and any attempts to allocate beyond pre-allocated memory will fail.

◆ SectionMemoryManager() [2/2]

llvm::backport::SectionMemoryManager::SectionMemoryManager ( const SectionMemoryManager )
delete

◆ ~SectionMemoryManager()

llvm::backport::SectionMemoryManager::~SectionMemoryManager ( )
override

Member Function Documentation

◆ allocateCodeSection()

uint8_t * llvm::backport::SectionMemoryManager::allocateCodeSection ( uintptr_t  Size,
unsigned  Alignment,
unsigned  SectionID,
StringRef  SectionName 
)
override

Allocates a memory block of (at least) the given size suitable for executable code.

The value of Alignment must be a power of two. If Alignment is zero a default alignment of 16 will be used.

◆ allocateDataSection()

uint8_t * llvm::backport::SectionMemoryManager::allocateDataSection ( uintptr_t  Size,
unsigned  Alignment,
unsigned  SectionID,
StringRef  SectionName,
bool  IsReadOnly 
)
override

Allocates a memory block of (at least) the given size suitable for executable code.

The value of Alignment must be a power of two. If Alignment is zero a default alignment of 16 will be used.

◆ allocateSection()

uint8_t * llvm::backport::SectionMemoryManager::allocateSection ( AllocationPurpose  Purpose,
uintptr_t  Size,
unsigned  Alignment 
)
private

◆ anchor()

void llvm::backport::SectionMemoryManager::anchor ( )
overrideprivate

◆ applyMemoryGroupPermissions()

std::error_code llvm::backport::SectionMemoryManager::applyMemoryGroupPermissions ( MemoryGroup MemGroup,
unsigned  Permissions 
)
private

◆ finalizeMemory()

bool llvm::backport::SectionMemoryManager::finalizeMemory ( std::string ErrMsg = nullptr)
override

Update section-specific memory permissions and other attributes.

This method is called when object loading is complete and section page permissions can be applied. It is up to the memory manager implementation to decide whether or not to act on this method. The memory manager will typically allocate all sections as read-write and then apply specific permissions when this method is called. Code sections cannot be executed until this function has been called. In addition, any cache coherency operations needed to reliably use the memory are also performed.

Returns
true if an error occurred, false otherwise.

◆ hasSpace()

bool llvm::backport::SectionMemoryManager::hasSpace ( const MemoryGroup MemGroup,
uintptr_t  Size 
) const
private

◆ invalidateInstructionCache()

virtual void llvm::backport::SectionMemoryManager::invalidateInstructionCache ( )
virtual

Invalidate instruction cache for code sections.

Some platforms with separate data cache and instruction cache require explicit cache flush, otherwise JIT code manipulations (like resolved relocations) will get to the data cache but not to the instruction cache.

This method is called from finalizeMemory.

◆ needsToReserveAllocationSpace()

bool llvm::backport::SectionMemoryManager::needsToReserveAllocationSpace ( )
inlineoverride

Enable reserveAllocationSpace when requested.

Definition at line 123 of file SectionMemoryManager.h.

References ReserveAllocation.

◆ operator=()

void llvm::backport::SectionMemoryManager::operator= ( const SectionMemoryManager )
delete

◆ reserveAllocationSpace()

virtual void llvm::backport::SectionMemoryManager::reserveAllocationSpace ( uintptr_t  CodeSize,
uint32_t  CodeAlign,
uintptr_t  RODataSize,
uint32_t  RODataAlign,
uintptr_t  RWDataSize,
uint32_t  RWDataAlign 
)
overridevirtual

Implements allocating all memory in a single block. This is required to limit memory offsets to fit the ARM ABI; large memory systems may otherwise allocate separate sections too far apart.

Field Documentation

◆ CodeMem

MemoryGroup llvm::backport::SectionMemoryManager::CodeMem
private

Definition at line 215 of file SectionMemoryManager.h.

◆ MMapper

MemoryMapper* llvm::backport::SectionMemoryManager::MMapper
private

Definition at line 218 of file SectionMemoryManager.h.

◆ OwnedMMapper

std::unique_ptr<MemoryMapper> llvm::backport::SectionMemoryManager::OwnedMMapper
private

Definition at line 219 of file SectionMemoryManager.h.

◆ ReserveAllocation

bool llvm::backport::SectionMemoryManager::ReserveAllocation
private

Definition at line 220 of file SectionMemoryManager.h.

Referenced by needsToReserveAllocationSpace().

◆ RODataMem

MemoryGroup llvm::backport::SectionMemoryManager::RODataMem
private

Definition at line 217 of file SectionMemoryManager.h.

◆ RWDataMem

MemoryGroup llvm::backport::SectionMemoryManager::RWDataMem
private

Definition at line 216 of file SectionMemoryManager.h.


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