public interface

ICallingConvention

com.pnfsoftware.jeb.core.units.code.asm.type.ICallingConvention
Known Indirect Subclasses

Class Overview

A calling convention object. Calling convention objects are immutable.

Notes:

  • support for multiple input and output entries
  • entries can be registers, register pairs, or stack slots
  • support for two register lists: general purpose and floating-point
  • the return-address location must be single-slot entry, either register or stack
  • register ids are well-defined in corresponding IRegisterBank implementations

Summary

Constants
int FLAG_COMPOSITE_INPUT_ON_STACK The flag indicates that all composite arguments (arrays, structures, unions) must go on the stack, regardless of registers declared to be holding storage items, if any.
int FLAG_FIRST_ARG_IS_THIS_POINTER The first argument must be a pointer to the object.
int FLAG_FLOAT_INPUT_ON_STACK The flag indicates that all float arguments must go on the stack, regardless of registers declared to be holding storage items, if any.
int FLAG_FORBID_PARAMS_2SLOTSUP 2+ slots (aka, multi-slot) parameters are disallowed.
int FLAG_FORBID_PARAMS_3SLOTSUP 3+ slots parameters are disallowed.
int FLAG_IPRD The flag indicates that the calling convention uses an implicit pointer as first parameter when the function prototype specifies that a "large" composite data type (some fundamental types, all aggregate types) is to be returned.
int FLAG_LINK_AFTER_INPUT This flag indicates that the return-address value is located after the input argument on the stack.
int FLAG_OUTPUT_AFTER_INPUT The flag indicates that output values are located on the pre-allocated stack slots located after the input values (whose count may not be known).
int FLAG_OUTPUT_PUSHED This flag indicates that the return values are to be pushed on the stack after return.
int FLAG_PARALLEL_INPUT_REGISTER_STACKS The indices in the lists of registers used to pass integral arguments and floating-point arguments grow together, in a parallel fashion.
int FLAG_SKIP_PASSED_INPUT_REGISTERS This flag indicates that candidate input registers that were passed over in favor of stack storage because they were not suitable for an argument at position N, will not be reused for an argument at a later position (>=N+1) even if that argument would be suitable for storage in an unused input register.
int FLAG_STACK_CLEANED_BY_CALLEE The flag indicates that the stack is cleaned by the callee (which is not the norm; if the flag is not set, it should be assumed the stack is cleaned by the caller).
Public Methods
abstract int determineSlotcountAlignment(int requestedSlotcount)
Determine the slotcount alignment requirement of a non-composite type.
abstract String format(int type)
abstract List<String> getAlternateNames()
Get a list of alternate names for this calling convention.
abstract List<CompilerType> getCompilerTypes()
Get the list of compiler types this calling convention may work with.
abstract int getFlags()
abstract ICallingConvention getIPRDConvention()
Retrieve the optional calling convention, derived from this convention, used to return large composite prototypes.
abstract StorageEntry getIPRDInputPtrEntry()
abstract int getIPRDMinimumSlotCount()
abstract StorageEntry getIPRDOutputPtrEntry()
abstract long getIdentifierKey()
Get an internally-generated identifier for this calling convention object.
abstract int getInputSlotCountHint()
Return the number of slots that are reserved for parameters.
abstract IStorageEntryGenerator getInputsGenerator()
Create a storage-location generator for the inputs provided to a routine using this calling convention.
abstract String getName()
Get the common name of this calling convention.
abstract List<String> getNames()
Retrieve all names for this calling convention (principal and alternates).
abstract String getNotes()
abstract StorageEntry getOutput(TypeLayoutInfo ti, int inputStackSlotCount)
Convenience method to retrieve the storage location of the single return value for this calling convention.
abstract int getOutputSlotCountHint()
Return the number of slots that are reserved for return values.
abstract IStorageEntryGenerator getOutputsGenerator(int inputStackSlotCount)
Create a storage-location generator for the outputs provided to a routine using this calling convention.
abstract List<ProcessorType> getProcessorTypes()
Get the list of processor types this calling convention may work with.
abstract Collection<Long> getPureSpoiledRegisters()
Get the list of registers that are spoiled by a callee, in the strictest sense, i.e.
abstract StorageEntry getReturnAddressSlot(Integer inputStackSlotCount)
abstract StorageEntry getReturnAddressSlot()
abstract Map<Integer, Integer> getSlotcountAlignmentMap()
Alignment specifications for non-composite types.
abstract Collection<Long> getSpoiledRegisters()
Get the list of all registers that may be modified and/or spoiled by a callee, in the most general sense.
abstract List<SubsystemType> getSubsystemTypes()
Get the list of subsystem types this calling convention may work with.
abstract boolean hasFlag(int f)
abstract boolean isCompatibleWith(ProcessorType wantedProcessor, SubsystemType wantedSubsystem, CompilerType wantedCompiler)
Determine whether this calling convention is compatible with the provided triple (processor, subsystem, compiler).
abstract boolean isStackCleanedByCallee()
Determine whether routine parameters pushed on stack before a routine call are cleaned by the callee.
abstract boolean isStackCleanedByCaller()
Determine whether routine parameters pushed on stack before a routine call are cleaned by the caller.
abstract boolean isUnknown()

