Skip to content

Latest commit

 

History

History
33 lines (18 loc) · 2.72 KB

iii.3.41-ldftn.md

File metadata and controls

33 lines (18 loc) · 2.72 KB

III.3.41 ldftn – load method pointer

Format Assembly Format Description
FE 06 <T> ldftn method Push a pointer to a method referenced by method, on the stack.

Stack Transition:

… → …, ftn

Description:

The ldftn instruction pushes a method pointer (§II.14.5) to the native code implementing the method described by method (a metadata token, either a methoddef or methodref (see Partition II)), or to some other implementation-specific description of method (see Note) onto the stack). The value pushed can be called using the calli instruction if it references a managed method (or a stub that transitions from managed to unmanaged code). It may also be used to construct a delegate, stored in a variable, etc.

The CLI resolves the method pointer according to the rules specified in §I.12.4.1.3 (Computed destinations), except that the destination is computed with respect to the class specified by method.

The value returned points to native code (see Note) using the calling convention specified by method. Thus a method pointer can be passed to unmanaged native code (e.g., as a callback routine). Note that the address computed by this instruction can be to a thunk produced specially for this purpose (for example, to re-enter the CIL interpreter when a native version of the method isn't available).

[Note: There are many options for implementing this instruction. Conceptually, this instruction places on the virtual machine's evaluation stack a representation of the address of the method specified. In terms of native code this can be an address (as specified), a data structure that contains the address, or any value that can be used to compute the address, depending on the architecture of the underlying machine, the native calling conventions, and the implementation technology of the VES (JIT, interpreter, threaded code, etc.). end note]

Exceptions:

System.MethodAccessException can be thrown when there is an invalid attempt to access a non-public method.

Correctness:

Correct CIL requires that method is a valid methoddef or methodref token.

Verifiability:

Verification tracks the method signature (§I.8.6.1.5) of the value, which includes the number and types of parameters, the type of the this pointer (for an instance method), and the return type and the calling convention. [Note: the type of this pointer for an instance method is determined as described in §I.8.6.1.5 based on the resolved method definition. end note]

See also the newobj instruction.