-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Support function pointer types in System.Reflection.Emit
#119935
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 6 commits
2ceb67e
34b17f9
1df4ed5
3c6a62e
3b8c5a5
1968af0
3d9357c
07adab0
0b61dda
b322aa8
6d7dbee
848b86b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -5,6 +5,7 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||||||
using System.Collections.Immutable; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
using System.Reflection.Metadata; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
using System.Reflection.Metadata.Ecma335; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
using System.Runtime.CompilerServices; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
namespace System.Reflection.Emit | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -223,12 +224,67 @@ private static void WriteSignatureForType(SignatureTypeEncoder signature, Type t | |||||||||||||||||||||||||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
signature.GenericTypeParameter(type.GenericParameterPosition); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
else if (type.IsFunctionPointer) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
WriteSignatureForFunctionPointerType(signature, type, module); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
else | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
WriteSimpleSignature(signature, type, module); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
private static void WriteSignatureForFunctionPointerType(SignatureTypeEncoder signature, Type type, ModuleBuilderImpl module) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
SignatureCallingConvention callConv = SignatureCallingConvention.Default; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
FunctionPointerAttributes attribs = FunctionPointerAttributes.None; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
List<Type> retModOpts = [.. type.GetFunctionPointerReturnType().GetOptionalCustomModifiers()]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
jgh07 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
if (type.GetFunctionPointerCallingConventions() is Type[] conventions && conventions.Length > 0) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
foreach (Type conv in conventions) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
if (conv == typeof(CallConvCdecl)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
protected override void SetCustomAttributeCore(ConstructorInfo con, ReadOnlySpan<byte> binaryAttribute) | |
{ | |
// Handle pseudo custom attributes | |
switch (con.ReflectedType!.FullName) | |
{ | |
case "System.Runtime.InteropServices.StructLayoutAttribute": | |
ParseStructLayoutAttribute(con, binaryAttribute); | |
return; | |
case "System.Runtime.CompilerServices.SpecialNameAttribute": | |
_attributes |= TypeAttributes.SpecialName; | |
return; | |
case "System.SerializableAttribute": | |
#pragma warning disable SYSLIB0050 // 'TypeAttributes.Serializable' is obsolete: 'Formatter-based serialization is obsolete and should not be used'. | |
_attributes |= TypeAttributes.Serializable; | |
#pragma warning restore SYSLIB0050 | |
return; | |
case "System.Runtime.InteropServices.ComImportAttribute": | |
_attributes |= TypeAttributes.Import; | |
return; | |
case "System.Runtime.InteropServices.WindowsRuntime.WindowsRuntimeImportAttribute": | |
_attributes |= TypeAttributes.WindowsRuntime; | |
return; | |
case "System.Security.SuppressUnmanagedCodeSecurityAttribute": // It says has no effect in .NET Core, maybe remove? | |
_attributes |= TypeAttributes.HasSecurity; | |
break; | |
} |
Uh oh!
There was an error while loading. Please reload this page.