Constants

public static final int FLAG_COMPOSITE_INPUT_ON_STACK

The flag indicates that all composite arguments (arrays, structures, unions) must go on the stack, regardless of registers declared to be holding storage items, if any. (I.e., input registers will be used for integral types, at least, not composite types.)

Constant Value: 4096 (0x00001000)

public static final int FLAG_FIRST_ARG_IS_THIS_POINTER

The first argument must be a pointer to the object. Typically, this flag is used by MSVC's __thiscall convention. Generally, it enforces the fact that the first parameter of a prototype must be a single-slot element (and more specifically, a pointer-type element.

Constant Value: 2048 (0x00000800)

public static final int FLAG_FLOAT_INPUT_ON_STACK

The flag indicates that all float arguments must go on the stack, regardless of registers declared to be holding storage items, if any. (I.e., input registers will be used for integral types, at least, not FP types.)

Constant Value: 64 (0x00000040)

public static final int FLAG_FORBID_PARAMS_2SLOTSUP

2+ slots (aka, multi-slot) parameters are disallowed. All inputs must fit on a single slot. Typically, such conventions require composite types to be passed by implicit reference.

Constant Value: 8192 (0x00002000)

public static final int FLAG_FORBID_PARAMS_3SLOTSUP

3+ slots parameters are disallowed. All inputs must fit on a 1 or 2 slots. Typically, such conventions require larger composite types to be passed by implicit reference.

Constant Value: 16384 (0x00004000)

public static final int FLAG_IPRD

The flag indicates that the calling convention uses an implicit pointer as first parameter when the function prototype specifies that a "large" composite data type (some fundamental types, all aggregate types) is to be returned. The return value is a pointer to that data. "IPRD" means Implicit Pointer to Return Data.

Example: this method, in x86:

 struct S1 {
     int a, b, c;
 };
 
 struct S1 __cdecl func(struct S1 x) {
     x.c += 1;
     return x;
 }
 
The explicit prototype and code:
 struct S1* __cdecl_iprd func(struct S1* prd, struct S1 x) {
     x.c += 1;
     copy(prd, &x);
     return prd;
 }
 

Constant Value: 256 (0x00000100)

public static final int FLAG_LINK_AFTER_INPUT

This flag indicates that the return-address value is located after the input argument on the stack.

Example:

 | ...
 | return addr
 | argN
 | (...)
 v arg1
 +-----------   <---- SP at routine entry
 
IMPORTANT: this flag requires that all calling convention elements (inputs, outputs, return address) be located on the stack.

Constant Value: 128 (0x00000080)

public static final int FLAG_OUTPUT_AFTER_INPUT

The flag indicates that output values are located on the pre-allocated stack slots located after the input values (whose count may not be known).

Example, when calling a function (int,int)->(int)

 v ...
 +-----------  (SP1)
 | ? retval1 (slot)
 | arg2
 | arg1
 v return addr
 +-----------   <---- SP at routine entry
 
If FLAG_STACK_CLEANED_BY_CALLEE is also set, the input values as well as the output values are 'cleared', i.e. the stack pointer would be expected to have the value SP1 when execution resumes to the return address.

IMPORTANT: this flag requires that all calling convention elements (inputs, outputs, return address) be located on the stack.

Constant Value: 32 (0x00000020)

public static final int FLAG_OUTPUT_PUSHED

This flag indicates that the return values are to be pushed on the stack after return. If it is combined with FLAG_STACK_CLEANED_BY_CALLEE, the input arguments are assumed to be cleaned before pushing the output.

Example, when calling a function (int,int)->(int):

 v ...
 +-----------  (SP1)
 | retaddr
 | arg2
 v arg1
 +-----------   <---- SP at routine entry
 
After execution:
 v ...
 +-----------  (SP1)
 | retval
 +-----------   <---- SP at return PC
 
IMPORTANT: this flag requires that all calling convention elements (inputs, outputs, return address) be located on the stack.

Constant Value: 512 (0x00000200)

public static final int FLAG_PARALLEL_INPUT_REGISTER_STACKS

The indices in the lists of registers used to pass integral arguments and floating-point arguments grow together, in a parallel fashion.

Example when calling a method: void f(int a, float b, int c, float d)

With the standard x86_64 Windows calling convention, arguments...

 - a would go in rcx
 - b would go in xmm1 (FP reg at index 1)
 - c would go in r8 (GP reg at index 2)
 - d would go in xmm3 (GP reg at index 3)
 

Here is an example of what happens when the general and FP register stacks used for arguments passing grow separately, as is the case for Linux x64, with the standard amd64 System V convention:

 - a would go in rdi
 - b would go in xmm0 (NOT xmm1) 
 - c would go in rsi (NOT rdx) 
 - d would go in xmm1 (NOT xmm3)
 

Constant Value: 1024 (0x00000400)

public static final int FLAG_SKIP_PASSED_INPUT_REGISTERS

This flag indicates that candidate input registers that were passed over in favor of stack storage because they were not suitable for an argument at position N, will not be reused for an argument at a later position (>=N+1) even if that argument would be suitable for storage in an unused input register.

