# Interface: com.pnfsoftware.jeb.core.units.code.asm.type.ICallingConvention

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](IRegisterBank) implementations

## Static Field: FLAG_COMPOSITE_INPUT_ON_STACK
Type: `int`

Constant value: `4096`
Description: 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.\)

## Static Field: FLAG_FIRST_ARG_IS_THIS_POINTER
Type: `int`

Constant value: `2048`
Description: 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](TypeLayoutInfo#ptr)\-type element.

## Static Field: FLAG_FLOAT_INPUT_ON_STACK
Type: `int`

Constant value: `64`
Description: 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.\)

## Static Field: FLAG_FORBID_PARAMS_2SLOTSUP
Type: `int`

Constant value: `8192`
Description: 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.

## Static Field: FLAG_FORBID_PARAMS_3SLOTSUP
Type: `int`

Constant value: `16384`
Description: 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.

## Static Field: FLAG_IPRD
Type: `int`

Constant value: `256`
Description: 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;**
 }
 
```

## Static Field: FLAG_LINK_AFTER_INPUT
Type: `int`

Constant value: `128`
Description: 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.**

## Static Field: FLAG_OUTPUT_AFTER_INPUT
Type: `int`

Constant value: `32`
Description: 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](#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.**

## Static Field: FLAG_OUTPUT_PUSHED
Type: `int`

Constant value: `512`
Description: 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](#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.**

## Static Field: FLAG_PARALLEL_INPUT_REGISTER_STACKS
Type: `int`

Constant value: `1024`
Description: 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)
 
```

## Static Field: FLAG_SKIP_PASSED_INPUT_REGISTERS
Type: `int`

