asmjit::FuncFrame Class Reference

Function frame.

Function frame is used directly by prolog and epilog insertion (PEI) utils. It provides information necessary to insert a proper and ABI comforming prolog and epilog. Function frame calculation is based on CallConv and other function attributes.

Function Frame Structure

Various properties can contribute to the size and structure of the function frame. The function frame in most cases won't use all of the properties illustrated (for example Spill Zone and Red Zone are never used together).

+-----------------------------+
| Arguments Passed by Stack |
+-----------------------------+
| Spill Zone |
+-----------------------------+ <- Stack offset (args) starts from here.
| Return Address, if Pushed |
+-----------------------------+ <- Stack pointer (SP) upon entry.
| Save/Restore Stack. |
+-----------------------------+-----------------------------+
| Local Stack | |
+-----------------------------+ Final Stack |
| Call Stack | |
+-----------------------------+-----------------------------+ <- SP after prolog.
| Red Zone |
+-----------------------------+

Public Members

Public Types

Member Functions

Construction & Destruction
Accessors
Finaliztion

Member Enumeration Documentation

FuncFrame::Tag : uint32_tenum

ConstantDescription
kTagInvalidOffset 

Tag used to inform that some offset is invalid.

FuncFrame::Attributes : uint32_tenum

Attributes are designed in a way that all are initially false, and user or FuncFrame finalizer adds them when necessary.

ConstantDescription
kAttrHasVarArgs 

Function has variable number of arguments.

kAttrHasPreservedFP 