An example of that is the x86 fastcall convention on Linux. The first two small integer integer parameters go in ecx and edx; others go on the stack. For a prototype like (int32 a, int64 b, int32 c), a goes in ecx, b on the stack, and c on the stack as well (even though it could fit in edx; note: x86 __fastcall on Windows does not skip over passed input registers; in this example, c would go in edx.}

Constant Value: 32768 (0x00008000)

public static final int FLAG_STACK_CLEANED_BY_CALLEE

The flag indicates that the stack is cleaned by the callee (which is not the norm; if the flag is not set, it should be assumed the stack is cleaned by the caller).

Note that a return-address value located on the stack is always pop'ed, regardless of the presence of this flag.

Constant Value: 1 (0x00000001)

Public Methods

public abstract int determineSlotcountAlignment (int requestedSlotcount)

Determine the slotcount alignment requirement of a non-composite type.

public abstract String format (int type)

Parameters
type 0: short-form (i.e., #toString()), 1: user-friendly long-form, 2: parseable yaml form

public abstract List<String> getAlternateNames ()

Get a list of alternate names for this calling convention.

public abstract List<CompilerType> getCompilerTypes ()

Get the list of compiler types this calling convention may work with.

public abstract int getFlags ()

public abstract ICallingConvention getIPRDConvention ()

Retrieve the optional calling convention, derived from this convention, used to return large composite prototypes. This only applies if the flag FLAG_IPRD was set.

Returns
  • a linked IPRD (Implicit Pointer to Return Data) convention, or null

public abstract StorageEntry getIPRDInputPtrEntry ()

public abstract int getIPRDMinimumSlotCount ()

public abstract StorageEntry getIPRDOutputPtrEntry ()

public abstract long getIdentifierKey ()

Get an internally-generated identifier for this calling convention object. The id is generated using:

  • the same names
  • same flags
  • same processor targets
  • same subsystem targets
  • same compiler targets

Returns
  • the key for this calling convention

public abstract int getInputSlotCountHint ()

Return the number of slots that are reserved for parameters. Note that this is just a hint on how many parameters are used.

public abstract IStorageEntryGenerator getInputsGenerator ()

Create a storage-location generator for the inputs provided to a routine using this calling convention. convention.

Returns
  • a generator

public abstract String getName ()

Get the common name of this calling convention.

public abstract List<String> getNames ()

Retrieve all names for this calling convention (principal and alternates).

public abstract String getNotes ()

public abstract StorageEntry getOutput (TypeLayoutInfo ti, int inputStackSlotCount)

Convenience method to retrieve the storage location of the single return value for this calling convention. Most calling conventions allow the return of a single value.

Parameters
ti storage type
inputStackSlotCount the number of stack slots used to provide input parameters (some calling conventions require that to calculate proper positioning for output values)

public abstract int getOutputSlotCountHint ()

Return the number of slots that are reserved for return values. Note that this is just a hint on how many return values are defined.

public abstract IStorageEntryGenerator getOutputsGenerator (int inputStackSlotCount)

Create a storage-location generator for the outputs provided to a routine using this calling convention.

Parameters
inputStackSlotCount optional value indicating how many stack slots were used to provide parameters (this value is the calling convention has the flags FLAG_OUTPUT_AFTER_INPUT or FLAG_OUTPUT_PUSHED)
Returns
  • a generator

public abstract List<ProcessorType> getProcessorTypes ()

Get the list of processor types this calling convention may work with.

public abstract Collection<Long> getPureSpoiledRegisters ()

Get the list of registers that are spoiled by a callee, in the strictest sense, i.e. their value may or may not be modified, but it is meaningless and should not be interpreted by the caller upon return. That set would NOT include return registers.

public abstract StorageEntry getReturnAddressSlot (Integer inputStackSlotCount)

public abstract StorageEntry getReturnAddressSlot ()

public abstract Map<Integer, Integer> getSlotcountAlignmentMap ()

Alignment specifications for non-composite types.

public abstract Collection<Long> getSpoiledRegisters ()

Get the list of all registers that may be modified and/or spoiled by a callee, in the most general sense. That set would include any type of return registers.

public abstract List<SubsystemType> getSubsystemTypes ()

Get the list of subsystem types this calling convention may work with.

public abstract boolean hasFlag (int f)

public abstract boolean isCompatibleWith (ProcessorType wantedProcessor, SubsystemType wantedSubsystem, CompilerType wantedCompiler)

Determine whether this calling convention is compatible with the provided triple (processor, subsystem, compiler).

Parameters
wantedProcessor mandatory (pass UNKNOWN if not known)
wantedSubsystem mandatory (pass UNKNOWN if not known)
wantedCompiler mandatory (pass UNKNOWN if not known)

public abstract boolean isStackCleanedByCallee ()

Determine whether routine parameters pushed on stack before a routine call are cleaned by the callee.

public abstract boolean isStackCleanedByCaller ()

Determine whether routine parameters pushed on stack before a routine call are cleaned by the caller.

public abstract boolean isUnknown ()