Calling Conventions in Managed Code

Once the CIL has been verified and compiled, the native code for the method can be safely executed. Since the CLI, like every modern execution environment, supports programming languages that use recursion, the stack is used to track execution state. Every method call has an activation record on this stack containing its arguments, return value, local variables, and other bookkeeping information such as a security object (which is used by the code access security engine). The structure of Rotor’s activation records is shown for both Intel x86 processors and Motorola PowerPC processors in Figure 5-7.

Elements of an SSCLI stack frame, for the X86 and PPC architectures

Figure 5-7. Elements of an SSCLI stack frame, for the X86 and PPC architectures

As methods call other methods, the stack is maintained cooperatively using a variety of calling conventions. All calls begin with the setup of the callsite (the stack context associated with a method call by the caller). Parameters are always a part of the callsite, since they can clearly be pushed only by the caller because the method being called knows nothing of them. Past this, however, different calling conventions use different mechanisms; why they differ is often a matter of history, of small performance gains, or of codified personal tastes, and their differences can seem quite arbitrary. Nonetheless, they exist, and how they interoperate in the SSCLI is described in ...

Get Shared Source CLI Essentials now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.