Preserve frame pointer (don't omit FP).

kAttrHasFuncCalls 

Function calls other functions (is not leaf).

kAttrX86AvxEnabled 

Use AVX instead of SSE for all operations (X86).

kAttrX86AvxCleanup 

Emit VZEROUPPER instruction in epilog (X86).

kAttrX86MmxCleanup 

Emit EMMS instruction in epilog (X86).

kAttrAlignedVecSR 

Function has aligned save/restore of vector registers.

kAttrIsFinalized 

FuncFrame is finalized and can be used by PEI.

Member Function Documentation

uint32_t FuncFrame::arch() constnoexcept

Returns the target architecture of the function frame.

uint32_t FuncFrame::attributes() constnoexcept

Returns function frame attributes, see Attributes.

bool FuncFrame::hasAttribute(uint32_t attr) constnoexcept

Checks whether the FuncFame contains an attribute attr.

void FuncFrame::addAttributes(uint32_t attrs)noexcept

Adds attributes attrs to the FuncFrame.

void FuncFrame::clearAttributes(uint32_t attrs)noexcept

Clears attributes attrs from the FrameFrame.

bool FuncFrame::hasVarArgs() constnoexcept

Tests whether the function has variable number of arguments.

void FuncFrame::setVarArgs()noexcept

Sets the variable arguments flag.

void FuncFrame::resetVarArgs()noexcept

Resets variable arguments flag.

bool FuncFrame::hasPreservedFP() constnoexcept

Tests whether the function preserves frame pointer (EBP|ESP on X86).

void FuncFrame::setPreservedFP()noexcept

Enables preserved frame pointer.

void FuncFrame::resetPreservedFP()noexcept

Disables preserved frame pointer.

bool FuncFrame::hasFuncCalls() constnoexcept

Tests whether the function calls other functions.

void FuncFrame::setFuncCalls()noexcept

Sets kFlagHasCalls to true.

void FuncFrame::resetFuncCalls()noexcept

Sets kFlagHasCalls to false.

bool FuncFrame::hasAvxCleanup() constnoexcept

Tests whether the function contains AVX cleanup - 'vzeroupper' instruction in epilog.

void FuncFrame::setAvxCleanup()noexcept

Enables AVX cleanup.

void FuncFrame::resetAvxCleanup()noexcept

Disables AVX cleanup.

bool FuncFrame::isAvxEnabled() constnoexcept

Tests whether the function contains AVX cleanup - 'vzeroupper' instruction in epilog.

void FuncFrame::setAvxEnabled()noexcept

Enables AVX cleanup.

void FuncFrame::resetAvxEnabled()noexcept

Disables AVX cleanup.

bool FuncFrame::hasMmxCleanup() constnoexcept

Tests whether the function contains MMX cleanup - 'emms' instruction in epilog.

void FuncFrame::setMmxCleanup()noexcept

Enables MMX cleanup.

void FuncFrame::resetMmxCleanup()noexcept

Disables MMX cleanup.

bool FuncFrame::hasCallStack() constnoexcept

Tests whether the function uses call stack.

bool FuncFrame::hasLocalStack() constnoexcept

Tests whether the function uses local stack.

bool FuncFrame::hasAlignedVecSR() constnoexcept

Tests whether vector registers can be saved and restored by using aligned reads and writes.

bool FuncFrame::hasDynamicAlignment() constnoexcept

Tests whether the function has to align stack dynamically.

bool FuncFrame::hasRedZone() constnoexcept

Tests whether the calling convention specifies 'RedZone'.

bool FuncFrame::hasSpillZone() constnoexcept

Tests whether the calling convention specifies 'SpillZone'.

uint32_t FuncFrame::redZoneSize() constnoexcept

Returns the size of 'RedZone'.

uint32_t FuncFrame::spillZoneSize() constnoexcept

Returns the size of 'SpillZone'.

uint32_t FuncFrame::naturalStackAlignment() constnoexcept

Returns natural stack alignment (guaranteed stack alignment upon entry).

uint32_t FuncFrame::minDynamicAlignment() constnoexcept

Returns natural stack alignment (guaranteed stack alignment upon entry).

bool FuncFrame::hasCalleeStackCleanup() constnoexcept

Tests whether the callee must adjust SP before returning (X86-STDCALL only)

uint32_t FuncFrame::calleeStackCleanup() constnoexcept

Returns home many bytes of the stack the the callee must adjust before returning (X86-STDCALL only)

uint32_t FuncFrame::callStackAlignment() constnoexcept

Returns call stack alignment.

uint32_t FuncFrame::localStackAlignment() constnoexcept

Returns local stack alignment.

uint32_t FuncFrame::finalStackAlignment() constnoexcept

Returns final stack alignment (the maximum value of call, local, and natural stack alignments).

void FuncFrame::setCallStackAlignment(uint32_t alignment)noexcept

Sets call stack alignment.

Note
This also updates the final stack alignment.

void FuncFrame::setLocalStackAlignment(uint32_t value)noexcept

Sets local stack alignment.

Note
This also updates the final stack alignment.

void FuncFrame::updateCallStackAlignment(uint32_t alignment)noexcept

Combines call stack alignment with alignment, updating it to the greater value.

Note
This also updates the final stack alignment.

void FuncFrame::updateLocalStackAlignment(uint32_t alignment)noexcept

Combines local stack alignment with alignment, updating it to the greater value.

Note
This also updates the final stack alignment.

uint32_t FuncFrame::callStackSize() constnoexcept

Returns call stack size.

uint32_t FuncFrame::localStackSize() constnoexcept

Returns local stack size.

void FuncFrame::setCallStackSize(uint32_t size)noexcept

Sets call stack size.

void FuncFrame::setLocalStackSize(uint32_t size)noexcept

Sets local stack size.

void FuncFrame::updateCallStackSize(uint32_t size)noexcept

Combines call stack size with size, updating it to the greater value.

void FuncFrame::updateLocalStackSize(uint32_t size)noexcept

Combines local stack size with size, updating it to the greater value.

uint32_t FuncFrame::finalStackSize() constnoexcept

Returns final stack size (only valid after the FuncFrame is finalized).

uint32_t FuncFrame::localStackOffset() constnoexcept

Returns an offset to access the local stack (non-zero only if call stack is used).

bool FuncFrame::hasDAOffset() constnoexcept

Tests whether the function prolog/epilog requires a memory slot for storing unaligned SP.

uint32_t FuncFrame::daOffset() constnoexcept

Returns a memory offset used to store DA (dynamic alignment) slot (relative to SP).

uint32_t FuncFrame::dirtyRegs(uint32_t group) constnoexcept

Returns mask of registers of the given register group that are modified by the function.

The engine would then calculate which registers must be saved & restored by the function by using the data provided by the calling convention.

void FuncFrame::setDirtyRegs(uint32_t group, uint32_t regs)noexcept

Sets which registers (as a mask) are modified by the function.

Remarks
Please note that this will completely overwrite the existing register mask, use addDirtyRegs() to modify the existing register mask.

void FuncFrame::addDirtyRegs(uint32_t group, uint32_t regs)noexcept[1/3]

Adds which registers (as a mask) are modified by the function.

void FuncFrame::addDirtyRegs(const BaseReg& reg)noexcept[2/3]

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

template<typename... Args>
void FuncFrame::addDirtyRegs(const BaseReg& reg, Args&&... args)noexcept[3/3]

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

uint32_t FuncFrame::savedRegs(uint32_t group) constnoexcept

Returns a calculated mask of registers of the given group that will be saved and restored in the function's prolog and epilog, respectively.

The register mask is calculated from both dirtyRegs (provided by user) and preservedMask (provided by the calling convention).

uint32_t FuncFrame::preservedRegs(uint32_t group) constnoexcept

Returns the mask of preserved registers of the given register group.

Preserved registers are those that must survive the function call unmodified. The function can only modify preserved registers it they are saved and restored in funciton's prolog and epilog, respectively.

uint32_t FuncFrame::pushPopSaveSize() constnoexcept

Returns stack size required to save/restore registers via push/pop.

uint32_t FuncFrame::pushPopSaveOffset() constnoexcept

Returns an offset to the stack where registers are saved via push/pop.

uint32_t FuncFrame::extraRegSaveSize() constnoexcept

Returns stack size required to save/restore extra registers that don't use push/pop/.

Note
On X86 this covers all registers except GP registers, on other architectures it can be always zero (for example AArch64 saves all registers via push/pop like instructions, so this would be zero).

uint32_t FuncFrame::extraRegSaveOffset() constnoexcept

Returns an offset to the stack where extra registers are saved.

bool FuncFrame::hasStackAdjustment() constnoexcept

Tests whether the functions contains stack adjustment.

uint32_t FuncFrame::stackAdjustment() constnoexcept

Returns function's stack adjustment used in function's prolog and epilog.

If the returned value is zero it means that the stack is not adjusted. This can mean both that the stack is not used and/or the stack is only adjusted by instructions that pust/pop registers into/from stack.

Member Data Documentation

uint32_t FuncFrame::_attributes

Function attributes.

uint8_t FuncFrame::_arch

Architecture, see Environment::Arch.

uint8_t FuncFrame::_spRegId

SP register ID (to access call stack and local stack).

uint8_t FuncFrame::_saRegId

SA register ID (to access stack arguments).

uint8_t FuncFrame::_redZoneSize

Red zone size (copied from CallConv).

uint8_t FuncFrame::_spillZoneSize

Spill zone size (copied from CallConv).

uint8_t FuncFrame::_naturalStackAlignment

Natural stack alignment (copied from CallConv).

uint8_t FuncFrame::_minDynamicAlignment

Minimum stack alignment to turn on dynamic alignment.

uint8_t FuncFrame::_callStackAlignment

Call stack alignment.

uint8_t FuncFrame::_localStackAlignment

Local stack alignment.

uint8_t FuncFrame::_finalStackAlignment

Final stack alignment.

uint16_t FuncFrame::_calleeStackCleanup

Adjustment of the stack before returning (X86-STDCALL).

uint32_t FuncFrame::_callStackSize

Call stack size.

uint32_t FuncFrame::_localStackSize

Local stack size.

uint32_t FuncFrame::_finalStackSize

Final stack size (sum of call stack and local stack).

uint32_t FuncFrame::_localStackOffset

Local stack offset (non-zero only if call stack is used).

uint32_t FuncFrame::_daOffset

Offset relative to SP that contains previous SP (before alignment).

uint32_t FuncFrame::_saOffsetFromSP

Offset of the first stack argument relative to SP.

uint32_t FuncFrame::_saOffsetFromSA

Offset of the first stack argument relative to SA (_saRegId or FP).

uint32_t FuncFrame::_stackAdjustment

Local stack adjustment in prolog/epilog.

uint32_t FuncFrame::_dirtyRegs[BaseReg::kGroupVirt]

Registers that are dirty.

uint32_t FuncFrame::_preservedRegs[BaseReg::kGroupVirt]

Registers that must be preserved (copied from CallConv).

uint8_t FuncFrame::_saveRestoreRegSize[BaseReg::kGroupVirt]

Size to save/restore per register group.

uint8_t FuncFrame::_saveRestoreAlignment[BaseReg::kGroupVirt]

Alignment of save/restore area per register group.

uint16_t FuncFrame::_pushPopSaveSize

Stack size required to save registers with push/pop.

uint16_t FuncFrame::_extraRegSaveSize

Stack size required to save extra registers that cannot use push/pop.

uint32_t FuncFrame::_pushPopSaveOffset

Offset where registers saved/restored via push/pop are stored.

uint32_t FuncFrame::_extraRegSaveOffset

Offset where extra ragisters that cannot use push/pop are stored.