简体   繁体   中英

Is the CallingConvention ignored in 64-bit .NET applications?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM