Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/dotnet/runtime.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorElinor Fung <elfung@microsoft.com>2021-05-21 09:07:39 +0300
committerGitHub <noreply@github.com>2021-05-21 09:07:39 +0300
commitd8fec8577aeb4321bc616f98f2eed1e983b114b6 (patch)
tree2420c25712c5b44b3d6f49ae9e497cc22a680413 /src/coreclr/tools/aot
parent419765391c14cb12366ee111b16e91a481ef7bc7 (diff)
Add UnmanagedCallConvAttribute (#52869)
Diffstat (limited to 'src/coreclr/tools/aot')
-rw-r--r--src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/MethodExtensions.cs40
-rw-r--r--src/coreclr/tools/aot/ILCompiler.ReadyToRun/ILCompiler.ReadyToRun.csproj3
2 files changed, 41 insertions, 2 deletions
diff --git a/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/MethodExtensions.cs b/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/MethodExtensions.cs
index eabc035af09..f9b363778a6 100644
--- a/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/MethodExtensions.cs
+++ b/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/MethodExtensions.cs
@@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
using Internal.TypeSystem;
+using Internal.TypeSystem.Ecma;
using Debug = System.Diagnostics.Debug;
@@ -21,19 +22,54 @@ namespace ILCompiler
}
/// <summary>
- /// Gets a value indicating whether GC transition should be suppressed on the given p/invoke.
+ /// Gets a value indicating whether the method has the SuppressGCTransition attribute
/// </summary>
- public static bool IsSuppressGCTransition(this MethodDesc method)
+ public static bool HasSuppressGCTransitionAttribute(this MethodDesc method)
{
Debug.Assert(method.IsPInvoke);
if (method is Internal.IL.Stubs.PInvokeTargetNativeMethod rawPinvoke)
method = rawPinvoke.Target;
+ // Check SuppressGCTransition attribute
return method.HasCustomAttribute("System.Runtime.InteropServices", "SuppressGCTransitionAttribute");
}
/// <summary>
+ /// Gets a value indicating whether GC transition should be suppressed on the given p/invoke.
+ /// </summary>
+ public static bool IsSuppressGCTransition(this MethodDesc method)
+ {
+ Debug.Assert(method.IsPInvoke);
+
+ // Check SuppressGCTransition attribute
+ if (method.HasSuppressGCTransitionAttribute())
+ return true;
+
+ MethodSignatureFlags unmanagedCallConv = method.GetPInvokeMethodMetadata().Flags.UnmanagedCallingConvention;
+ if (unmanagedCallConv != MethodSignatureFlags.None)
+ return false;
+
+ if (!(method is Internal.TypeSystem.Ecma.EcmaMethod ecmaMethod))
+ return false;
+
+ // Check UnmanagedCallConv attribute
+ System.Reflection.Metadata.CustomAttributeValue<TypeDesc>? unmanagedCallConvAttribute = ecmaMethod.GetDecodedCustomAttribute("System.Runtime.InteropServices", "UnmanagedCallConvAttribute");
+ if (unmanagedCallConvAttribute == null)
+ return false;
+
+ foreach (DefType defType in Internal.JitInterface.CallConvHelper.EnumerateCallConvsFromAttribute(unmanagedCallConvAttribute.Value))
+ {
+ if (defType.Name == "CallConvSuppressGCTransition")
+ {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ /// <summary>
/// Return true when the method is marked as non-versionable. Non-versionable methods
/// may be freely inlined into ReadyToRun images even when they don't reside in the
/// same version bubble as the module being compiled.
diff --git a/src/coreclr/tools/aot/ILCompiler.ReadyToRun/ILCompiler.ReadyToRun.csproj b/src/coreclr/tools/aot/ILCompiler.ReadyToRun/ILCompiler.ReadyToRun.csproj
index 8c387fa3c98..6299418227b 100644
--- a/src/coreclr/tools/aot/ILCompiler.ReadyToRun/ILCompiler.ReadyToRun.csproj
+++ b/src/coreclr/tools/aot/ILCompiler.ReadyToRun/ILCompiler.ReadyToRun.csproj
@@ -248,6 +248,9 @@
<Compile Include="..\..\Common\JitInterface\TypeString.cs">
<Link>JitInterface\TypeString.cs</Link>
</Compile>
+ <Compile Include="..\..\Common\JitInterface\CallConvHelper.cs">
+ <Link>JitInterface\CallConvHelper.cs</Link>
+ </Compile>
<Compile Include="..\..\Common\JitInterface\CorInfoBase.cs">
<Link>JitInterface\CorInfoBase.cs</Link>
</Compile>