You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Add a new unmanaged calling convention bit for use with function pointers #38133
We need a new unmanaged calling convention bit for use with function pointers in .NET 5.
This bit will represent the "platform" default calling convention (essentially equivalent to Winapi for P/Invoke).
Based on the conversations, this would be bit 9 in the calling kind encoding.
namespaceSystem.Reflection.Metadata{publicenumSignatureCallingConvention:byte{// existingDefault=0x0,CDecl=0x1,StdCall=0x2,ThisCall=0x3,FastCall=0x4,// 0x5 - 0x8 are taken by other types of signatures (fields, properties, etc.)// newUnmanaged=0x9,}}
enum CallingConvention is used in other more common contexts like DllImport where this new value would be confusing.
The use of enum CallingConvention in the Reflection.Emit APIs is broken, e.g. CallingConvention.WinApi is mapped to StdCall here. I think we should leave the use of this enum in Reflection.Emit alone and not try to fix it or improve it.
If we wanted to make this work with existing reflection APIs, I think it may be better to add a new Unmanaged value to enum CallingConventions. This enum can be used in combination with SignatureHelper to produce signature with modopts and then emitted using Emit(OpCode opcode, SignatureHelper signature).
I think we should hold off on adding new support to reflection emit for this in this release. We're very close to ship, and I'm not aware of any scenarios where we need calli support for this in the .NET 5 timeframe. Support in System.Reflection.Metadata is different though, as that is the api surface used by the compilers to generate code, we should fix that so that the Roslyn team doesn't need to maintain their own definition of the enum value.
Activity
Dotnet-GitSync-Bot commentedon Jun 19, 2020
I couldn't figure out the best area label to add to this issue. Please help me learn by adding exactly one area label.
tannergooding commentedon Jun 19, 2020
CC. @333fred, @davidwrighton, @AaronRobinsonMSFT, @jkotas, @lambdageek
AaronRobinsonMSFT commentedon Jun 19, 2020
Related #34805
jkotas commentedon Jun 19, 2020
This should include the new API proposal for
System.Reflection.Metadata. I have edited the top post.AaronRobinsonMSFT commentedon Jun 24, 2020
Seems like we are going to also have to update
System.Runtime.InteropServices.CallingConventionto support theILGenerator.EmitCalli()scenario.AaronRobinsonMSFT commentedon Jun 24, 2020
I have updated the above proposal. We could also not support it since the API doesn't seem to have a place to addmodopts?/cc @davidwrighton
Edit: Removed the updated
enum CallingConventionfrom proposal since it isn't worth trying to reconcile with all the places the enum is used.jkotas commentedon Jun 24, 2020
enum CallingConventionis used in other more common contexts likeDllImportwhere this new value would be confusing.The use of
enum CallingConventionin the Reflection.Emit APIs is broken, e.g.CallingConvention.WinApiis mapped to StdCall here. I think we should leave the use of this enum in Reflection.Emit alone and not try to fix it or improve it.If we wanted to make this work with existing reflection APIs, I think it may be better to add a new
Unmanagedvalue toenum CallingConventions. This enum can be used in combination withSignatureHelperto produce signature with modopts and then emitted usingEmit(OpCode opcode, SignatureHelper signature).AaronRobinsonMSFT commentedon Jun 24, 2020
That is what I was thinking as well. Perhaps it would be worth marking that API as
Obsolete?davidwrighton commentedon Jun 24, 2020
I think we should hold off on adding new support to reflection emit for this in this release. We're very close to ship, and I'm not aware of any scenarios where we need calli support for this in the .NET 5 timeframe. Support in System.Reflection.Metadata is different though, as that is the api surface used by the compilers to generate code, we should fix that so that the Roslyn team doesn't need to maintain their own definition of the enum value.
terrajobst commentedon Jul 2, 2020
Video
Technically, the actual calling convention is expressed as modopt on the return type but we felt a vague name is good enough.