LLMpediaThe first transparent, open encyclopedia generated by LLMs

Microsoft x64 calling convention

Generated by GPT-5-mini
Note: This article was automatically generated by a large language model (LLM) from purely parametric knowledge (no retrieval). It may contain inaccuracies or hallucinations. This encyclopedia is part of a research project currently under review.
Article Genealogy
Parent: x86 architecture Hop 4
Expansion Funnel Raw 64 → Dedup 18 → NER 17 → Enqueued 12
1. Extracted64
2. After dedup18 (None)
3. After NER17 (None)
Rejected: 1 (not NE: 1)
4. Enqueued12 (None)
Microsoft x64 calling convention
NameMicrosoft x64 calling convention
Used byMicrosoft Windows, Visual C++, .NET, Windows API, Windows NT
Architecturex86-64, x64, AMD64, Intel 64
First appeared2005
DesignerMicrosoft Corporation
Calling convention typeregister-based, stack-based

Microsoft x64 calling convention The Microsoft x64 calling convention is the dominant application binary interface for 64-bit Windows platforms, dictating how procedures receive parameters, return values, and preserve registers for compatibility across compilers, system libraries, and runtime environments. It defines register roles, shadow space, stack alignment, and unwind metadata used by kernel-mode and user-mode components, enabling interoperation among Visual C++, the .NET Framework, Windows API, and third-party toolchains. Implementations and tooling from Intel Corporation, AMD, Microsoft Research, LLVM Project, GCC, and vendors such as Borland, Embarcadero Technologies, and Intel Compiler adhere to or map to this convention for binary compatibility with operating system interfaces like Windows NT, Windows 10, and Windows Server.

Overview

The convention arose to unify calling semantics for 64-bit Windows after the transition from 32-bit ABIs used by Microsoft Visual C++, aligning with processor features from AMD64 and Intel 64. It prescribes a fixed register assignment, mandatory shadow space to simplify prologue generation, and caller/callee preservation rules that affect code generation in compilers such as MSVC, Clang, and GCC. It interacts with exception handling models used by Structured Exception Handling and runtime systems used by Common Language Runtime and language implementations like C#, C++, Rust, Go (programming language), and Swift (programming language) targeting Windows.

Register Usage

General-purpose registers are organized into volatile and nonvolatile sets mapped to calling tasks; volatile registers serve as parameter carriers and temporaries used by compilers such as Microsoft Visual C++, Intel Compiler, and LLVM Project backends. The convention designates registers for first four integer or pointer arguments, leaving others preserved across calls; these roles influence register allocation strategies in optimizers from GCC and Clang. Floating-point and SIMD parameter passing uses registers exposed by Streaming SIMD Extensions and Advanced Vector Extensions, affecting code generation in libraries like DirectX, OpenGL, and Intel MKL. Reserved nonvolatile registers are used for frame pointers, home pointer preservation, and interoperation with debugger technologies like WinDbg and Visual Studio.

Stack Frame and Shadow Space

A fixed-size shadow space (home space) is allocated by the caller for callees' local home slots to simplify prologues generated by MSVC and to assist stack unwinding used by Windows Error Reporting and Structured Exception Handling. Stack alignment rules are enforced to maintain 16-byte alignment required by the ABI and processor microarchitectures from Intel Corporation and AMD, influencing stack probes and prologue emission in kernels like Windows NT Kernel and runtimes such as .NET Core and CoreCLR. The convention specifies how stack-based arguments, varargs, and spill slots are laid out for interop with language runtimes including Python (programming language), Ruby, Node.js, and JavaScriptCore when embedding native extensions or invoking DLL functions.

Parameter Passing and Return Values

The first four integer or pointer parameters are passed in predetermined registers, with subsequent arguments pushed on the stack by the caller; this model affects ABI stubs generated by Microsoft Visual C++, Clang, and GCC. Floating-point and vector returns use XMM registers, which is important for numerical libraries such as Intel MKL, OpenBLAS, and graphics APIs like Direct3D and Vulkan when used from languages compiled by MSVC or Clang. Struct and aggregate return semantics are defined to either use registers or caller-allocated memory depending on size and alignment, impacting interop layers in COM and Windows Runtime components, and influencing marshaling behavior in P/Invoke and C++/CLI.

Exception Handling and Interoperability

Exception handling requires unwind metadata emitted by compilers and linkers (for example, tools from Microsoft Visual Studio and LLVM Project), enabling stack walking by debuggers such as WinDbg and crash reporters like WER to interpret prologues and epilogues. The convention interacts with language-level exceptions in C++, C#, and managed runtimes such as CLR and Mono when native-to-managed or managed-to-native transitions occur, necessitating thunking and marshaling code in frameworks like COM interop and P/Invoke. Interoperability considerations also touch on calling convention translation layers provided by compatibility tools such as Wine, virtualization stacks like Hyper-V, and cross-compilation environments maintained by MinGW-w64 and Cygwin.

Calling Convention Variants and Compatibility

Several variants and compatibility modes exist to bridge differences between toolchains: compilers such as Clang and GCC on Windows provide command-line switches or attributes to match Microsoft x64 semantics for link compatibility with libraries produced by MSVC and system DLLs like kernel32.dll and user32.dll. Language runtimes and foreign function interfaces in projects such as Python, Ruby, Perl, and R expose platform-specific calling convention options to ensure binary compatibility with Windows APIs and third-party libraries from vendors like NVIDIA, AMD, and Intel Corporation. Migration guides and ABI documents produced by Microsoft Developer Network and community resources from LLVM Project and GCC maintainers document pitfalls in varargs, nonstandard prologues, and mixed-mode assemblies used by Visual Studio, JetBrains, and tooling ecosystems.

Category:Calling conventions