When interacting with a 64-bit native library through an explicitly 64-bit .NET application via P/Invoke, is the CallingConvention property in the DllImport
attribute effectively ignored?
I ask this because on "traditional" x86 you have to specify the way the caller or callee cleans up stack variables (as well as how the function itself might use certain CPU registers etc); but as far as I understand, x64 only has a single convention, __fastcall
(the recently added __vectorcall
notwithstanding).
So does the CLR just go ahead and marshal function calls with the __fastcall
x64 convention, regardless of what you set for the CallingConvention
property?
Yes, completely ignored. The 64-bit pinvoke marshaller only supports the x64 ABI, loosely based on __fastcall. Very loosely. You won't get an exception if you specify CallingConvention, it just shrugs it off.
Note that __vectorcall is not specific to x64, there is also an x86 variant. Neither are supported by the pinvoke marshaller, you'd have to write a C++/CLI wrapper. There would be very little point in having it supported, .NET jitters still have very weak SSE2/AVX support. A wee bit in System.Numerics.Vector with the RyuJIT jitter, the new x64 jitter that shipped with VS2015 but no where near being able to pass arguments to a method yet. The harsh alignment requirement is going to require a very drastic CLR rewrite, long distance future music.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With