Constant value: `32768`
Description: 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`.}

## Static Field: FLAG_STACK_CLEANED_BY_CALLEE
Type: `int`

Constant value: `1`
Description: 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.

## Method: determineSlotcountAlignment
- parameter: `requestedSlotcount`, type: `int`
- return type: `int`

Description: Determine the slotcount alignment requirement of a non\-[composite](TypeCategory#COMPOSITE) type.
parameter: requestedSlotcount: requested slot count
return: aligned slot count

## Method: format
- parameter: `type`, type: `int`
- return type: `java.lang.String`

Description: Format this calling convention.
parameter: type: 0: short\-form \(i.e., `toString()`\), 1: user\-friendly long\-form, 2:            parseable yaml form
return: formatted convention

## Method: getAlternateNames
- return type: `java.util.List<java.lang.String>`

Description: Get a list of alternate names for this calling convention.
return: alternate names

## Method: getCompilerTypes
- return type: `java.util.List<com.pnfsoftware.jeb.core.units.codeobject.CompilerType>`

Description: Get the list of compiler types this calling convention may work with.
return: compiler type list

## Method: getFlags
- return type: `int`

Description: Retrieve convention flags.
return: flags

## Method: getIPRDConvention
- return type: `com.pnfsoftware.jeb.core.units.code.asm.type.ICallingConvention`

Description: Retrieve the optional calling convention, derived from this convention, used to return large composite prototypes. This only applies if the flag [#FLAG_IPRD](#FLAG_IPRD) was set.
return: a linked IPRD \(Implicit Pointer to Return Data\) convention, or null

## Method: getIPRDInputPtrEntry
- return type: `com.pnfsoftware.jeb.core.units.code.asm.type.StorageEntry`

Description: Retrieve the implicit input pointer storage entry.
return: input pointer storage entry

## Method: getIPRDMinimumSlotCount
- return type: `int`

Description: Retrieve the minimum slot count for implicit pointer\-to\-return\-data handling.
return: minimum slot count

## Method: getIPRDOutputPtrEntry
- return type: `com.pnfsoftware.jeb.core.units.code.asm.type.StorageEntry`

Description: Retrieve the implicit output pointer storage entry.
return: output pointer storage entry

## Method: getIdentifierKey
- return type: `long`

Description: 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
return: the key for this calling convention

## Method: getInputSlotCountHint
- return type: `int`

Description: Return the number of slots that are reserved for parameters. Note that this is just a hint on how many parameters are used.
return: input slot count hint

## Method: getInputsGenerator
- return type: `com.pnfsoftware.jeb.core.units.code.asm.type.IStorageEntryGenerator`

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

## Method: getName
- return type: `java.lang.String`

Description: Get the common name of this calling convention.
return: principal name

## Method: getNames
- return type: `java.util.List<java.lang.String>`

Description: Retrieve all names for this calling convention \(principal and alternates\).
return: principal and alternate names

## Method: getNotes
- return type: `java.lang.String`

Description: Retrieve implementation notes.
return: notes, or null

## Method: getOutput
- parameter: `ti`, type: `com.pnfsoftware.jeb.core.units.code.asm.type.TypeLayoutInfo`
- parameter: `inputStackSlotCount`, type: `int`
- return type: `com.pnfsoftware.jeb.core.units.code.asm.type.StorageEntry`

Description: 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.
parameter: ti: storage type
parameter: inputStackSlotCount: the number of stack slots used to provide input parameters \(some            calling conventions require that to calculate proper positioning for output            values\)
return: output storage entry, or null

## Method: getOutputSlotCountHint
- return type: `int`

Description: 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.
return: output slot count hint

## Method: getOutputsGenerator
- parameter: `inputStackSlotCount`, type: `int`
- return type: `com.pnfsoftware.jeb.core.units.code.asm.type.IStorageEntryGenerator`

Description: Create a storage\-location generator for the outputs provided to a routine using this calling convention.
parameter: 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](#FLAG_OUTPUT_AFTER_INPUT) or [#FLAG_OUTPUT_PUSHED](#FLAG_OUTPUT_PUSHED)\)
return: a generator

## Method: getProcessorTypes
- return type: `java.util.List<com.pnfsoftware.jeb.core.units.codeobject.ProcessorType>`

Description: Get the list of processor types this calling convention may work with.
return: processor type list

## Method: getPureSpoiledRegisters
- return type: `java.util.Collection<java.lang.Long>`

Description: 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.
return: pure spoiled register ids

## Method: getReturnAddressSlot
- return type: `com.pnfsoftware.jeb.core.units.code.asm.type.StorageEntry`

Description: Retrieve the return\-address storage slot.
return: return\-address storage slot

## Method: getReturnAddressSlot
- parameter: `inputStackSlotCount`, type: `java.lang.Integer`
- return type: `com.pnfsoftware.jeb.core.units.code.asm.type.StorageEntry`

Description: Retrieve the return\-address storage slot.
parameter: inputStackSlotCount: input stack slot count
return: return\-address storage slot

## Method: getSlotcountAlignmentMap
- return type: `java.util.Map<java.lang.Integer,java.lang.Integer>`

Description: Alignment specifications for non\-[composite](TypeCategory#COMPOSITE) types.
return: slot\-count alignment map

## Method: getSpoiledRegisters
- return type: `java.util.Collection<java.lang.Long>`

Description: 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.
return: spoiled register ids

## Method: getSubsystemTypes
- return type: `java.util.List<com.pnfsoftware.jeb.core.units.codeobject.SubsystemType>`

Description: Get the list of subsystem types this calling convention may work with.
return: subsystem type list

## Method: hasFlag
- parameter: `f`, type: `int`
- return type: `boolean`

Description: Determine whether a flag is set.
parameter: f: flag to test
return: true if the flag is set

## Method: isCompatibleWith
- parameter: `wantedProcessor`, type: `com.pnfsoftware.jeb.core.units.codeobject.ProcessorType`
- parameter: `wantedSubsystem`, type: `com.pnfsoftware.jeb.core.units.codeobject.SubsystemType`
- parameter: `wantedCompiler`, type: `com.pnfsoftware.jeb.core.units.codeobject.CompilerType`
- return type: `boolean`

Description: Determine whether this calling convention is compatible with the provided triple \(processor, subsystem, compiler\).
parameter: wantedProcessor: mandatory \(pass UNKNOWN if not known\)
parameter: wantedSubsystem: mandatory \(pass UNKNOWN if not known\)
parameter: wantedCompiler: mandatory \(pass UNKNOWN if not known\)
return: true if this convention is compatible

## Method: isStackCleanedByCallee
- return type: `boolean`

Description: Determine whether routine parameters pushed on stack before a routine call are cleaned by the callee.
return: true if callees clean stack parameters

## Method: isStackCleanedByCaller
- return type: `boolean`

Description: Determine whether routine parameters pushed on stack before a routine call are cleaned by the caller.
return: true if callers clean stack parameters

## Method: isUnknown
- return type: `boolean`

Description: Determine whether this is the unknown calling convention.
return: true if this convention is unknown

