summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Wrighton <davidwr@microsoft.com>2019-05-23 16:18:07 -0700
committerGitHub <noreply@github.com>2019-05-23 16:18:07 -0700
commitabdee1f2fa9531c78eeadef6d0bb8fb1f823d011 (patch)
tree7e5ed4af489c50339849dcf18b9e30b60b65d351
parent046d61c972d0b8372cbb7cec98e5636e08735782 (diff)
downloadcoreclr-abdee1f2fa9531c78eeadef6d0bb8fb1f823d011.tar.gz
coreclr-abdee1f2fa9531c78eeadef6d0bb8fb1f823d011.tar.bz2
coreclr-abdee1f2fa9531c78eeadef6d0bb8fb1f823d011.zip
Fewer ilstubs in corelib from reflection apis (#24708)
Rework use of marshalling for RuntimeTypeHandle, RuntimeModule, RuntimeAssembly, and IRuntimeMethodInfo as used by QCalls - Remove special QCall only used marshallers for RuntimeAssembly, RuntimeModule and IRuntimeMethodInfo - Following the pattern of ObjectHandleOnStack, implement QCall handle types for RuntimeAssembly/Module/TypeHandle. Use these in all QCalls that once passed the types directly. - For uses of IRuntimeMethodInfo, follow the existing RuntimeMethodHandleInternal pattern Also perform some replacement of bool marshalling with use of Interop.BOOL, and a few cases of using pointers instead of byref arguments. Fix delivers a relatively small win on startup, and small throughput gains around reflection as IL stubs are no longer necessary for many functions in reflection that once needed them. Reduces methods jitted on powershell startup from 422 to 399, (About 5%) but performance win is only about 5ms on ~400ms as the methods removed are simple.
-rw-r--r--src/System.Private.CoreLib/System.Private.CoreLib.csproj2
-rw-r--r--src/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.Globalization.cs4
-rw-r--r--src/System.Private.CoreLib/shared/System/Globalization/CultureInfo.Windows.cs19
-rw-r--r--src/System.Private.CoreLib/src/System/ApplicationModel.Windows.cs4
-rw-r--r--src/System.Private.CoreLib/src/System/Enum.CoreCLR.cs7
-rw-r--r--src/System.Private.CoreLib/src/System/Environment.CoreCLR.cs5
-rw-r--r--src/System.Private.CoreLib/src/System/Reflection/CustomAttribute.cs10
-rw-r--r--src/System.Private.CoreLib/src/System/Reflection/Emit/DynamicMethod.cs8
-rw-r--r--src/System.Private.CoreLib/src/System/Reflection/Emit/EventBuilder.cs5
-rw-r--r--src/System.Private.CoreLib/src/System/Reflection/Emit/FieldBuilder.cs10
-rw-r--r--src/System.Private.CoreLib/src/System/Reflection/Emit/MethodBuilder.cs9
-rw-r--r--src/System.Private.CoreLib/src/System/Reflection/Emit/ModuleBuilder.cs61
-rw-r--r--src/System.Private.CoreLib/src/System/Reflection/Emit/ParameterBuilder.cs5
-rw-r--r--src/System.Private.CoreLib/src/System/Reflection/Emit/PropertyBuilder.cs4
-rw-r--r--src/System.Private.CoreLib/src/System/Reflection/Emit/TypeBuilder.cs82
-rw-r--r--src/System.Private.CoreLib/src/System/Reflection/Metadata/AssemblyExtensions.cs6
-rw-r--r--src/System.Private.CoreLib/src/System/Reflection/RuntimeAssembly.cs106
-rw-r--r--src/System.Private.CoreLib/src/System/Reflection/RuntimeMethodInfo.cs2
-rw-r--r--src/System.Private.CoreLib/src/System/Reflection/RuntimeModule.cs29
-rw-r--r--src/System.Private.CoreLib/src/System/RtType.cs9
-rw-r--r--src/System.Private.CoreLib/src/System/Runtime/CompilerServices/RuntimeHelpers.cs2
-rw-r--r--src/System.Private.CoreLib/src/System/Runtime/CompilerServices/jithelpers.cs70
-rw-r--r--src/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshal.CoreCLR.cs9
-rw-r--r--src/System.Private.CoreLib/src/System/Runtime/InteropServices/NativeLibrary.CoreCLR.cs5
-rw-r--r--src/System.Private.CoreLib/src/System/Runtime/Loader/AssemblyLoadContext.CoreCLR.cs5
-rw-r--r--src/System.Private.CoreLib/src/System/RuntimeHandles.cs150
-rw-r--r--src/System.Private.CoreLib/src/System/Threading/Thread.CoreCLR.cs4
-rw-r--r--src/System.Private.CoreLib/src/System/Threading/ThreadPool.CoreCLR.cs2
-rw-r--r--src/tools/r2rdump/R2RReader.cs6
-rw-r--r--src/vm/commodule.cpp4
-rw-r--r--src/vm/commodule.h2
-rw-r--r--src/vm/ilmarshalers.h21
-rw-r--r--src/vm/mlinfo.cpp36
-rw-r--r--src/vm/mtypes.h3
-rw-r--r--src/vm/qcall.cpp2
-rw-r--r--src/vm/qcall.h14
-rw-r--r--src/vm/reflectioninvocation.cpp4
-rw-r--r--src/vm/reflectioninvocation.h2
-rw-r--r--src/vm/runtimehandles.cpp72
-rw-r--r--src/vm/runtimehandles.h36
40 files changed, 498 insertions, 338 deletions
diff --git a/src/System.Private.CoreLib/System.Private.CoreLib.csproj b/src/System.Private.CoreLib/System.Private.CoreLib.csproj
index 9f7b5238f6..f8d2995128 100644
--- a/src/System.Private.CoreLib/System.Private.CoreLib.csproj
+++ b/src/System.Private.CoreLib/System.Private.CoreLib.csproj
@@ -120,6 +120,7 @@
<PropertyGroup>
<CommonPath>$(MSBuildThisFileDirectory)Common</CommonPath>
<BclSourcesRoot>$(MSBuildThisFileDirectory)src</BclSourcesRoot>
+ <SharedBclSourcesRoot>$(MSBuildThisFileDirectory)shared</SharedBclSourcesRoot>
</PropertyGroup>
<!-- Msbuild variables needed to get CoreCLR features to be set properly. -->
@@ -374,6 +375,7 @@
<Compile Include="$(BclSourcesRoot)\System\Variant.cs" />
</ItemGroup>
<ItemGroup Condition="'$(TargetsUnix)' == 'true'">
+ <Compile Include="$(SharedBclSourcesRoot)\Interop\Windows\Interop.BOOL.cs" /> <!-- The CLR internally uses a BOOL type analogous to the Windows BOOL type on Unix -->
<Compile Include="$(BclSourcesRoot)\Interop\Unix\Interop.Libraries.cs" />
<Compile Include="$(BclSourcesRoot)\System\DateTime.Unix.CoreCLR.cs" />
<Compile Include="$(BclSourcesRoot)\System\Globalization\GlobalizationMode.Unix.cs" />
diff --git a/src/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.Globalization.cs b/src/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.Globalization.cs
index cab7537ced..49d8033e54 100644
--- a/src/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.Globalization.cs
+++ b/src/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.Globalization.cs
@@ -101,8 +101,8 @@ internal static partial class Interop
int cchStr);
#if !ENABLE_WINRT
- [DllImport("Kernel32.dll", CharSet = CharSet.Auto)]
- internal static extern bool GetUserPreferredUILanguages(uint dwFlags, out uint pulNumLanguages, char[]? pwszLanguagesBuffer, ref uint pcchLanguagesBuffer);
+ [DllImport("kernel32.dll", CharSet = CharSet.Auto)]
+ internal static extern Interop.BOOL GetUserPreferredUILanguages(uint dwFlags, uint* pulNumLanguages, char* pwszLanguagesBuffer, uint* pcchLanguagesBuffer);
#endif //!ENABLE_WINRT
[DllImport("kernel32.dll", CharSet = CharSet.Unicode)]
diff --git a/src/System.Private.CoreLib/shared/System/Globalization/CultureInfo.Windows.cs b/src/System.Private.CoreLib/shared/System/Globalization/CultureInfo.Windows.cs
index 67a70d8234..d746659fd2 100644
--- a/src/System.Private.CoreLib/shared/System/Globalization/CultureInfo.Windows.cs
+++ b/src/System.Private.CoreLib/shared/System/Globalization/CultureInfo.Windows.cs
@@ -39,7 +39,7 @@ namespace System.Globalization
return GetCultureByName(strDefault);
}
- private static CultureInfo GetUserDefaultUICulture()
+ private unsafe static CultureInfo GetUserDefaultUICulture()
{
#if !ENABLE_WINRT
if (GlobalizationMode.Invariant)
@@ -49,18 +49,21 @@ namespace System.Globalization
uint langCount = 0;
uint bufLen = 0;
- if (Interop.Kernel32.GetUserPreferredUILanguages(MUI_LANGUAGE_NAME, out langCount, null, ref bufLen))
+ if (Interop.Kernel32.GetUserPreferredUILanguages(MUI_LANGUAGE_NAME, &langCount, null, &bufLen) != Interop.BOOL.FALSE)
{
char[] languages = new char[bufLen];
- if (Interop.Kernel32.GetUserPreferredUILanguages(MUI_LANGUAGE_NAME, out langCount, languages, ref bufLen))
+ fixed (char* pLanguages = languages)
{
- int index = 0;
- while (languages[index] != (char)0 && index < languages.Length)
+ if (Interop.Kernel32.GetUserPreferredUILanguages(MUI_LANGUAGE_NAME, &langCount, pLanguages, &bufLen) != Interop.BOOL.FALSE)
{
- index++;
- }
+ int index = 0;
+ while (languages[index] != (char)0 && index < languages.Length)
+ {
+ index++;
+ }
- return GetCultureByName(new string(languages, 0, index));
+ return GetCultureByName(new string(languages, 0, index));
+ }
}
}
#endif
diff --git a/src/System.Private.CoreLib/src/System/ApplicationModel.Windows.cs b/src/System.Private.CoreLib/src/System/ApplicationModel.Windows.cs
index ea1e017424..9c4a60d1be 100644
--- a/src/System.Private.CoreLib/src/System/ApplicationModel.Windows.cs
+++ b/src/System.Private.CoreLib/src/System/ApplicationModel.Windows.cs
@@ -11,10 +11,10 @@ namespace System
{
#if FEATURE_APPX
// Cache the value in readonly static that can be optimized out by the JIT
- internal readonly static bool IsUap = IsAppXProcess();
+ internal readonly static bool IsUap = IsAppXProcess() != Interop.BOOL.FALSE;
[DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)]
- private static extern bool IsAppXProcess();
+ private static extern Interop.BOOL IsAppXProcess();
#endif
}
}
diff --git a/src/System.Private.CoreLib/src/System/Enum.CoreCLR.cs b/src/System.Private.CoreLib/src/System/Enum.CoreCLR.cs
index 06d08bc948..71533b4a3f 100644
--- a/src/System.Private.CoreLib/src/System/Enum.CoreCLR.cs
+++ b/src/System.Private.CoreLib/src/System/Enum.CoreCLR.cs
@@ -12,7 +12,7 @@ namespace System
public abstract partial class Enum
{
[DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)]
- private static extern void GetEnumValuesAndNames(RuntimeTypeHandle enumType, ObjectHandleOnStack values, ObjectHandleOnStack names, bool getNames);
+ private static extern void GetEnumValuesAndNames(QCallTypeHandle enumType, ObjectHandleOnStack values, ObjectHandleOnStack names, Interop.BOOL getNames);
[MethodImpl(MethodImplOptions.InternalCall)]
public override extern bool Equals(object? obj);
@@ -55,11 +55,12 @@ namespace System
{
ulong[]? values = null;
string[]? names = null;
+ RuntimeTypeHandle enumTypeHandle = enumType.GetTypeHandleInternal();
GetEnumValuesAndNames(
- enumType.GetTypeHandleInternal(),
+ JitHelpers.GetQCallTypeHandleOnStack(ref enumTypeHandle),
JitHelpers.GetObjectHandleOnStack(ref values),
JitHelpers.GetObjectHandleOnStack(ref names),
- getNames);
+ getNames ? Interop.BOOL.TRUE : Interop.BOOL.FALSE);
bool hasFlagsAttribute = enumType.IsDefined(typeof(FlagsAttribute), inherit: false);
entry = new EnumInfo(hasFlagsAttribute, values!, names!);
diff --git a/src/System.Private.CoreLib/src/System/Environment.CoreCLR.cs b/src/System.Private.CoreLib/src/System/Environment.CoreCLR.cs
index de51ed4a9a..36ddf53e53 100644
--- a/src/System.Private.CoreLib/src/System/Environment.CoreCLR.cs
+++ b/src/System.Private.CoreLib/src/System/Environment.CoreCLR.cs
@@ -107,15 +107,14 @@ namespace System
private static class WinRT
{
// Cache the value in readonly static that can be optimized out by the JIT
- public readonly static bool IsSupported = WinRTSupported();
+ public readonly static bool IsSupported = WinRTSupported() != Interop.BOOL.FALSE;
}
// Does the current version of Windows have Windows Runtime suppport?
internal static bool IsWinRTSupported => WinRT.IsSupported;
[DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)]
- [return: MarshalAs(UnmanagedType.Bool)]
- private static extern bool WinRTSupported();
+ private static extern Interop.BOOL WinRTSupported();
#endif // FEATURE_COMINTEROP
}
}
diff --git a/src/System.Private.CoreLib/src/System/Reflection/CustomAttribute.cs b/src/System.Private.CoreLib/src/System/Reflection/CustomAttribute.cs
index f8a6deccf8..cee3326052 100644
--- a/src/System.Private.CoreLib/src/System/Reflection/CustomAttribute.cs
+++ b/src/System.Private.CoreLib/src/System/Reflection/CustomAttribute.cs
@@ -1586,7 +1586,15 @@ namespace System.Reflection
decoratedModule.ModuleHandle.ResolveTypeHandle(tkParent) :
new RuntimeTypeHandle();
- return RuntimeMethodHandle.IsCAVisibleFromDecoratedType(attributeType.TypeHandle, ctor!, parentTypeHandle, decoratedModule);
+ RuntimeTypeHandle attributeTypeHandle = attributeType.TypeHandle;
+
+ bool result = RuntimeMethodHandle.IsCAVisibleFromDecoratedType(JitHelpers.GetQCallTypeHandleOnStack(ref attributeTypeHandle),
+ ctor != null ? ctor.Value : RuntimeMethodHandleInternal.EmptyHandle,
+ JitHelpers.GetQCallTypeHandleOnStack(ref parentTypeHandle),
+ JitHelpers.GetQCallModuleOnStack(ref decoratedModule)) != Interop.BOOL.FALSE;
+
+ GC.KeepAlive(ctor);
+ return result;
}
#endregion
diff --git a/src/System.Private.CoreLib/src/System/Reflection/Emit/DynamicMethod.cs b/src/System.Private.CoreLib/src/System/Reflection/Emit/DynamicMethod.cs
index b77a17f756..978f234a1f 100644
--- a/src/System.Private.CoreLib/src/System/Reflection/Emit/DynamicMethod.cs
+++ b/src/System.Private.CoreLib/src/System/Reflection/Emit/DynamicMethod.cs
@@ -342,7 +342,9 @@ namespace System.Reflection.Emit
{
// Compile the method since accessibility checks are done as part of compilation.
GetMethodDescriptor();
- System.Runtime.CompilerServices.RuntimeHelpers._CompileMethod(m_methodHandle!);
+ IRuntimeMethodInfo? methodHandle = m_methodHandle;
+ System.Runtime.CompilerServices.RuntimeHelpers._CompileMethod(methodHandle != null ? methodHandle.Value : RuntimeMethodHandleInternal.EmptyHandle);
+ GC.KeepAlive(methodHandle);
}
MulticastDelegate d = (MulticastDelegate)Delegate.CreateDelegateNoSecurityCheck(delegateType, null, GetMethodDescriptor());
@@ -357,7 +359,9 @@ namespace System.Reflection.Emit
{
// Compile the method since accessibility checks are done as part of compilation
GetMethodDescriptor();
- System.Runtime.CompilerServices.RuntimeHelpers._CompileMethod(m_methodHandle!);
+ IRuntimeMethodInfo? methodHandle = m_methodHandle;
+ System.Runtime.CompilerServices.RuntimeHelpers._CompileMethod(methodHandle != null ? methodHandle.Value : RuntimeMethodHandleInternal.EmptyHandle);
+ GC.KeepAlive(methodHandle);
}
MulticastDelegate d = (MulticastDelegate)Delegate.CreateDelegateNoSecurityCheck(delegateType, target, GetMethodDescriptor());
diff --git a/src/System.Private.CoreLib/src/System/Reflection/Emit/EventBuilder.cs b/src/System.Private.CoreLib/src/System/Reflection/Emit/EventBuilder.cs
index 2c36570be2..fad7c8bfef 100644
--- a/src/System.Private.CoreLib/src/System/Reflection/Emit/EventBuilder.cs
+++ b/src/System.Private.CoreLib/src/System/Reflection/Emit/EventBuilder.cs
@@ -13,6 +13,8 @@
**
===========================================================*/
+using System.Runtime.CompilerServices;
+
namespace System.Reflection.Emit
{
//
@@ -53,8 +55,9 @@ namespace System.Reflection.Emit
}
m_type.ThrowIfCreated();
+ ModuleBuilder module = m_module;
TypeBuilder.DefineMethodSemantics(
- m_module.GetNativeHandle(),
+ JitHelpers.GetQCallModuleOnStack(ref module),
m_evToken.Token,
semantics,
mdBuilder.GetToken().Token);
diff --git a/src/System.Private.CoreLib/src/System/Reflection/Emit/FieldBuilder.cs b/src/System.Private.CoreLib/src/System/Reflection/Emit/FieldBuilder.cs
index 82016657a5..edb2d7618e 100644
--- a/src/System.Private.CoreLib/src/System/Reflection/Emit/FieldBuilder.cs
+++ b/src/System.Private.CoreLib/src/System/Reflection/Emit/FieldBuilder.cs
@@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
+using System.Runtime.CompilerServices;
using CultureInfo = System.Globalization.CultureInfo;
namespace System.Reflection.Emit
@@ -47,7 +48,8 @@ namespace System.Reflection.Emit
int sigLength;
byte[] signature = sigHelp.InternalGetSignature(out sigLength);
- m_fieldTok = TypeBuilder.DefineField(m_typeBuilder.GetModuleBuilder().GetNativeHandle(),
+ ModuleBuilder module = m_typeBuilder.GetModuleBuilder();
+ m_fieldTok = TypeBuilder.DefineField(JitHelpers.GetQCallModuleOnStack(ref module),
typeBuilder.TypeToken.Token, fieldName, signature, sigLength, m_Attributes);
m_tkField = new FieldToken(m_fieldTok, type);
@@ -58,7 +60,8 @@ namespace System.Reflection.Emit
#region Internal Members
internal void SetData(byte[]? data, int size)
{
- ModuleBuilder.SetFieldRVAContent(m_typeBuilder.GetModuleBuilder().GetNativeHandle(), m_tkField.Token, data, size);
+ ModuleBuilder module = m_typeBuilder.GetModuleBuilder();
+ ModuleBuilder.SetFieldRVAContent(JitHelpers.GetQCallModuleOnStack(ref module), m_tkField.Token, data, size);
}
#endregion
@@ -166,7 +169,8 @@ namespace System.Reflection.Emit
{
m_typeBuilder.ThrowIfCreated();
- TypeBuilder.SetFieldLayoutOffset(m_typeBuilder.GetModuleBuilder().GetNativeHandle(), GetToken().Token, iOffset);
+ ModuleBuilder module = m_typeBuilder.GetModuleBuilder();
+ TypeBuilder.SetFieldLayoutOffset(JitHelpers.GetQCallModuleOnStack(ref module), GetToken().Token, iOffset);
}
public void SetConstant(object? defaultValue)
diff --git a/src/System.Private.CoreLib/src/System/Reflection/Emit/MethodBuilder.cs b/src/System.Private.CoreLib/src/System/Reflection/Emit/MethodBuilder.cs
index 1b13937a73..abf38abb6e 100644
--- a/src/System.Private.CoreLib/src/System/Reflection/Emit/MethodBuilder.cs
+++ b/src/System.Private.CoreLib/src/System/Reflection/Emit/MethodBuilder.cs
@@ -6,6 +6,7 @@ using System.Text;
using CultureInfo = System.Globalization.CultureInfo;
using System.Diagnostics.SymbolStore;
using System.Collections.Generic;
+using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Diagnostics;
@@ -741,15 +742,16 @@ namespace System.Reflection.Emit
int sigLength;
byte[] sigBytes = GetMethodSignature().InternalGetSignature(out sigLength);
+ ModuleBuilder module = m_module;
- int token = TypeBuilder.DefineMethod(m_module.GetNativeHandle(), m_containingType.MetadataTokenInternal, m_strName, sigBytes, sigLength, Attributes);
+ int token = TypeBuilder.DefineMethod(JitHelpers.GetQCallModuleOnStack(ref module), m_containingType.MetadataTokenInternal, m_strName, sigBytes, sigLength, Attributes);
m_tkMethod = new MethodToken(token);
if (m_inst != null)
foreach (GenericTypeParameterBuilder tb in m_inst)
if (!tb.m_type.IsCreated()) tb.m_type.CreateType();
- TypeBuilder.SetMethodImpl(m_module.GetNativeHandle(), token, m_dwMethodImplFlags);
+ TypeBuilder.SetMethodImpl(JitHelpers.GetQCallModuleOnStack(ref module), token, m_dwMethodImplFlags);
return m_tkMethod;
}
@@ -834,7 +836,8 @@ namespace System.Reflection.Emit
m_canBeRuntimeImpl = true;
- TypeBuilder.SetMethodImpl(m_module.GetNativeHandle(), MetadataTokenInternal, attributes);
+ ModuleBuilder module = m_module;
+ TypeBuilder.SetMethodImpl(JitHelpers.GetQCallModuleOnStack(ref module), MetadataTokenInternal, attributes);
}
public ILGenerator GetILGenerator()
diff --git a/src/System.Private.CoreLib/src/System/Reflection/Emit/ModuleBuilder.cs b/src/System.Private.CoreLib/src/System/Reflection/Emit/ModuleBuilder.cs
index b8e0f639b0..f6911ea261 100644
--- a/src/System.Private.CoreLib/src/System/Reflection/Emit/ModuleBuilder.cs
+++ b/src/System.Private.CoreLib/src/System/Reflection/Emit/ModuleBuilder.cs
@@ -132,67 +132,79 @@ namespace System.Reflection.Emit
}
[DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)]
- private static extern int GetTypeRef(RuntimeModule module, string strFullName, RuntimeModule refedModule, string? strRefedModuleFileName, int tkResolution);
+ private static extern int GetTypeRef(QCallModule module, string strFullName, QCallModule refedModule, string? strRefedModuleFileName, int tkResolution);
[DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)]
- private static extern int GetMemberRef(RuntimeModule module, RuntimeModule refedModule, int tr, int defToken);
+ private static extern int GetMemberRef(QCallModule module, QCallModule refedModule, int tr, int defToken);
private int GetMemberRef(Module? refedModule, int tr, int defToken)
{
- return GetMemberRef(GetNativeHandle(), GetRuntimeModuleFromModule(refedModule).GetNativeHandle(), tr, defToken);
+ ModuleBuilder thisModule = this;
+ RuntimeModule refedRuntimeModule = GetRuntimeModuleFromModule(refedModule);
+
+ return GetMemberRef(JitHelpers.GetQCallModuleOnStack(ref thisModule), JitHelpers.GetQCallModuleOnStack(ref refedRuntimeModule), tr, defToken);
}
[DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)]
- private static extern int GetMemberRefFromSignature(RuntimeModule module, int tr, string methodName, byte[] signature, int length);
+ private static extern int GetMemberRefFromSignature(QCallModule module, int tr, string methodName, byte[] signature, int length);
private int GetMemberRefFromSignature(int tr, string methodName, byte[] signature, int length)
{
- return GetMemberRefFromSignature(GetNativeHandle(), tr, methodName, signature, length);
+ ModuleBuilder thisModule = this;
+ return GetMemberRefFromSignature(JitHelpers.GetQCallModuleOnStack(ref thisModule), tr, methodName, signature, length);
}
[DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)]
- private static extern int GetMemberRefOfMethodInfo(RuntimeModule module, int tr, IRuntimeMethodInfo method);
+ private static extern int GetMemberRefOfMethodInfo(QCallModule module, int tr, RuntimeMethodHandleInternal method);
private int GetMemberRefOfMethodInfo(int tr, RuntimeMethodInfo method)
{
Debug.Assert(method != null);
- return GetMemberRefOfMethodInfo(GetNativeHandle(), tr, method);
+ ModuleBuilder thisModule = this;
+ int result = GetMemberRefOfMethodInfo(JitHelpers.GetQCallModuleOnStack(ref thisModule), tr, ((IRuntimeMethodInfo)method).Value);
+ GC.KeepAlive(method);
+ return result;
}
private int GetMemberRefOfMethodInfo(int tr, RuntimeConstructorInfo method)
{
Debug.Assert(method != null);
- return GetMemberRefOfMethodInfo(GetNativeHandle(), tr, method);
+ ModuleBuilder thisModule = this;
+ int result = GetMemberRefOfMethodInfo(JitHelpers.GetQCallModuleOnStack(ref thisModule), tr, ((IRuntimeMethodInfo)method).Value);
+ GC.KeepAlive(method);
+ return result;
}
[DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)]
- private static extern int GetMemberRefOfFieldInfo(RuntimeModule module, int tkType, RuntimeTypeHandle declaringType, int tkField);
+ private static extern int GetMemberRefOfFieldInfo(QCallModule module, int tkType, QCallTypeHandle declaringType, int tkField);
private int GetMemberRefOfFieldInfo(int tkType, RuntimeTypeHandle declaringType, RuntimeFieldInfo runtimeField)
{
Debug.Assert(runtimeField != null);
- return GetMemberRefOfFieldInfo(GetNativeHandle(), tkType, declaringType, runtimeField.MetadataToken);
+ ModuleBuilder thisModule = this;
+ return GetMemberRefOfFieldInfo(JitHelpers.GetQCallModuleOnStack(ref thisModule), tkType, JitHelpers.GetQCallTypeHandleOnStack(ref declaringType), runtimeField.MetadataToken);
}
[DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)]
- private static extern int GetTokenFromTypeSpec(RuntimeModule pModule, byte[] signature, int length);
+ private static extern int GetTokenFromTypeSpec(QCallModule pModule, byte[] signature, int length);
private int GetTokenFromTypeSpec(byte[] signature, int length)
{
- return GetTokenFromTypeSpec(GetNativeHandle(), signature, length);
+ ModuleBuilder thisModule = this;
+ return GetTokenFromTypeSpec(JitHelpers.GetQCallModuleOnStack(ref thisModule), signature, length);
}
[DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)]
- private static extern int GetArrayMethodToken(RuntimeModule module, int tkTypeSpec, string methodName, byte[] signature, int sigLength);
+ private static extern int GetArrayMethodToken(QCallModule module, int tkTypeSpec, string methodName, byte[] signature, int sigLength);
[DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)]
- private static extern int GetStringConstant(RuntimeModule module, string str, int length);
+ private static extern int GetStringConstant(QCallModule module, string str, int length);
[DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)]
- internal static extern void SetFieldRVAContent(RuntimeModule module, int fdToken, byte[]? data, int length);
+ internal static extern void SetFieldRVAContent(QCallModule module, int fdToken, byte[]? data, int length);
#endregion
@@ -237,7 +249,9 @@ namespace System.Reflection.Emit
Debug.Assert(!type.IsByRef, "Must not be ByRef.");
Debug.Assert(!type.IsGenericType || type.IsGenericTypeDefinition, "Must not have generic arguments.");
- return GetTypeRef(GetNativeHandle(), typeName, GetRuntimeModuleFromModule(refedModule).GetNativeHandle(), strRefedModuleFileName, tkResolution);
+ ModuleBuilder thisModule = this;
+ RuntimeModule refedRuntimeModule = GetRuntimeModuleFromModule(refedModule);
+ return GetTypeRef(JitHelpers.GetQCallModuleOnStack(ref thisModule), typeName, JitHelpers.GetQCallModuleOnStack(ref refedRuntimeModule), strRefedModuleFileName, tkResolution);
}
internal MethodToken InternalGetConstructorToken(ConstructorInfo con, bool usingRef)
@@ -1274,7 +1288,8 @@ namespace System.Reflection.Emit
// Create MethodSepc M<Bar> with parent G?.M<S>
byte[] sigBytes = SignatureHelper.GetMethodSpecSigHelper(
this, methodInfo.GetGenericArguments()).InternalGetSignature(out int sigLength);
- tk = TypeBuilder.DefineMethodSpec(GetNativeHandle(), tk, sigBytes, sigLength);
+ ModuleBuilder thisModule = this;
+ tk = TypeBuilder.DefineMethodSpec(JitHelpers.GetQCallModuleOnStack(ref thisModule), tk, sigBytes, sigLength);
}
else
{
@@ -1338,7 +1353,8 @@ namespace System.Reflection.Emit
byte[] sigBytes = sigHelp.InternalGetSignature(out int length);
TypeToken typeSpec = GetTypeTokenInternal(arrayClass);
- return new MethodToken(GetArrayMethodToken(GetNativeHandle(),
+ ModuleBuilder thisModule = this;
+ return new MethodToken(GetArrayMethodToken(JitHelpers.GetQCallModuleOnStack(ref thisModule),
typeSpec.Token, methodName, sigBytes, length));
}
@@ -1459,7 +1475,8 @@ namespace System.Reflection.Emit
// Returns a token representing a String constant. If the string
// value has already been defined, the existing token will be returned.
- return new StringToken(GetStringConstant(GetNativeHandle(), str, str.Length));
+ ModuleBuilder thisModule = this;
+ return new StringToken(GetStringConstant(JitHelpers.GetQCallModuleOnStack(ref thisModule), str, str.Length));
}
public SignatureToken GetSignatureToken(SignatureHelper sigHelper)
@@ -1473,7 +1490,8 @@ namespace System.Reflection.Emit
// get the signature in byte form
byte[] sigBytes = sigHelper.InternalGetSignature(out int sigLength);
- return new SignatureToken(TypeBuilder.GetTokenFromSig(GetNativeHandle(), sigBytes, sigLength));
+ ModuleBuilder thisModule = this;
+ return new SignatureToken(TypeBuilder.GetTokenFromSig(JitHelpers.GetQCallModuleOnStack(ref thisModule), sigBytes, sigLength));
}
public SignatureToken GetSignatureToken(byte[] sigBytes, int sigLength)
@@ -1486,7 +1504,8 @@ namespace System.Reflection.Emit
byte[] localSigBytes = new byte[sigBytes.Length];
Buffer.BlockCopy(sigBytes, 0, localSigBytes, 0, sigBytes.Length);
- return new SignatureToken(TypeBuilder.GetTokenFromSig(GetNativeHandle(), localSigBytes, sigLength));
+ ModuleBuilder thisModule = this;
+ return new SignatureToken(TypeBuilder.GetTokenFromSig(JitHelpers.GetQCallModuleOnStack(ref thisModule), localSigBytes, sigLength));
}
#endregion
diff --git a/src/System.Private.CoreLib/src/System/Reflection/Emit/ParameterBuilder.cs b/src/System.Private.CoreLib/src/System/Reflection/Emit/ParameterBuilder.cs
index 1c98383c17..ed96eeedea 100644
--- a/src/System.Private.CoreLib/src/System/Reflection/Emit/ParameterBuilder.cs
+++ b/src/System.Private.CoreLib/src/System/Reflection/Emit/ParameterBuilder.cs
@@ -2,6 +2,8 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
+using System.Runtime.CompilerServices;
+
namespace System.Reflection.Emit
{
public class ParameterBuilder
@@ -56,8 +58,9 @@ namespace System.Reflection.Emit
_name = paramName;
_methodBuilder = methodBuilder;
_attributes = attributes;
+ ModuleBuilder module = _methodBuilder.GetModuleBuilder();
_token = new ParameterToken(TypeBuilder.SetParamInfo(
- _methodBuilder.GetModuleBuilder().GetNativeHandle(),
+ JitHelpers.GetQCallModuleOnStack(ref module),
_methodBuilder.GetToken().Token,
sequence,
attributes,
diff --git a/src/System.Private.CoreLib/src/System/Reflection/Emit/PropertyBuilder.cs b/src/System.Private.CoreLib/src/System/Reflection/Emit/PropertyBuilder.cs
index d9a9bf88db..b33b742832 100644
--- a/src/System.Private.CoreLib/src/System/Reflection/Emit/PropertyBuilder.cs
+++ b/src/System.Private.CoreLib/src/System/Reflection/Emit/PropertyBuilder.cs
@@ -13,6 +13,7 @@
**
===========================================================*/
+using System.Runtime.CompilerServices;
using CultureInfo = System.Globalization.CultureInfo;
namespace System.Reflection.Emit
@@ -89,8 +90,9 @@ namespace System.Reflection.Emit
}
m_containingType.ThrowIfCreated();
+ ModuleBuilder module = m_moduleBuilder;
TypeBuilder.DefineMethodSemantics(
- m_moduleBuilder.GetNativeHandle(),
+ JitHelpers.GetQCallModuleOnStack(ref module),
m_prToken.Token,
semantics,
mdBuilder.GetToken().Token);
diff --git a/src/System.Private.CoreLib/src/System/Reflection/Emit/TypeBuilder.cs b/src/System.Private.CoreLib/src/System/Reflection/Emit/TypeBuilder.cs
index d08153b217..a98c1e9403 100644
--- a/src/System.Private.CoreLib/src/System/Reflection/Emit/TypeBuilder.cs
+++ b/src/System.Private.CoreLib/src/System/Reflection/Emit/TypeBuilder.cs
@@ -141,26 +141,26 @@ namespace System.Reflection.Emit
#region Private Static FCalls
[DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)]
- private static extern void SetParentType(RuntimeModule module, int tdTypeDef, int tkParent);
+ private static extern void SetParentType(QCallModule module, int tdTypeDef, int tkParent);
[DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)]
- private static extern void AddInterfaceImpl(RuntimeModule module, int tdTypeDef, int tkInterface);
+ private static extern void AddInterfaceImpl(QCallModule module, int tdTypeDef, int tkInterface);
#endregion
#region Internal Static FCalls
[DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)]
- internal static extern int DefineMethod(RuntimeModule module, int tkParent, string name, byte[] signature, int sigLength,
+ internal static extern int DefineMethod(QCallModule module, int tkParent, string name, byte[] signature, int sigLength,
MethodAttributes attributes);
[DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)]
- internal static extern int DefineMethodSpec(RuntimeModule module, int tkParent, byte[] signature, int sigLength);
+ internal static extern int DefineMethodSpec(QCallModule module, int tkParent, byte[] signature, int sigLength);
[DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)]
- internal static extern int DefineField(RuntimeModule module, int tkParent, string name, byte[] signature, int sigLength,
+ internal static extern int DefineField(QCallModule module, int tkParent, string name, byte[] signature, int sigLength,
FieldAttributes attributes);
[DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)]
- private static extern void SetMethodIL(RuntimeModule module, int tk, bool isInitLocals,
+ private static extern void SetMethodIL(QCallModule module, int tk, bool isInitLocals,
byte[]? body, int bodyLength,
byte[] LocalSig, int sigLength,
int maxStackSize,
@@ -168,7 +168,7 @@ namespace System.Reflection.Emit
int[]? tokenFixups, int numTokenFixups);
[DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)]
- private static extern void DefineCustomAttribute(RuntimeModule module, int tkAssociate, int tkConstructor,
+ private static extern void DefineCustomAttribute(QCallModule module, int tkAssociate, int tkConstructor,
byte[]? attr, int attrLength, bool toDisk, bool updateCompilerFlags);
internal static void DefineCustomAttribute(ModuleBuilder module, int tkAssociate, int tkConstructor,
@@ -182,45 +182,45 @@ namespace System.Reflection.Emit
Buffer.BlockCopy(attr, 0, localAttr, 0, attr.Length);
}
- DefineCustomAttribute(module.GetNativeHandle(), tkAssociate, tkConstructor,
+ DefineCustomAttribute(JitHelpers.GetQCallModuleOnStack(ref module), tkAssociate, tkConstructor,
localAttr, (localAttr != null) ? localAttr.Length : 0, toDisk, updateCompilerFlags);
}
[DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)]
- internal static extern int DefineProperty(RuntimeModule module, int tkParent, string name, PropertyAttributes attributes,
+ internal static extern int DefineProperty(QCallModule module, int tkParent, string name, PropertyAttributes attributes,
byte[] signature, int sigLength);
[DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)]
- internal static extern int DefineEvent(RuntimeModule module, int tkParent, string name, EventAttributes attributes, int tkEventType);
+ internal static extern int DefineEvent(QCallModule module, int tkParent, string name, EventAttributes attributes, int tkEventType);
[DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)]
- internal static extern void DefineMethodSemantics(RuntimeModule module, int tkAssociation,
+ internal static extern void DefineMethodSemantics(QCallModule module, int tkAssociation,
MethodSemanticsAttributes semantics, int tkMethod);
[DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)]
- internal static extern void DefineMethodImpl(RuntimeModule module, int tkType, int tkBody, int tkDecl);
+ internal static extern void DefineMethodImpl(QCallModule module, int tkType, int tkBody, int tkDecl);
[DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)]
- internal static extern void SetMethodImpl(RuntimeModule module, int tkMethod, MethodImplAttributes MethodImplAttributes);
+ internal static extern void SetMethodImpl(QCallModule module, int tkMethod, MethodImplAttributes MethodImplAttributes);
[DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)]
- internal static extern int SetParamInfo(RuntimeModule module, int tkMethod, int iSequence,
+ internal static extern int SetParamInfo(QCallModule module, int tkMethod, int iSequence,
ParameterAttributes iParamAttributes, string? strParamName);
[DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)]
- internal static extern int GetTokenFromSig(RuntimeModule module, byte[] signature, int sigLength);
+ internal static extern int GetTokenFromSig(QCallModule module, byte[] signature, int sigLength);
[DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)]
- internal static extern void SetFieldLayoutOffset(RuntimeModule module, int fdToken, int iOffset);
+ internal static extern void SetFieldLayoutOffset(QCallModule module, int fdToken, int iOffset);
[DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)]
- internal static extern void SetClassLayout(RuntimeModule module, int tk, PackingSize iPackingSize, int iTypeSize);
+ internal static extern void SetClassLayout(QCallModule module, int tk, PackingSize iPackingSize, int iTypeSize);
[DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)]
- private static extern unsafe void SetConstantValue(RuntimeModule module, int tk, int corType, void* pValue);
+ private static extern unsafe void SetConstantValue(QCallModule module, int tk, int corType, void* pValue);
[DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)]
- private static extern void SetPInvokeData(RuntimeModule module, string DllName, string name, int token, int linkFlags);
+ private static extern void SetPInvokeData(QCallModule module, string DllName, string name, int token, int linkFlags);
#endregion
#region Internal\Private Static Members
@@ -357,20 +357,20 @@ namespace System.Reflection.Emit
case CorElementType.ELEMENT_TYPE_U8:
case CorElementType.ELEMENT_TYPE_R8:
fixed (byte* pData = &value.GetRawData())
- SetConstantValue(module.GetNativeHandle(), tk, (int)corType, pData);
+ SetConstantValue(JitHelpers.GetQCallModuleOnStack(ref module), tk, (int)corType, pData);
break;
default:
if (type == typeof(string))
{
fixed (char* pString = (string)value)
- SetConstantValue(module.GetNativeHandle(), tk, (int)CorElementType.ELEMENT_TYPE_STRING, pString);
+ SetConstantValue(JitHelpers.GetQCallModuleOnStack(ref module), tk, (int)CorElementType.ELEMENT_TYPE_STRING, pString);
}
else if (type == typeof(DateTime))
{
//date is a I8 representation
long ticks = ((DateTime)value).Ticks;
- SetConstantValue(module.GetNativeHandle(), tk, (int)CorElementType.ELEMENT_TYPE_I8, &ticks);
+ SetConstantValue(JitHelpers.GetQCallModuleOnStack(ref module), tk, (int)CorElementType.ELEMENT_TYPE_I8, &ticks);
}
else
{
@@ -385,7 +385,7 @@ namespace System.Reflection.Emit
// (See ECMA-335 II.15.4.1.4 "The .param directive" and II.22.9 "Constant" for details.)
// This is how the Roslyn compilers generally encode `default(TValueType)` default values.
- SetConstantValue(module.GetNativeHandle(), tk, (int)CorElementType.ELEMENT_TYPE_CLASS, null);
+ SetConstantValue(JitHelpers.GetQCallModuleOnStack(ref module), tk, (int)CorElementType.ELEMENT_TYPE_CLASS, null);
}
}
@@ -548,13 +548,13 @@ namespace System.Reflection.Emit
tkEnclosingType = enclosingType.m_tdType.Token;
}
- m_tdType = new TypeToken(DefineType(m_module.GetNativeHandle(),
+ m_tdType = new TypeToken(DefineType(JitHelpers.GetQCallModuleOnStack(ref module),
fullname, tkParent, m_iAttr, tkEnclosingType, interfaceTokens!));
m_iPackingSize = iPackingSize;
m_iTypeSize = iTypeSize;
if ((m_iPackingSize != 0) || (m_iTypeSize != 0))
- SetClassLayout(GetModuleBuilder().GetNativeHandle(), m_tdType.Token, m_iPackingSize, m_iTypeSize);
+ SetClassLayout(JitHelpers.GetQCallModuleOnStack(ref module), m_tdType.Token, m_iPackingSize, m_iTypeSize);
m_module.AddType(FullName!, this);
}
@@ -643,15 +643,15 @@ namespace System.Reflection.Emit
#region FCalls
[DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)]
- private static extern int DefineType(RuntimeModule module,
+ private static extern int DefineType(QCallModule module,
string fullname, int tkParent, TypeAttributes attributes, int tkEnclosingType, int[] interfaceTokens);
[DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)]
- private static extern int DefineGenericParam(RuntimeModule module,
+ private static extern int DefineGenericParam(QCallModule module,
string name, int tkParent, GenericParameterAttributes attributes, int position, int[] constraints);
[DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)]
- private static extern void TermCreateClass(RuntimeModule module, int tk, ObjectHandleOnStack type);
+ private static extern void TermCreateClass(QCallModule module, int tk, ObjectHandleOnStack type);
#endregion
#region Internal Methods
@@ -1289,7 +1289,8 @@ namespace System.Reflection.Emit
MethodToken tkBody = m_module.GetMethodTokenInternal(methodInfoBody);
MethodToken tkDecl = m_module.GetMethodTokenInternal(methodInfoDeclaration);
- DefineMethodImpl(m_module.GetNativeHandle(), m_tdType.Token, tkBody.Token, tkDecl.Token);
+ ModuleBuilder module = m_module;
+ DefineMethodImpl(JitHelpers.GetQCallModuleOnStack(ref module), m_tdType.Token, tkBody.Token, tkDecl.Token);
}
public MethodBuilder DefineMethod(string name, MethodAttributes attributes, Type? returnType, Type[]? parameterTypes)
@@ -1506,7 +1507,8 @@ namespace System.Reflection.Emit
break;
}
- SetPInvokeData(m_module.GetNativeHandle(),
+ ModuleBuilder module = m_module;
+ SetPInvokeData(JitHelpers.GetQCallModuleOnStack(ref module),
dllName,
importName,
token.Token,
@@ -1861,8 +1863,10 @@ namespace System.Reflection.Emit
// get the signature in byte form
sigBytes = sigHelper.InternalGetSignature(out sigLength);
+ ModuleBuilder module = m_module;
+
PropertyToken prToken = new PropertyToken(DefineProperty(
- m_module.GetNativeHandle(),
+ JitHelpers.GetQCallModuleOnStack(ref module),
m_tdType.Token,
name,
attributes,
@@ -1907,8 +1911,9 @@ namespace System.Reflection.Emit
tkType = m_module.GetTypeTokenInternal(eventtype).Token;
// Internal helpers to define property records
+ ModuleBuilder module = m_module;
evToken = new EventToken(DefineEvent(
- m_module.GetNativeHandle(),
+ JitHelpers.GetQCallModuleOnStack(ref module),
m_tdType.Token,
name,
attributes,
@@ -1971,6 +1976,8 @@ namespace System.Reflection.Emit
if (m_typeParent != null)
tkParent = m_module.GetTypeTokenInternal(m_typeParent).Token;
+ ModuleBuilder module = m_module;
+
if (IsGenericParameter)
{
int[] constraints; // Array of token constrains terminated by null token
@@ -1991,7 +1998,7 @@ namespace System.Reflection.Emit
}
int declMember = m_declMeth == null ? m_DeclaringType!.m_tdType.Token : m_declMeth.GetToken().Token;
- m_tdType = new TypeToken(DefineGenericParam(m_module.GetNativeHandle(),
+ m_tdType = new TypeToken(DefineGenericParam(JitHelpers.GetQCallModuleOnStack(ref module),
m_strName!, declMember, m_genParamAttributes, m_genParamPos, constraints));
if (m_ca != null)
@@ -2011,7 +2018,7 @@ namespace System.Reflection.Emit
// Check for global typebuilder
if (((m_tdType.Token & 0x00FFFFFF) != 0) && ((tkParent & 0x00FFFFFF) != 0))
{
- SetParentType(m_module.GetNativeHandle(), m_tdType.Token, tkParent);
+ SetParentType(JitHelpers.GetQCallModuleOnStack(ref module), m_tdType.Token, tkParent);
}
if (m_inst != null)
@@ -2094,7 +2101,7 @@ namespace System.Reflection.Emit
ExceptionHandler[]? exceptions = meth.GetExceptionHandlers();
int[]? tokenFixups = meth.GetTokenFixups();
- SetMethodIL(m_module.GetNativeHandle(), meth.GetToken().Token, meth.InitLocals,
+ SetMethodIL(JitHelpers.GetQCallModuleOnStack(ref module), meth.GetToken().Token, meth.InitLocals,
body, (body != null) ? body.Length : 0,
localSig, sigLength, maxStack,
exceptions, (exceptions != null) ? exceptions.Length : 0,
@@ -2112,7 +2119,7 @@ namespace System.Reflection.Emit
// Terminate the process.
RuntimeType cls = null!;
- TermCreateClass(m_module.GetNativeHandle(), m_tdType.Token, JitHelpers.GetObjectHandleOnStack(ref cls));
+ TermCreateClass(JitHelpers.GetQCallModuleOnStack(ref module), m_tdType.Token, JitHelpers.GetObjectHandleOnStack(ref cls));
if (!m_isHiddenGlobalType)
{
@@ -2187,7 +2194,8 @@ namespace System.Reflection.Emit
ThrowIfCreated();
TypeToken tkInterface = m_module.GetTypeTokenInternal(interfaceType);
- AddInterfaceImpl(m_module.GetNativeHandle(), m_tdType.Token, tkInterface.Token);
+ ModuleBuilder module = m_module;
+ AddInterfaceImpl(JitHelpers.GetQCallModuleOnStack(ref module), m_tdType.Token, tkInterface.Token);
m_typeInterfaces.Add(interfaceType);
}
diff --git a/src/System.Private.CoreLib/src/System/Reflection/Metadata/AssemblyExtensions.cs b/src/System.Private.CoreLib/src/System/Reflection/Metadata/AssemblyExtensions.cs
index 938cf98932..79d39abcca 100644
--- a/src/System.Private.CoreLib/src/System/Reflection/Metadata/AssemblyExtensions.cs
+++ b/src/System.Private.CoreLib/src/System/Reflection/Metadata/AssemblyExtensions.cs
@@ -11,7 +11,7 @@ namespace System.Reflection.Metadata
{
[DllImport(JitHelpers.QCall)]
[return: MarshalAs(UnmanagedType.Bool)]
- private static extern unsafe bool InternalTryGetRawMetadata(RuntimeAssembly assembly, ref byte* blob, ref int length);
+ private static extern unsafe bool InternalTryGetRawMetadata(QCallAssembly assembly, ref byte* blob, ref int length);
// Retrieves the metadata section of the assembly, for use with System.Reflection.Metadata.MetadataReader.
// - Returns false upon failure. Metadata might not be available for some assemblies, such as AssemblyBuilder, .NET
@@ -37,7 +37,9 @@ namespace System.Reflection.Metadata
return false;
}
- return InternalTryGetRawMetadata(runtimeAssembly, ref blob, ref length);
+ RuntimeAssembly rtAsm = runtimeAssembly;
+
+ return InternalTryGetRawMetadata(JitHelpers.GetQCallAssemblyOnStack(ref rtAsm), ref blob, ref length);
}
}
}
diff --git a/src/System.Private.CoreLib/src/System/Reflection/RuntimeAssembly.cs b/src/System.Private.CoreLib/src/System/Reflection/RuntimeAssembly.cs
index bbeba81e2a..a9f80651b9 100644
--- a/src/System.Private.CoreLib/src/System/Reflection/RuntimeAssembly.cs
+++ b/src/System.Private.CoreLib/src/System/Reflection/RuntimeAssembly.cs
@@ -30,6 +30,8 @@ namespace System.Reflection
#endregion
+ internal IntPtr GetUnderlyingNativeHandle() { return m_assembly; }
+
private sealed class ManifestResourceStream : UnmanagedMemoryStream
{
private RuntimeAssembly _manifestAssembly;
@@ -67,14 +69,15 @@ namespace System.Reflection
private const string s_localFilePrefix = "file:";
[DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)]
- private static extern void GetCodeBase(RuntimeAssembly assembly,
+ private static extern void GetCodeBase(QCallAssembly assembly,
bool copiedName,
StringHandleOnStack retString);
internal string? GetCodeBase(bool copiedName)
{
string? codeBase = null;
- GetCodeBase(GetNativeHandle(), copiedName, JitHelpers.GetStringHandleOnStack(ref codeBase));
+ RuntimeAssembly runtimeAssembly = this;
+ GetCodeBase(JitHelpers.GetQCallAssemblyOnStack(ref runtimeAssembly), copiedName, JitHelpers.GetStringHandleOnStack(ref codeBase));
return codeBase;
}
@@ -113,7 +116,7 @@ namespace System.Reflection
}
[DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)]
- private static extern void GetFullName(RuntimeAssembly assembly, StringHandleOnStack retString);
+ private static extern void GetFullName(QCallAssembly assembly, StringHandleOnStack retString);
public override string? FullName
{
@@ -123,7 +126,8 @@ namespace System.Reflection
if (m_fullname == null)
{
string? s = null;
- GetFullName(GetNativeHandle(), JitHelpers.GetStringHandleOnStack(ref s));
+ RuntimeAssembly runtimeAssembly = this;
+ GetFullName(JitHelpers.GetQCallAssemblyOnStack(ref runtimeAssembly), JitHelpers.GetStringHandleOnStack(ref s));
Interlocked.CompareExchange(ref m_fullname, s, null);
}
@@ -132,14 +136,15 @@ namespace System.Reflection
}
[DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)]
- private static extern void GetEntryPoint(RuntimeAssembly assembly, ObjectHandleOnStack retMethod);
+ private static extern void GetEntryPoint(QCallAssembly assembly, ObjectHandleOnStack retMethod);
public override MethodInfo? EntryPoint
{
get
{
IRuntimeMethodInfo? methodHandle = null;
- GetEntryPoint(GetNativeHandle(), JitHelpers.GetObjectHandleOnStack(ref methodHandle));
+ RuntimeAssembly runtimeAssembly = this;
+ GetEntryPoint(JitHelpers.GetQCallAssemblyOnStack(ref runtimeAssembly), JitHelpers.GetObjectHandleOnStack(ref methodHandle));
if (methodHandle == null)
return null;
@@ -149,7 +154,7 @@ namespace System.Reflection
}
[DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)]
- private static extern void GetType(RuntimeAssembly assembly,
+ private static extern void GetType(QCallAssembly assembly,
string name,
bool throwOnError,
bool ignoreCase,
@@ -167,7 +172,8 @@ namespace System.Reflection
object? keepAlive = null;
AssemblyLoadContext? assemblyLoadContextStack = AssemblyLoadContext.CurrentContextualReflectionContext;
- GetType(GetNativeHandle(),
+ RuntimeAssembly runtimeAssembly = this;
+ GetType(JitHelpers.GetQCallAssemblyOnStack(ref runtimeAssembly),
name,
throwOnError,
ignoreCase,
@@ -180,12 +186,13 @@ namespace System.Reflection
}
[DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)]
- private static extern void GetExportedTypes(RuntimeAssembly assembly, ObjectHandleOnStack retTypes);
+ private static extern void GetExportedTypes(QCallAssembly assembly, ObjectHandleOnStack retTypes);
public override Type[] GetExportedTypes()
{
Type[]? types = null;
- GetExportedTypes(GetNativeHandle(), JitHelpers.GetObjectHandleOnStack(ref types));
+ RuntimeAssembly runtimeAssembly = this;
+ GetExportedTypes(JitHelpers.GetQCallAssemblyOnStack(ref runtimeAssembly), JitHelpers.GetObjectHandleOnStack(ref types));
return types!;
}
@@ -211,14 +218,20 @@ namespace System.Reflection
}
[DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)]
- [return: MarshalAs(UnmanagedType.Bool)]
- internal static extern bool GetIsCollectible(RuntimeAssembly assembly);
+ internal static extern Interop.BOOL GetIsCollectible(QCallAssembly assembly);
- public override bool IsCollectible => GetIsCollectible(GetNativeHandle());
+ public override bool IsCollectible
+ {
+ get
+ {
+ RuntimeAssembly runtimeAssembly = this;
+ return GetIsCollectible(JitHelpers.GetQCallAssemblyOnStack(ref runtimeAssembly)) != Interop.BOOL.FALSE;
+ }
+ }
// GetResource will return a pointer to the resources in memory.
[DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)]
- private static extern unsafe byte* GetResource(RuntimeAssembly assembly,
+ private static extern unsafe byte* GetResource(QCallAssembly assembly,
string resourceName,
out uint length);
@@ -241,7 +254,8 @@ namespace System.Reflection
public unsafe override Stream? GetManifestResourceStream(string name)
{
uint length = 0;
- byte* pbInMemoryResource = GetResource(GetNativeHandle(), name, out length);
+ RuntimeAssembly runtimeAssembly = this;
+ byte* pbInMemoryResource = GetResource(JitHelpers.GetQCallAssemblyOnStack(ref runtimeAssembly), name, out length);
if (pbInMemoryResource != null)
{
@@ -353,12 +367,13 @@ namespace System.Reflection
// Returns the module in this assembly with name 'name'
[DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)]
- private static extern void GetModule(RuntimeAssembly assembly, string name, ObjectHandleOnStack retModule);
+ private static extern void GetModule(QCallAssembly assembly, string name, ObjectHandleOnStack retModule);
public override Module? GetModule(string name)
{
Module? retModule = null;
- GetModule(GetNativeHandle(), name, JitHelpers.GetObjectHandleOnStack(ref retModule));
+ RuntimeAssembly runtimeAssembly = this;
+ GetModule(JitHelpers.GetQCallAssemblyOnStack(ref runtimeAssembly), name, JitHelpers.GetObjectHandleOnStack(ref retModule));
return retModule;
}
@@ -410,7 +425,7 @@ namespace System.Reflection
}
[DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)]
- private static extern int GetManifestResourceInfo(RuntimeAssembly assembly,
+ private static extern int GetManifestResourceInfo(QCallAssembly assembly,
string resourceName,
ObjectHandleOnStack assemblyRef,
StringHandleOnStack retFileName);
@@ -419,7 +434,8 @@ namespace System.Reflection
{
RuntimeAssembly? retAssembly = null;
string? fileName = null;
- int location = GetManifestResourceInfo(GetNativeHandle(), resourceName,
+ RuntimeAssembly runtimeAssembly = this;
+ int location = GetManifestResourceInfo(JitHelpers.GetQCallAssemblyOnStack(ref runtimeAssembly), resourceName,
JitHelpers.GetObjectHandleOnStack(ref retAssembly),
JitHelpers.GetStringHandleOnStack(ref fileName));
@@ -431,7 +447,7 @@ namespace System.Reflection
}
[DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)]
- private static extern void GetLocation(RuntimeAssembly assembly, StringHandleOnStack retString);
+ private static extern void GetLocation(QCallAssembly assembly, StringHandleOnStack retString);
public override string Location
{
@@ -439,21 +455,23 @@ namespace System.Reflection
{
string? location = null;
- GetLocation(GetNativeHandle(), JitHelpers.GetStringHandleOnStack(ref location));
+ RuntimeAssembly runtimeAssembly = this;
+ GetLocation(JitHelpers.GetQCallAssemblyOnStack(ref runtimeAssembly), JitHelpers.GetStringHandleOnStack(ref location));
return location!;
}
}
[DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)]
- private static extern void GetImageRuntimeVersion(RuntimeAssembly assembly, StringHandleOnStack retString);
+ private static extern void GetImageRuntimeVersion(QCallAssembly assembly, StringHandleOnStack retString);
public override string ImageRuntimeVersion
{
get
{
string? s = null;
- GetImageRuntimeVersion(GetNativeHandle(), JitHelpers.GetStringHandleOnStack(ref s));
+ RuntimeAssembly runtimeAssembly = this;
+ GetImageRuntimeVersion(JitHelpers.GetQCallAssemblyOnStack(ref runtimeAssembly), JitHelpers.GetStringHandleOnStack(ref s));
return s!;
}
}
@@ -503,7 +521,7 @@ namespace System.Reflection
}
[DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)]
- private static extern void GetVersion(RuntimeAssembly assembly,
+ private static extern void GetVersion(QCallAssembly assembly,
out int majVer,
out int minVer,
out int buildNum,
@@ -512,18 +530,20 @@ namespace System.Reflection
internal Version GetVersion()
{
int majorVer, minorVer, build, revision;
- GetVersion(GetNativeHandle(), out majorVer, out minorVer, out build, out revision);
+ RuntimeAssembly runtimeAssembly = this;
+ GetVersion(JitHelpers.GetQCallAssemblyOnStack(ref runtimeAssembly), out majorVer, out minorVer, out build, out revision);
return new Version(majorVer, minorVer, build, revision);
}
[DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)]
- private static extern void GetLocale(RuntimeAssembly assembly, StringHandleOnStack retString);
+ private static extern void GetLocale(QCallAssembly assembly, StringHandleOnStack retString);
internal CultureInfo GetLocale()
{
string? locale = null;
- GetLocale(GetNativeHandle(), JitHelpers.GetStringHandleOnStack(ref locale));
+ RuntimeAssembly runtimeAssembly = this;
+ GetLocale(JitHelpers.GetQCallAssemblyOnStack(ref runtimeAssembly), JitHelpers.GetStringHandleOnStack(ref locale));
if (locale == null)
return CultureInfo.InvariantCulture;
@@ -543,38 +563,42 @@ namespace System.Reflection
}
[DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)]
- private static extern void GetSimpleName(RuntimeAssembly assembly, StringHandleOnStack retSimpleName);
+ private static extern void GetSimpleName(QCallAssembly assembly, StringHandleOnStack retSimpleName);
internal string? GetSimpleName()
{
+ RuntimeAssembly runtimeAssembly = this;
string? name = null;
- GetSimpleName(GetNativeHandle(), JitHelpers.GetStringHandleOnStack(ref name));
+ GetSimpleName(JitHelpers.GetQCallAssemblyOnStack(ref runtimeAssembly), JitHelpers.GetStringHandleOnStack(ref name));
return name;
}
[DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)]
- private static extern AssemblyHashAlgorithm GetHashAlgorithm(RuntimeAssembly assembly);
+ private static extern AssemblyHashAlgorithm GetHashAlgorithm(QCallAssembly assembly);
private AssemblyHashAlgorithm GetHashAlgorithm()
{
- return GetHashAlgorithm(GetNativeHandle());
+ RuntimeAssembly runtimeAssembly = this;
+ return GetHashAlgorithm(JitHelpers.GetQCallAssemblyOnStack(ref runtimeAssembly));
}
[DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)]
- private static extern AssemblyNameFlags GetFlags(RuntimeAssembly assembly);
+ private static extern AssemblyNameFlags GetFlags(QCallAssembly assembly);
private AssemblyNameFlags GetFlags()
{
- return GetFlags(GetNativeHandle());
+ RuntimeAssembly runtimeAssembly = this;
+ return GetFlags(JitHelpers.GetQCallAssemblyOnStack(ref runtimeAssembly));
}
[DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)]
- private static extern void GetPublicKey(RuntimeAssembly assembly, ObjectHandleOnStack retPublicKey);
+ private static extern void GetPublicKey(QCallAssembly assembly, ObjectHandleOnStack retPublicKey);
internal byte[]? GetPublicKey()
{
byte[]? publicKey = null;
- GetPublicKey(GetNativeHandle(), JitHelpers.GetObjectHandleOnStack(ref publicKey));
+ RuntimeAssembly runtimeAssembly = this;
+ GetPublicKey(JitHelpers.GetQCallAssemblyOnStack(ref runtimeAssembly), JitHelpers.GetObjectHandleOnStack(ref publicKey));
return publicKey;
}
@@ -646,7 +670,7 @@ namespace System.Reflection
}
[DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)]
- private static extern void GetModules(RuntimeAssembly assembly,
+ private static extern void GetModules(QCallAssembly assembly,
bool loadIfNotFound,
bool getResourceModules,
ObjectHandleOnStack retModuleHandles);
@@ -655,7 +679,9 @@ namespace System.Reflection
bool getResourceModules)
{
RuntimeModule[]? modules = null;
- GetModules(GetNativeHandle(), loadIfNotFound, getResourceModules, JitHelpers.GetObjectHandleOnStack(ref modules));
+ RuntimeAssembly runtimeAssembly = this;
+
+ GetModules(JitHelpers.GetQCallAssemblyOnStack(ref runtimeAssembly), loadIfNotFound, getResourceModules, JitHelpers.GetObjectHandleOnStack(ref modules));
return modules!;
}
@@ -682,6 +708,8 @@ namespace System.Reflection
MetadataImport scope = GetManifestModule(GetNativeHandle()).MetadataImport;
scope.Enum(MetadataTokenType.ExportedType, 0, out MetadataEnumResult enumResult);
+ RuntimeAssembly runtimeAssembly = this;
+ QCallAssembly pAssembly = JitHelpers.GetQCallAssemblyOnStack(ref runtimeAssembly);
for (int i = 0; i < enumResult.Length; i++)
{
MetadataToken mdtExternalType = enumResult[i];
@@ -690,7 +718,7 @@ namespace System.Reflection
ObjectHandleOnStack pType = JitHelpers.GetObjectHandleOnStack(ref type);
try
{
- GetForwardedType(this, mdtExternalType, pType);
+ GetForwardedType(pAssembly, mdtExternalType, pType);
if (type == null)
continue; // mdtExternalType was not a forwarder entry.
}
@@ -745,6 +773,6 @@ namespace System.Reflection
}
[DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)]
- private static extern void GetForwardedType(RuntimeAssembly assembly, MetadataToken mdtExternalType, ObjectHandleOnStack type);
+ private static extern void GetForwardedType(QCallAssembly assembly, MetadataToken mdtExternalType, ObjectHandleOnStack type);
}
}
diff --git a/src/System.Private.CoreLib/src/System/Reflection/RuntimeMethodInfo.cs b/src/System.Private.CoreLib/src/System/Reflection/RuntimeMethodInfo.cs
index 5f27d52a95..7ba7576e00 100644
--- a/src/System.Private.CoreLib/src/System/Reflection/RuntimeMethodInfo.cs
+++ b/src/System.Private.CoreLib/src/System/Reflection/RuntimeMethodInfo.cs
@@ -528,7 +528,7 @@ namespace System.Reflection
}
#pragma warning restore CS8608
- public override bool IsCollectible => RuntimeMethodHandle.GetIsCollectible(new RuntimeMethodHandleInternal(m_handle));
+ public override bool IsCollectible => (RuntimeMethodHandle.GetIsCollectible(new RuntimeMethodHandleInternal(m_handle)) != Interop.BOOL.FALSE);
public override MethodInfo? GetBaseDefinition()
{
diff --git a/src/System.Private.CoreLib/src/System/Reflection/RuntimeModule.cs b/src/System.Private.CoreLib/src/System/Reflection/RuntimeModule.cs
index d241ac95c9..c3210e14fd 100644
--- a/src/System.Private.CoreLib/src/System/Reflection/RuntimeModule.cs
+++ b/src/System.Private.CoreLib/src/System/Reflection/RuntimeModule.cs
@@ -15,16 +15,16 @@ namespace System.Reflection
#region FCalls
[DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)]
- private static extern void GetType(RuntimeModule module, string className, bool throwOnError, bool ignoreCase, ObjectHandleOnStack type, ObjectHandleOnStack keepAlive);
+ private static extern void GetType(QCallModule module, string className, bool throwOnError, bool ignoreCase, ObjectHandleOnStack type, ObjectHandleOnStack keepAlive);
[DllImport(JitHelpers.QCall)]
- private static extern bool nIsTransientInternal(RuntimeModule module);
+ private static extern bool nIsTransientInternal(QCallModule module);
[DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)]
- private static extern void GetScopeName(RuntimeModule module, StringHandleOnStack retString);
+ private static extern void GetScopeName(QCallModule module, StringHandleOnStack retString);
[DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)]
- private static extern void GetFullyQualifiedName(RuntimeModule module, StringHandleOnStack retString);
+ private static extern void GetFullyQualifiedName(QCallModule module, StringHandleOnStack retString);
[MethodImplAttribute(MethodImplOptions.InternalCall)]
private static extern RuntimeType[] GetTypes(RuntimeModule module);
@@ -374,7 +374,7 @@ namespace System.Reflection
get
{
if (m_runtimeType == null)
- m_runtimeType = ModuleHandle.GetModuleType(GetNativeHandle());
+ m_runtimeType = ModuleHandle.GetModuleType(this);
return m_runtimeType;
}
@@ -382,7 +382,8 @@ namespace System.Reflection
internal bool IsTransientInternal()
{
- return RuntimeModule.nIsTransientInternal(this.GetNativeHandle());
+ RuntimeModule thisAsLocal = this;
+ return RuntimeModule.nIsTransientInternal(JitHelpers.GetQCallModuleOnStack(ref thisAsLocal));
}
internal MetadataImport MetadataImport
@@ -391,7 +392,7 @@ namespace System.Reflection
{
unsafe
{
- return ModuleHandle.GetMetadataImport(GetNativeHandle());
+ return ModuleHandle.GetMetadataImport(this);
}
}
}
@@ -449,7 +450,8 @@ namespace System.Reflection
RuntimeType? retType = null;
object? keepAlive = null;
- GetType(GetNativeHandle(), className, throwOnError, ignoreCase, JitHelpers.GetObjectHandleOnStack(ref retType), JitHelpers.GetObjectHandleOnStack(ref keepAlive));
+ RuntimeModule thisAsLocal = this;
+ GetType(JitHelpers.GetQCallModuleOnStack(ref thisAsLocal), className, throwOnError, ignoreCase, JitHelpers.GetObjectHandleOnStack(ref retType), JitHelpers.GetObjectHandleOnStack(ref keepAlive));
GC.KeepAlive(keepAlive);
return retType;
}
@@ -457,7 +459,8 @@ namespace System.Reflection
internal string GetFullyQualifiedName()
{
string? fullyQualifiedName = null;
- GetFullyQualifiedName(GetNativeHandle(), JitHelpers.GetStringHandleOnStack(ref fullyQualifiedName));
+ RuntimeModule thisAsLocal = this;
+ GetFullyQualifiedName(JitHelpers.GetQCallModuleOnStack(ref thisAsLocal), JitHelpers.GetStringHandleOnStack(ref fullyQualifiedName));
return fullyQualifiedName!;
}
@@ -536,7 +539,8 @@ namespace System.Reflection
get
{
string? scopeName = null;
- GetScopeName(GetNativeHandle(), JitHelpers.GetStringHandleOnStack(ref scopeName));
+ RuntimeModule thisAsLocal = this;
+ GetScopeName(JitHelpers.GetQCallModuleOnStack(ref thisAsLocal),JitHelpers.GetStringHandleOnStack(ref scopeName));
return scopeName!;
}
}
@@ -581,6 +585,11 @@ namespace System.Reflection
{
return this;
}
+
+ internal IntPtr GetUnderlyingNativeHandle()
+ {
+ return m_pData;
+ }
#endregion
}
}
diff --git a/src/System.Private.CoreLib/src/System/RtType.cs b/src/System.Private.CoreLib/src/System/RtType.cs
index dfdaa7fffa..0bad3f6e91 100644
--- a/src/System.Private.CoreLib/src/System/RtType.cs
+++ b/src/System.Private.CoreLib/src/System/RtType.cs
@@ -3066,7 +3066,14 @@ namespace System
internal sealed override RuntimeTypeHandle GetTypeHandleInternal() => new RuntimeTypeHandle(this);
- public sealed override bool IsCollectible => RuntimeTypeHandle.IsCollectible(GetTypeHandleInternal());
+ public sealed override bool IsCollectible
+ {
+ get
+ {
+ RuntimeType thisType = this;
+ return RuntimeTypeHandle.IsCollectible(JitHelpers.GetQCallTypeHandleOnStack(ref thisType)) != Interop.BOOL.FALSE;
+ }
+ }
protected override TypeCode GetTypeCodeImpl()
{
diff --git a/src/System.Private.CoreLib/src/System/Runtime/CompilerServices/RuntimeHelpers.cs b/src/System.Private.CoreLib/src/System/Runtime/CompilerServices/RuntimeHelpers.cs
index a7d2028727..1c36377794 100644
--- a/src/System.Private.CoreLib/src/System/Runtime/CompilerServices/RuntimeHelpers.cs
+++ b/src/System.Private.CoreLib/src/System/Runtime/CompilerServices/RuntimeHelpers.cs
@@ -63,7 +63,7 @@ namespace System.Runtime.CompilerServices
[DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)]
- internal static extern void _CompileMethod(IRuntimeMethodInfo method);
+ internal static extern void _CompileMethod(RuntimeMethodHandleInternal method);
[MethodImplAttribute(MethodImplOptions.InternalCall)]
private static extern unsafe void _PrepareMethod(IRuntimeMethodInfo method, IntPtr* pInstantiation, int cInstantiation);
diff --git a/src/System.Private.CoreLib/src/System/Runtime/CompilerServices/jithelpers.cs b/src/System.Private.CoreLib/src/System/Runtime/CompilerServices/jithelpers.cs
index dfa32eccf7..bf792c3b11 100644
--- a/src/System.Private.CoreLib/src/System/Runtime/CompilerServices/jithelpers.cs
+++ b/src/System.Private.CoreLib/src/System/Runtime/CompilerServices/jithelpers.cs
@@ -46,6 +46,47 @@ namespace System.Runtime.CompilerServices
}
}
+ internal struct QCallModule
+ {
+ private IntPtr m_ptr;
+ private IntPtr m_module;
+ internal QCallModule(IntPtr pObject, System.Reflection.RuntimeModule module)
+ {
+ m_ptr = pObject;
+ m_module = module.GetUnderlyingNativeHandle();
+ }
+ internal QCallModule(IntPtr pObject, System.Reflection.Emit.ModuleBuilder module)
+ {
+ m_ptr = pObject;
+ m_module = module.GetNativeHandle().GetUnderlyingNativeHandle();
+ }
+ }
+
+ internal struct QCallAssembly
+ {
+ private IntPtr m_ptr;
+ private IntPtr m_assembly;
+ internal QCallAssembly(IntPtr pObject, System.Reflection.RuntimeAssembly assembly)
+ {
+ m_ptr = pObject;
+ m_assembly = assembly.GetUnderlyingNativeHandle();
+ }
+ }
+
+ internal struct QCallTypeHandle
+ {
+ private IntPtr m_ptr;
+ private IntPtr m_handle;
+ internal QCallTypeHandle(IntPtr pObject, RuntimeType type)
+ {
+ m_ptr = pObject;
+ if (type != null)
+ m_handle = type.m_handle;
+ else
+ m_handle = IntPtr.Zero;
+ }
+ }
+
// Helper class to assist with unsafe pinning of arbitrary objects.
// It's used by VM code.
internal class RawData
@@ -78,6 +119,35 @@ namespace System.Runtime.CompilerServices
return new ObjectHandleOnStack((IntPtr)Unsafe.AsPointer(ref o));
}
+ // Wraps RuntimeModule into a handle. Used to pass RuntimeModule to native code wihtout letting it be collected
+ internal static QCallModule GetQCallModuleOnStack(ref System.Reflection.RuntimeModule module)
+ {
+ return new QCallModule((IntPtr)Unsafe.AsPointer(ref module), module);
+ }
+
+ internal static QCallModule GetQCallModuleOnStack(ref System.Reflection.Emit.ModuleBuilder module)
+ {
+ return new QCallModule((IntPtr)Unsafe.AsPointer(ref module), module);
+ }
+
+ // Wraps RuntimeAssembly into a handle. Used to pass RuntimeAssembly to native code wihtout letting it be collected
+ internal static QCallAssembly GetQCallAssemblyOnStack(ref System.Reflection.RuntimeAssembly assembly)
+ {
+ return new QCallAssembly((IntPtr)Unsafe.AsPointer(ref assembly), assembly);
+ }
+
+ // Wraps RuntimeTypeHandle into a handle. Used to pass RuntimeAssembly to native code wihtout letting it be collected
+ internal static QCallTypeHandle GetQCallTypeHandleOnStack(ref System.RuntimeTypeHandle rth)
+ {
+ return new QCallTypeHandle((IntPtr)Unsafe.AsPointer(ref rth.m_type), rth.m_type);
+ }
+
+ // Wraps RuntimeTypeHandle into a handle. Used to pass RuntimeAssembly to native code wihtout letting it be collected
+ internal static QCallTypeHandle GetQCallTypeHandleOnStack(ref System.RuntimeType type)
+ {
+ return new QCallTypeHandle((IntPtr)Unsafe.AsPointer(ref type), type);
+ }
+
// Wraps StackCrawlMark into a handle. Used to pass StackCrawlMark to QCalls.
// stackMark has to be a local variable on the stack.
internal static StackCrawlMarkHandle GetStackCrawlMarkHandle(ref StackCrawlMark stackMark)
diff --git a/src/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshal.CoreCLR.cs b/src/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshal.CoreCLR.cs
index 5fed3237eb..cecf880f59 100644
--- a/src/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshal.CoreCLR.cs
+++ b/src/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshal.CoreCLR.cs
@@ -175,11 +175,12 @@ namespace System.Runtime.InteropServices
throw new ArgumentException(SR.Argument_MustBeRuntimeMethodInfo, nameof(m));
}
- InternalPrelink(rmi);
+ InternalPrelink(((IRuntimeMethodInfo)rmi).Value);
+ GC.KeepAlive(rmi);
}
[DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)]
- private static extern void InternalPrelink(IRuntimeMethodInfo m);
+ private static extern void InternalPrelink(RuntimeMethodHandleInternal m);
[MethodImpl(MethodImplOptions.InternalCall)]
public static extern /* struct _EXCEPTION_POINTERS* */ IntPtr GetExceptionPointers();
@@ -233,14 +234,14 @@ namespace System.Runtime.InteropServices
if (m is RuntimeModule rtModule)
{
- return GetHINSTANCE(rtModule.GetNativeHandle());
+ return GetHINSTANCE(JitHelpers.GetQCallModuleOnStack(ref rtModule));
}
return (IntPtr)(-1);
}
[DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)]
- private static extern IntPtr GetHINSTANCE(RuntimeModule m);
+ private static extern IntPtr GetHINSTANCE(QCallModule m);
#endif // FEATURE_COMINTEROP
diff --git a/src/System.Private.CoreLib/src/System/Runtime/InteropServices/NativeLibrary.CoreCLR.cs b/src/System.Private.CoreLib/src/System/Runtime/InteropServices/NativeLibrary.CoreCLR.cs
index b2002ca768..872eb2b409 100644
--- a/src/System.Private.CoreLib/src/System/Runtime/InteropServices/NativeLibrary.CoreCLR.cs
+++ b/src/System.Private.CoreLib/src/System/Runtime/InteropServices/NativeLibrary.CoreCLR.cs
@@ -12,8 +12,9 @@ namespace System.Runtime.InteropServices
{
internal static IntPtr LoadLibraryByName(string libraryName, Assembly assembly, DllImportSearchPath? searchPath, bool throwOnError)
{
+ RuntimeAssembly rtAsm = (RuntimeAssembly)assembly;
return LoadByName(libraryName,
- ((RuntimeAssembly)assembly).GetNativeHandle(),
+ JitHelpers.GetQCallAssemblyOnStack(ref rtAsm),
searchPath.HasValue,
(uint) searchPath.GetValueOrDefault(),
throwOnError);
@@ -25,7 +26,7 @@ namespace System.Runtime.InteropServices
internal static extern IntPtr LoadFromPath(string libraryName, bool throwOnError);
[DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)]
- internal static extern IntPtr LoadByName(string libraryName, RuntimeAssembly callingAssembly,
+ internal static extern IntPtr LoadByName(string libraryName, QCallAssembly callingAssembly,
bool hasDllImportSearchPathFlag, uint dllImportSearchPathFlag,
bool throwOnError);
diff --git a/src/System.Private.CoreLib/src/System/Runtime/Loader/AssemblyLoadContext.CoreCLR.cs b/src/System.Private.CoreLib/src/System/Runtime/Loader/AssemblyLoadContext.CoreCLR.cs
index 118cf3a1a9..197a07e7ce 100644
--- a/src/System.Private.CoreLib/src/System/Runtime/Loader/AssemblyLoadContext.CoreCLR.cs
+++ b/src/System.Private.CoreLib/src/System/Runtime/Loader/AssemblyLoadContext.CoreCLR.cs
@@ -248,7 +248,7 @@ namespace System.Runtime.Loader
}
[DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)]
- private static extern IntPtr GetLoadContextForAssembly(RuntimeAssembly assembly);
+ private static extern IntPtr GetLoadContextForAssembly(QCallAssembly assembly);
// Returns the load context in which the specified assembly has been loaded
public static AssemblyLoadContext? GetLoadContext(Assembly assembly)
@@ -265,7 +265,8 @@ namespace System.Runtime.Loader
// We only support looking up load context for runtime assemblies.
if (rtAsm != null)
{
- IntPtr ptrAssemblyLoadContext = GetLoadContextForAssembly(rtAsm);
+ RuntimeAssembly runtimeAssembly = rtAsm;
+ IntPtr ptrAssemblyLoadContext = GetLoadContextForAssembly(JitHelpers.GetQCallAssemblyOnStack(ref runtimeAssembly));
if (ptrAssemblyLoadContext == IntPtr.Zero)
{
// If the load context is returned null, then the assembly was bound using the TPA binder
diff --git a/src/System.Private.CoreLib/src/System/RuntimeHandles.cs b/src/System.Private.CoreLib/src/System/RuntimeHandles.cs
index 872a6f1052..591354c95a 100644
--- a/src/System.Private.CoreLib/src/System/RuntimeHandles.cs
+++ b/src/System.Private.CoreLib/src/System/RuntimeHandles.cs
@@ -78,7 +78,7 @@ namespace System
// This is the RuntimeType for the type
- private RuntimeType m_type;
+ internal RuntimeType m_type;
public override int GetHashCode()
{
@@ -318,41 +318,48 @@ namespace System
internal static extern Type[]? GetInterfaces(RuntimeType type);
[DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)]
- private static extern void GetConstraints(RuntimeTypeHandle handle, ObjectHandleOnStack types);
+ private static extern void GetConstraints(QCallTypeHandle handle, ObjectHandleOnStack types);
internal Type[] GetConstraints()
{
Type[]? types = null;
- GetConstraints(GetNativeHandle(), JitHelpers.GetObjectHandleOnStack(ref types));
+ RuntimeTypeHandle nativeHandle = GetNativeHandle();
+
+ GetConstraints(JitHelpers.GetQCallTypeHandleOnStack(ref nativeHandle), JitHelpers.GetObjectHandleOnStack(ref types));
return types!;
}
[DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)]
- private static extern IntPtr GetGCHandle(RuntimeTypeHandle handle, GCHandleType type);
+ private static extern IntPtr GetGCHandle(QCallTypeHandle handle, GCHandleType type);
internal IntPtr GetGCHandle(GCHandleType type)
{
- return GetGCHandle(GetNativeHandle(), type);
+ RuntimeTypeHandle nativeHandle = GetNativeHandle();
+ return GetGCHandle(JitHelpers.GetQCallTypeHandleOnStack(ref nativeHandle), type);
}
[MethodImplAttribute(MethodImplOptions.InternalCall)]
internal static extern int GetNumVirtuals(RuntimeType type);
[DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)]
- private static extern void VerifyInterfaceIsImplemented(RuntimeTypeHandle handle, RuntimeTypeHandle interfaceHandle);
+ private static extern void VerifyInterfaceIsImplemented(QCallTypeHandle handle, QCallTypeHandle interfaceHandle);
internal void VerifyInterfaceIsImplemented(RuntimeTypeHandle interfaceHandle)
{
- VerifyInterfaceIsImplemented(GetNativeHandle(), interfaceHandle.GetNativeHandle());
+ RuntimeTypeHandle nativeHandle = GetNativeHandle();
+ RuntimeTypeHandle nativeInterfaceHandle = interfaceHandle.GetNativeHandle();
+ VerifyInterfaceIsImplemented(JitHelpers.GetQCallTypeHandleOnStack(ref nativeHandle), JitHelpers.GetQCallTypeHandleOnStack(ref nativeInterfaceHandle));
}
[DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)]
- private static extern RuntimeMethodHandleInternal GetInterfaceMethodImplementation(RuntimeTypeHandle handle, RuntimeTypeHandle interfaceHandle, RuntimeMethodHandleInternal interfaceMethodHandle);
+ private static extern RuntimeMethodHandleInternal GetInterfaceMethodImplementation(QCallTypeHandle handle, QCallTypeHandle interfaceHandle, RuntimeMethodHandleInternal interfaceMethodHandle);
internal RuntimeMethodHandleInternal GetInterfaceMethodImplementation(RuntimeTypeHandle interfaceHandle, RuntimeMethodHandleInternal interfaceMethodHandle)
{
- return GetInterfaceMethodImplementation(GetNativeHandle(), interfaceHandle.GetNativeHandle(), interfaceMethodHandle);
+ RuntimeTypeHandle nativeHandle = GetNativeHandle();
+ RuntimeTypeHandle nativeInterfaceHandle = interfaceHandle.GetNativeHandle();
+ return GetInterfaceMethodImplementation(JitHelpers.GetQCallTypeHandleOnStack(ref nativeHandle), JitHelpers.GetQCallTypeHandleOnStack(ref nativeInterfaceHandle), interfaceMethodHandle);
}
[MethodImplAttribute(MethodImplOptions.InternalCall)]
@@ -366,23 +373,24 @@ namespace System
[DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)]
[return: MarshalAs(UnmanagedType.Bool)]
- private static extern bool _IsVisible(RuntimeTypeHandle typeHandle);
+ private static extern bool _IsVisible(QCallTypeHandle typeHandle);
internal static bool IsVisible(RuntimeType type)
{
- return _IsVisible(new RuntimeTypeHandle(type));
+ return _IsVisible(JitHelpers.GetQCallTypeHandleOnStack(ref type));
}
[MethodImplAttribute(MethodImplOptions.InternalCall)]
internal static extern bool IsValueType(RuntimeType type);
[DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)]
- private static extern void ConstructName(RuntimeTypeHandle handle, TypeNameFormatFlags formatFlags, StringHandleOnStack retString);
+ private static extern void ConstructName(QCallTypeHandle handle, TypeNameFormatFlags formatFlags, StringHandleOnStack retString);
internal string ConstructName(TypeNameFormatFlags formatFlags)
{
string? name = null;
- ConstructName(GetNativeHandle(), formatFlags, JitHelpers.GetStringHandleOnStack(ref name));
+ RuntimeTypeHandle nativeHandle = GetNativeHandle();
+ ConstructName(JitHelpers.GetQCallTypeHandleOnStack(ref nativeHandle), formatFlags, JitHelpers.GetStringHandleOnStack(ref name));
return name!;
}
@@ -404,12 +412,13 @@ namespace System
internal static extern IRuntimeMethodInfo GetDeclaringMethod(RuntimeType type);
[DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)]
- private static extern void GetDefaultConstructor(RuntimeTypeHandle handle, ObjectHandleOnStack method);
+ private static extern void GetDefaultConstructor(QCallTypeHandle handle, ObjectHandleOnStack method);
internal IRuntimeMethodInfo? GetDefaultConstructor()
{
IRuntimeMethodInfo? ctor = null;
- GetDefaultConstructor(GetNativeHandle(), JitHelpers.GetObjectHandleOnStack(ref ctor));
+ RuntimeTypeHandle nativeHandle = GetNativeHandle();
+ GetDefaultConstructor(JitHelpers.GetQCallTypeHandleOnStack(ref nativeHandle), JitHelpers.GetObjectHandleOnStack(ref ctor));
return ctor;
}
@@ -449,7 +458,7 @@ namespace System
}
[DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)]
- private static extern void GetTypeByNameUsingCARules(string name, RuntimeModule scope, ObjectHandleOnStack type);
+ private static extern void GetTypeByNameUsingCARules(string name, QCallModule scope, ObjectHandleOnStack type);
internal static RuntimeType GetTypeByNameUsingCARules(string name, RuntimeModule scope)
{
@@ -457,30 +466,32 @@ namespace System
throw new ArgumentException(null, nameof(name));
RuntimeType type = null!;
- GetTypeByNameUsingCARules(name, scope.GetNativeHandle(), JitHelpers.GetObjectHandleOnStack(ref type));
+ GetTypeByNameUsingCARules(name, JitHelpers.GetQCallModuleOnStack(ref scope), JitHelpers.GetObjectHandleOnStack(ref type));
return type;
}
[DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)]
- internal static extern void GetInstantiation(RuntimeTypeHandle type, ObjectHandleOnStack types, bool fAsRuntimeTypeArray);
+ internal static extern void GetInstantiation(QCallTypeHandle type, ObjectHandleOnStack types, Interop.BOOL fAsRuntimeTypeArray);
internal RuntimeType[] GetInstantiationInternal()
{
RuntimeType[] types = null!;
- GetInstantiation(GetNativeHandle(), JitHelpers.GetObjectHandleOnStack(ref types), true);
+ RuntimeTypeHandle nativeHandle = GetNativeHandle();
+ GetInstantiation(JitHelpers.GetQCallTypeHandleOnStack(ref nativeHandle), JitHelpers.GetObjectHandleOnStack(ref types), Interop.BOOL.TRUE);
return types;
}
internal Type[] GetInstantiationPublic()
{
Type[] types = null!;
- GetInstantiation(GetNativeHandle(), JitHelpers.GetObjectHandleOnStack(ref types), false);
+ RuntimeTypeHandle nativeHandle = GetNativeHandle();
+ GetInstantiation(JitHelpers.GetQCallTypeHandleOnStack(ref nativeHandle), JitHelpers.GetObjectHandleOnStack(ref types), Interop.BOOL.FALSE);
return types;
}
[DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)]
- private static extern void Instantiate(RuntimeTypeHandle handle, IntPtr* pInst, int numGenericArgs, ObjectHandleOnStack type);
+ private static extern void Instantiate(QCallTypeHandle handle, IntPtr* pInst, int numGenericArgs, ObjectHandleOnStack type);
internal RuntimeType Instantiate(Type[]? inst)
{
@@ -491,67 +502,75 @@ namespace System
fixed (IntPtr* pInst = instHandles)
{
RuntimeType type = null!;
- Instantiate(GetNativeHandle(), pInst, instCount, JitHelpers.GetObjectHandleOnStack(ref type));
+ RuntimeTypeHandle nativeHandle = GetNativeHandle();
+ Instantiate(JitHelpers.GetQCallTypeHandleOnStack(ref nativeHandle), pInst, instCount, JitHelpers.GetObjectHandleOnStack(ref type));
GC.KeepAlive(inst);
return type;
}
}
[DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)]
- private static extern void MakeArray(RuntimeTypeHandle handle, int rank, ObjectHandleOnStack type);
+ private static extern void MakeArray(QCallTypeHandle handle, int rank, ObjectHandleOnStack type);
internal RuntimeType MakeArray(int rank)
{
RuntimeType type = null!;
- MakeArray(GetNativeHandle(), rank, JitHelpers.GetObjectHandleOnStack(ref type));
+ RuntimeTypeHandle nativeHandle = GetNativeHandle();
+ MakeArray(JitHelpers.GetQCallTypeHandleOnStack(ref nativeHandle), rank, JitHelpers.GetObjectHandleOnStack(ref type));
return type;
}
[DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)]
- private static extern void MakeSZArray(RuntimeTypeHandle handle, ObjectHandleOnStack type);
+ private static extern void MakeSZArray(QCallTypeHandle handle, ObjectHandleOnStack type);
internal RuntimeType MakeSZArray()
{
RuntimeType type = null!;
- MakeSZArray(GetNativeHandle(), JitHelpers.GetObjectHandleOnStack(ref type));
+ RuntimeTypeHandle nativeHandle = GetNativeHandle();
+ MakeSZArray(JitHelpers.GetQCallTypeHandleOnStack(ref nativeHandle), JitHelpers.GetObjectHandleOnStack(ref type));
return type;
}
[DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)]
- private static extern void MakeByRef(RuntimeTypeHandle handle, ObjectHandleOnStack type);
+ private static extern void MakeByRef(QCallTypeHandle handle, ObjectHandleOnStack type);
internal RuntimeType MakeByRef()
{
RuntimeType type = null!;
- MakeByRef(GetNativeHandle(), JitHelpers.GetObjectHandleOnStack(ref type));
+ RuntimeTypeHandle nativeHandle = GetNativeHandle();
+ MakeByRef(JitHelpers.GetQCallTypeHandleOnStack(ref nativeHandle), JitHelpers.GetObjectHandleOnStack(ref type));
return type;
}
[DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)]
- private static extern void MakePointer(RuntimeTypeHandle handle, ObjectHandleOnStack type);
+ private static extern void MakePointer(QCallTypeHandle handle, ObjectHandleOnStack type);
internal RuntimeType MakePointer()
{
RuntimeType type = null!;
- MakePointer(GetNativeHandle(), JitHelpers.GetObjectHandleOnStack(ref type));
+ RuntimeTypeHandle nativeHandle = GetNativeHandle();
+ MakePointer(JitHelpers.GetQCallTypeHandleOnStack(ref nativeHandle), JitHelpers.GetObjectHandleOnStack(ref type));
return type;
}
[DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)]
- internal static extern bool IsCollectible(RuntimeTypeHandle handle);
+ internal static extern Interop.BOOL IsCollectible(QCallTypeHandle handle);
[MethodImplAttribute(MethodImplOptions.InternalCall)]
internal static extern bool HasInstantiation(RuntimeType type);
[DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)]
- private static extern void GetGenericTypeDefinition(RuntimeTypeHandle type, ObjectHandleOnStack retType);
+ private static extern void GetGenericTypeDefinition(QCallTypeHandle type, ObjectHandleOnStack retType);
internal static RuntimeType GetGenericTypeDefinition(RuntimeType type)
{
RuntimeType retType = type;
if (HasInstantiation(retType) && !IsGenericTypeDefinition(retType))
- GetGenericTypeDefinition(retType.GetTypeHandleInternal(), JitHelpers.GetObjectHandleOnStack(ref retType));
+ {
+ RuntimeTypeHandle nativeHandle = retType.GetTypeHandleInternal();
+ GetGenericTypeDefinition(JitHelpers.GetQCallTypeHandleOnStack(ref nativeHandle), JitHelpers.GetObjectHandleOnStack(ref retType));
+ }
return retType;
}
@@ -797,15 +816,14 @@ namespace System
}
[DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)]
- [return: MarshalAs(UnmanagedType.Bool)]
- internal static extern bool GetIsCollectible(RuntimeMethodHandleInternal handle);
+ internal static extern Interop.BOOL GetIsCollectible(RuntimeMethodHandleInternal handle);
[DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)]
- internal static extern bool IsCAVisibleFromDecoratedType(
- RuntimeTypeHandle attrTypeHandle,
- IRuntimeMethodInfo attrCtor,
- RuntimeTypeHandle sourceTypeHandle,
- RuntimeModule sourceModule);
+ internal static extern Interop.BOOL IsCAVisibleFromDecoratedType(
+ QCallTypeHandle attrTypeHandle,
+ RuntimeMethodHandleInternal attrCtor,
+ QCallTypeHandle sourceTypeHandle,
+ QCallModule sourceModule);
[MethodImplAttribute(MethodImplOptions.InternalCall)]
private static extern IRuntimeMethodInfo? _GetCurrentMethod(ref StackCrawlMark stackMark);
@@ -828,12 +846,14 @@ namespace System
internal static extern MethodImplAttributes GetImplAttributes(IRuntimeMethodInfo method);
[DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)]
- private static extern void ConstructInstantiation(IRuntimeMethodInfo method, TypeNameFormatFlags format, StringHandleOnStack retString);
+ private static extern void ConstructInstantiation(RuntimeMethodHandleInternal method, TypeNameFormatFlags format, StringHandleOnStack retString);
internal static string ConstructInstantiation(IRuntimeMethodInfo method, TypeNameFormatFlags format)
{
string? name = null;
- ConstructInstantiation(EnsureNonNullMethodInfo(method), format, JitHelpers.GetStringHandleOnStack(ref name));
+ IRuntimeMethodInfo methodInfo = EnsureNonNullMethodInfo(method);
+ ConstructInstantiation(methodInfo.Value, format, JitHelpers.GetStringHandleOnStack(ref name));
+ GC.KeepAlive(methodInfo);
return name!;
}
@@ -889,12 +909,12 @@ namespace System
internal static extern object InvokeMethod(object? target, object[]? arguments, Signature sig, bool constructor, bool wrapExceptions);
[DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)]
- private static extern void GetMethodInstantiation(RuntimeMethodHandleInternal method, ObjectHandleOnStack types, bool fAsRuntimeTypeArray);
+ private static extern void GetMethodInstantiation(RuntimeMethodHandleInternal method, ObjectHandleOnStack types, Interop.BOOL fAsRuntimeTypeArray);
internal static RuntimeType[] GetMethodInstantiationInternal(IRuntimeMethodInfo method)
{
RuntimeType[] types = null!;
- GetMethodInstantiation(EnsureNonNullMethodInfo(method).Value, JitHelpers.GetObjectHandleOnStack(ref types), true);
+ GetMethodInstantiation(EnsureNonNullMethodInfo(method).Value, JitHelpers.GetObjectHandleOnStack(ref types), Interop.BOOL.TRUE);
GC.KeepAlive(method);
return types;
}
@@ -902,14 +922,14 @@ namespace System
internal static RuntimeType[] GetMethodInstantiationInternal(RuntimeMethodHandleInternal method)
{
RuntimeType[] types = null!;
- GetMethodInstantiation(method, JitHelpers.GetObjectHandleOnStack(ref types), true);
+ GetMethodInstantiation(method, JitHelpers.GetObjectHandleOnStack(ref types), Interop.BOOL.TRUE);
return types;
}
internal static Type[] GetMethodInstantiationPublic(IRuntimeMethodInfo method)
{
RuntimeType[] types = null!;
- GetMethodInstantiation(EnsureNonNullMethodInfo(method).Value, JitHelpers.GetObjectHandleOnStack(ref types), false);
+ GetMethodInstantiation(EnsureNonNullMethodInfo(method).Value, JitHelpers.GetObjectHandleOnStack(ref types), Interop.BOOL.FALSE);
GC.KeepAlive(method);
return types;
}
@@ -944,12 +964,15 @@ namespace System
internal static extern bool IsTypicalMethodDefinition(IRuntimeMethodInfo method);
[DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)]
- private static extern void GetTypicalMethodDefinition(IRuntimeMethodInfo method, ObjectHandleOnStack outMethod);
+ private static extern void GetTypicalMethodDefinition(RuntimeMethodHandleInternal method, ObjectHandleOnStack outMethod);
internal static IRuntimeMethodInfo GetTypicalMethodDefinition(IRuntimeMethodInfo method)
{
if (!IsTypicalMethodDefinition(method))
- GetTypicalMethodDefinition(method, JitHelpers.GetObjectHandleOnStack(ref method));
+ {
+ GetTypicalMethodDefinition(method.Value, JitHelpers.GetObjectHandleOnStack(ref method));
+ GC.KeepAlive(method);
+ }
return method;
}
@@ -960,13 +983,14 @@ namespace System
internal static int GetGenericParameterCount(IRuntimeMethodInfo method) => GetGenericParameterCount(method.Value);
[DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)]
- private static extern void StripMethodInstantiation(IRuntimeMethodInfo method, ObjectHandleOnStack outMethod);
+ private static extern void StripMethodInstantiation(RuntimeMethodHandleInternal method, ObjectHandleOnStack outMethod);
internal static IRuntimeMethodInfo StripMethodInstantiation(IRuntimeMethodInfo method)
{
IRuntimeMethodInfo strippedMethod = method;
- StripMethodInstantiation(method, JitHelpers.GetObjectHandleOnStack(ref strippedMethod));
+ StripMethodInstantiation(method.Value, JitHelpers.GetObjectHandleOnStack(ref strippedMethod));
+ GC.KeepAlive(method);
return strippedMethod;
}
@@ -1269,7 +1293,7 @@ namespace System
fixed (IntPtr* typeInstArgs = typeInstantiationContextHandles, methodInstArgs = methodInstantiationContextHandles)
{
RuntimeType type = null!;
- ResolveType(module, typeToken, typeInstArgs, typeInstCount, methodInstArgs, methodInstCount, JitHelpers.GetObjectHandleOnStack(ref type));
+ ResolveType(JitHelpers.GetQCallModuleOnStack(ref module), typeToken, typeInstArgs, typeInstCount, methodInstArgs, methodInstCount, JitHelpers.GetObjectHandleOnStack(ref type));
GC.KeepAlive(typeInstantiationContext);
GC.KeepAlive(methodInstantiationContext);
return type;
@@ -1277,7 +1301,7 @@ namespace System
}
[DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)]
- private static extern void ResolveType(RuntimeModule module,
+ private static extern void ResolveType(QCallModule module,
int typeToken,
IntPtr* typeInstArgs,
int typeInstCount,
@@ -1317,12 +1341,12 @@ namespace System
fixed (IntPtr* typeInstArgs = typeInstantiationContext, methodInstArgs = methodInstantiationContext)
{
- return ResolveMethod(module.GetNativeHandle(), methodToken, typeInstArgs, typeInstCount, methodInstArgs, methodInstCount);
+ return ResolveMethod(JitHelpers.GetQCallModuleOnStack(ref module), methodToken, typeInstArgs, typeInstCount, methodInstArgs, methodInstCount);
}
}
[DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)]
- private static extern RuntimeMethodHandleInternal ResolveMethod(RuntimeModule module,
+ private static extern RuntimeMethodHandleInternal ResolveMethod(QCallModule module,
int methodToken,
IntPtr* typeInstArgs,
int typeInstCount,
@@ -1350,7 +1374,7 @@ namespace System
fixed (IntPtr* typeInstArgs = typeInstantiationContextHandles, methodInstArgs = methodInstantiationContextHandles)
{
IRuntimeFieldInfo field = null!;
- ResolveField(module.GetNativeHandle(), fieldToken, typeInstArgs, typeInstCount, methodInstArgs, methodInstCount, JitHelpers.GetObjectHandleOnStack(ref field));
+ ResolveField(JitHelpers.GetQCallModuleOnStack(ref module), fieldToken, typeInstArgs, typeInstCount, methodInstArgs, methodInstCount, JitHelpers.GetObjectHandleOnStack(ref field));
GC.KeepAlive(typeInstantiationContext);
GC.KeepAlive(methodInstantiationContext);
return field;
@@ -1358,7 +1382,7 @@ namespace System
}
[DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)]
- private static extern void ResolveField(RuntimeModule module,
+ private static extern void ResolveField(QCallModule module,
int fieldToken,
IntPtr* typeInstArgs,
int typeInstCount,
@@ -1367,31 +1391,31 @@ namespace System
ObjectHandleOnStack retField);
[DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)]
- private static extern bool _ContainsPropertyMatchingHash(RuntimeModule module, int propertyToken, uint hash);
+ private static extern Interop.BOOL _ContainsPropertyMatchingHash(QCallModule module, int propertyToken, uint hash);
internal static bool ContainsPropertyMatchingHash(RuntimeModule module, int propertyToken, uint hash)
{
- return _ContainsPropertyMatchingHash(module.GetNativeHandle(), propertyToken, hash);
+ return _ContainsPropertyMatchingHash(JitHelpers.GetQCallModuleOnStack(ref module), propertyToken, hash) != Interop.BOOL.FALSE;
}
[DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)]
- internal static extern void GetModuleType(RuntimeModule handle, ObjectHandleOnStack type);
+ internal static extern void GetModuleType(QCallModule handle, ObjectHandleOnStack type);
internal static RuntimeType GetModuleType(RuntimeModule module)
{
RuntimeType type = null!;
- GetModuleType(module.GetNativeHandle(), JitHelpers.GetObjectHandleOnStack(ref type));
+ GetModuleType(JitHelpers.GetQCallModuleOnStack(ref module), JitHelpers.GetObjectHandleOnStack(ref type));
return type;
}
[DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)]
- private static extern void GetPEKind(RuntimeModule handle, out int peKind, out int machine);
+ private unsafe static extern void GetPEKind(QCallModule handle, int *peKind, int *machine);
// making this internal, used by Module.GetPEKind
- internal static void GetPEKind(RuntimeModule module, out PortableExecutableKinds peKind, out ImageFileMachine machine)
+ internal unsafe static void GetPEKind(RuntimeModule module, out PortableExecutableKinds peKind, out ImageFileMachine machine)
{
int lKind, lMachine;
- GetPEKind(module.GetNativeHandle(), out lKind, out lMachine);
+ GetPEKind(JitHelpers.GetQCallModuleOnStack(ref module), &lKind, &lMachine);
peKind = (PortableExecutableKinds)lKind;
machine = (ImageFileMachine)lMachine;
}
diff --git a/src/System.Private.CoreLib/src/System/Threading/Thread.CoreCLR.cs b/src/System.Private.CoreLib/src/System/Threading/Thread.CoreCLR.cs
index d466f87fa9..9b3118abba 100644
--- a/src/System.Private.CoreLib/src/System/Threading/Thread.CoreCLR.cs
+++ b/src/System.Private.CoreLib/src/System/Threading/Thread.CoreCLR.cs
@@ -269,9 +269,9 @@ namespace System.Threading
public static void SpinWait(int iterations) => SpinWaitInternal(iterations);
[DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)]
- private static extern bool YieldInternal();
+ private static extern Interop.BOOL YieldInternal();
- public static bool Yield() => YieldInternal();
+ public static bool Yield() => YieldInternal() != Interop.BOOL.FALSE;
[MethodImpl(MethodImplOptions.NoInlining)]
private static Thread InitializeCurrentThread() => (t_currentThread = GetCurrentThreadNative());
diff --git a/src/System.Private.CoreLib/src/System/Threading/ThreadPool.CoreCLR.cs b/src/System.Private.CoreLib/src/System/Threading/ThreadPool.CoreCLR.cs
index eac84d4dbe..53d47b98cf 100644
--- a/src/System.Private.CoreLib/src/System/Threading/ThreadPool.CoreCLR.cs
+++ b/src/System.Private.CoreLib/src/System/Threading/ThreadPool.CoreCLR.cs
@@ -298,7 +298,7 @@ namespace System.Threading
}
[DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)]
- internal static extern bool RequestWorkerThread();
+ internal static extern Interop.BOOL RequestWorkerThread();
[MethodImplAttribute(MethodImplOptions.InternalCall)]
private static extern unsafe bool PostQueuedCompletionStatus(NativeOverlapped* overlapped);
diff --git a/src/tools/r2rdump/R2RReader.cs b/src/tools/r2rdump/R2RReader.cs
index 9f88f38e30..edfbec05f2 100644
--- a/src/tools/r2rdump/R2RReader.cs
+++ b/src/tools/r2rdump/R2RReader.cs
@@ -557,11 +557,15 @@ namespace R2RDump
{
gcInfo = new Amd64.GcInfo(Image, unwindOffset + unwindInfo.Size, Machine, R2RHeader.MajorVersion);
}
+ catch (OverflowException)
+ {
+ Console.WriteLine($"Warning: Could not parse GC Info for method: {method.SignatureString}");
+ }
catch (IndexOutOfRangeException)
{
Console.WriteLine($"Warning: Could not parse GC Info for method: {method.SignatureString}");
}
-
+
}
}
else if (Machine == Machine.I386)
diff --git a/src/vm/commodule.cpp b/src/vm/commodule.cpp
index f2469078c9..6465ac4425 100644
--- a/src/vm/commodule.cpp
+++ b/src/vm/commodule.cpp
@@ -556,7 +556,7 @@ INT32 QCALLTYPE COMModule::GetMemberRefOfMethodInfo(QCall::ModuleHandle pModule,
// Return a MemberRef token given a RuntimeFieldInfo
//
//******************************************************************************
-mdMemberRef QCALLTYPE COMModule::GetMemberRefOfFieldInfo(QCall::ModuleHandle pModule, mdTypeDef tr, void * th, mdFieldDef tkField)
+mdMemberRef QCALLTYPE COMModule::GetMemberRefOfFieldInfo(QCall::ModuleHandle pModule, mdTypeDef tr, QCall::TypeHandle th, mdFieldDef tkField)
{
QCALL_CONTRACT;
@@ -571,7 +571,7 @@ mdMemberRef QCALLTYPE COMModule::GetMemberRefOfFieldInfo(QCall::ModuleHandle pMo
}
else
{
- TypeHandle typeHandle = TypeHandle::FromPtr(th);
+ TypeHandle typeHandle = th.AsTypeHandle();
RefClassWriter * pRCW = pModule->GetReflectionModule()->GetClassWriter();
_ASSERTE(pRCW);
diff --git a/src/vm/commodule.h b/src/vm/commodule.h
index 837a432b17..fd51cd6c5c 100644
--- a/src/vm/commodule.h
+++ b/src/vm/commodule.h
@@ -66,7 +66,7 @@ public:
// GetMemberRefOfFieldInfo
// This function will return a memberRef token given a FieldInfo
static
- mdMemberRef QCALLTYPE GetMemberRefOfFieldInfo(QCall::ModuleHandle pModule, mdTypeDef tr, EnregisteredTypeHandle th, mdFieldDef tkField);
+ mdMemberRef QCALLTYPE GetMemberRefOfFieldInfo(QCall::ModuleHandle pModule, mdTypeDef tr, QCall::TypeHandle th, mdFieldDef tkField);
// GetMemberRefFromSignature
// This function will return the MemberRef token given the signature from managed code
diff --git a/src/vm/ilmarshalers.h b/src/vm/ilmarshalers.h
index 750ac3de20..61ff14267e 100644
--- a/src/vm/ilmarshalers.h
+++ b/src/vm/ilmarshalers.h
@@ -1822,27 +1822,6 @@ protected:
virtual BinderClassID GetManagedTypeBinderID() = 0;
};
-class ILIRuntimeMethodInfoMarshaler : public ILReflectionObjectMarshaler
-{
-protected:
- virtual BinderFieldID GetObjectFieldID() { LIMITED_METHOD_CONTRACT; return FIELD__STUBMETHODINFO__HANDLE; }
- virtual BinderClassID GetManagedTypeBinderID() { LIMITED_METHOD_CONTRACT; return CLASS__STUBMETHODINFO; }
-};
-
-class ILRuntimeModuleMarshaler : public ILReflectionObjectMarshaler
-{
-protected:
- virtual BinderFieldID GetObjectFieldID() { LIMITED_METHOD_CONTRACT; return FIELD__MODULE__DATA; }
- virtual BinderClassID GetManagedTypeBinderID() { LIMITED_METHOD_CONTRACT; return CLASS__MODULE; }
-};
-
-class ILRuntimeAssemblyMarshaler : public ILReflectionObjectMarshaler
-{
-protected:
- virtual BinderFieldID GetObjectFieldID() { LIMITED_METHOD_CONTRACT; return FIELD__ASSEMBLY__HANDLE; }
- virtual BinderClassID GetManagedTypeBinderID() { LIMITED_METHOD_CONTRACT; return CLASS__ASSEMBLY; }
-};
-
class ILRuntimeTypeHandleMarshaler : public ILReflectionObjectMarshaler
{
protected:
diff --git a/src/vm/mlinfo.cpp b/src/vm/mlinfo.cpp
index 8a1eda073c..5899db2d9a 100644
--- a/src/vm/mlinfo.cpp
+++ b/src/vm/mlinfo.cpp
@@ -2266,15 +2266,6 @@ MarshalInfo::MarshalInfo(Module* pModule,
m_args.m_pMT = m_pMT;
m_type = MARSHAL_TYPE_CRITICALHANDLE;
}
- else if (sig.IsClassThrowing(pModule, g_ReflectionMethodInterfaceName, pTypeContext))
- {
- if (nativeType != NATIVE_TYPE_DEFAULT)
- {
- IfFailGoto(E_FAIL, lFail);
- }
-
- m_type = MARSHAL_TYPE_RUNTIMEMETHODINFO;
- }
#ifdef FEATURE_COMINTEROP
else if (m_pMT->IsInterface())
{
@@ -2370,24 +2361,6 @@ MarshalInfo::MarshalInfo(Module* pModule,
}
m_type = MARSHAL_TYPE_LAYOUTCLASSPTR;
m_args.m_pMT = m_pMT;
- }
- else if (sig.IsClassThrowing(pModule, g_ReflectionModuleName, pTypeContext))
- {
- if (nativeType != NATIVE_TYPE_DEFAULT)
- {
- IfFailGoto(E_FAIL, lFail);
- }
-
- m_type = MARSHAL_TYPE_RUNTIMEMODULE;
- }
- else if (sig.IsClassThrowing(pModule, g_ReflectionAssemblyName, pTypeContext))
- {
- if (nativeType != NATIVE_TYPE_DEFAULT)
- {
- IfFailGoto(E_FAIL, lFail);
- }
-
- m_type = MARSHAL_TYPE_RUNTIMEASSEMBLY;
}
#ifdef FEATURE_COMINTEROP
else if (m_ms == MARSHAL_SCENARIO_WINRT && sig.IsClassThrowing(pModule, g_SystemUriClassName, pTypeContext))
@@ -4462,15 +4435,6 @@ VOID MarshalInfo::MarshalTypeToString(SString& strMarshalType, BOOL fSizeIsSpeci
case MARSHAL_TYPE_RUNTIMEMETHODHANDLE:
strRetVal = W("RuntimeMethodHandle");
break;
- case MARSHAL_TYPE_RUNTIMEMETHODINFO:
- strRetVal = W("RuntimeMethodInfo");
- break;
- case MARSHAL_TYPE_RUNTIMEMODULE:
- strRetVal = W("RuntimeModule");
- break;
- case MARSHAL_TYPE_RUNTIMEASSEMBLY:
- strRetVal = W("RuntimeAssembly");
- break;
default:
strRetVal = W("<UNKNOWN>");
break;
diff --git a/src/vm/mtypes.h b/src/vm/mtypes.h
index 5f75eeb6e6..67cb806dd9 100644
--- a/src/vm/mtypes.h
+++ b/src/vm/mtypes.h
@@ -105,9 +105,6 @@ DEFINE_MARSHALER_TYPE(MARSHAL_TYPE_OLECOLOR, OleColorMars
DEFINE_MARSHALER_TYPE(MARSHAL_TYPE_RUNTIMETYPEHANDLE, RuntimeTypeHandleMarshaler, false)
DEFINE_MARSHALER_TYPE(MARSHAL_TYPE_RUNTIMEMETHODHANDLE, RuntimeMethodHandleMarshaler, false)
DEFINE_MARSHALER_TYPE(MARSHAL_TYPE_RUNTIMEFIELDHANDLE, RuntimeFieldHandleMarshaler, false)
-DEFINE_MARSHALER_TYPE(MARSHAL_TYPE_RUNTIMEMETHODINFO, IRuntimeMethodInfoMarshaler, false)
-DEFINE_MARSHALER_TYPE(MARSHAL_TYPE_RUNTIMEMODULE, RuntimeModuleMarshaler, false)
-DEFINE_MARSHALER_TYPE(MARSHAL_TYPE_RUNTIMEASSEMBLY, RuntimeAssemblyMarshaler, false)
#ifdef FEATURE_COMINTEROP
DEFINE_MARSHALER_TYPE(MARSHAL_TYPE_NULLABLE, NullableMarshaler, true)
diff --git a/src/vm/qcall.cpp b/src/vm/qcall.cpp
index bcad868343..5fcfd0ceb8 100644
--- a/src/vm/qcall.cpp
+++ b/src/vm/qcall.cpp
@@ -71,7 +71,7 @@ void QCall::ObjectHandleOnStack::SetGuidArray(const GUID * p, COUNT_T length)
GCX_COOP();
- TypeHandle typeHandle = MscorlibBinder::GetClass(CLASS__GUID);
+ ::TypeHandle typeHandle = MscorlibBinder::GetClass(CLASS__GUID);
BASEARRAYREF arr = (BASEARRAYREF) AllocateSzArray(typeHandle.MakeSZArray(), length);
memcpyNoGCRefs(arr->GetDataPtr(), p, length * sizeof(GUID));
Set(arr);
diff --git a/src/vm/qcall.h b/src/vm/qcall.h
index dd60bbb158..7979331607 100644
--- a/src/vm/qcall.h
+++ b/src/vm/qcall.h
@@ -239,6 +239,7 @@ public:
struct AssemblyHandle
{
+ Object ** m_ppObject;
DomainAssembly * m_pAssembly;
operator DomainAssembly * ()
@@ -256,6 +257,7 @@ public:
struct ModuleHandle
{
+ Object ** m_ppObject;
Module * m_pModule;
operator Module * ()
@@ -271,6 +273,18 @@ public:
}
};
+ struct TypeHandle
+ {
+ Object ** m_ppObject;
+ PTR_VOID m_pTypeHandle;
+
+ ::TypeHandle AsTypeHandle()
+ {
+ LIMITED_METHOD_CONTRACT;
+ return ::TypeHandle::FromPtr(m_pTypeHandle);
+ }
+ };
+
struct LoaderAllocatorHandle
{
LoaderAllocator * m_pLoaderAllocator;
diff --git a/src/vm/reflectioninvocation.cpp b/src/vm/reflectioninvocation.cpp
index 219d40fba0..99879bfad8 100644
--- a/src/vm/reflectioninvocation.cpp
+++ b/src/vm/reflectioninvocation.cpp
@@ -2709,13 +2709,13 @@ public:
}
};
-void QCALLTYPE ReflectionEnum::GetEnumValuesAndNames(EnregisteredTypeHandle pEnumType, QCall::ObjectHandleOnStack pReturnValues, QCall::ObjectHandleOnStack pReturnNames, BOOL fGetNames)
+void QCALLTYPE ReflectionEnum::GetEnumValuesAndNames(QCall::TypeHandle pEnumType, QCall::ObjectHandleOnStack pReturnValues, QCall::ObjectHandleOnStack pReturnNames, BOOL fGetNames)
{
QCALL_CONTRACT;
BEGIN_QCALL;
- TypeHandle th = TypeHandle::FromPtr(pEnumType);
+ TypeHandle th = pEnumType.AsTypeHandle();
if (!th.IsEnum())
COMPlusThrow(kArgumentException, W("Arg_MustBeEnum"));
diff --git a/src/vm/reflectioninvocation.h b/src/vm/reflectioninvocation.h
index 0b4b7692f7..c140f089e0 100644
--- a/src/vm/reflectioninvocation.h
+++ b/src/vm/reflectioninvocation.h
@@ -94,7 +94,7 @@ public:
static FCDECL1(INT32, InternalGetCorElementType, Object *pRefThis);
static
- void QCALLTYPE GetEnumValuesAndNames(EnregisteredTypeHandle pEnumType, QCall::ObjectHandleOnStack pReturnValues, QCall::ObjectHandleOnStack pReturnNames, BOOL fGetNames);
+ void QCALLTYPE GetEnumValuesAndNames(QCall::TypeHandle pEnumType, QCall::ObjectHandleOnStack pReturnValues, QCall::ObjectHandleOnStack pReturnNames, BOOL fGetNames);
static FCDECL2_IV(Object*, InternalBoxEnum, ReflectClassBaseObject* pEnumType, INT64 value);
static FCDECL2(FC_BOOL_RET, InternalEquals, Object *pRefThis, Object* pRefTarget);
diff --git a/src/vm/runtimehandles.cpp b/src/vm/runtimehandles.cpp
index 1880d41773..7d18e7a31d 100644
--- a/src/vm/runtimehandles.cpp
+++ b/src/vm/runtimehandles.cpp
@@ -112,9 +112,9 @@ static BOOL CheckCAVisibilityFromDecoratedType(MethodTable* pCAMT, MethodDesc* p
}
BOOL QCALLTYPE RuntimeMethodHandle::IsCAVisibleFromDecoratedType(
- EnregisteredTypeHandle targetTypeHandle,
+ QCall::TypeHandle targetTypeHandle,
MethodDesc * pTargetCtor,
- EnregisteredTypeHandle sourceTypeHandle,
+ QCall::TypeHandle sourceTypeHandle,
QCall::ModuleHandle sourceModuleHandle)
{
QCALL_CONTRACT;
@@ -122,8 +122,8 @@ BOOL QCALLTYPE RuntimeMethodHandle::IsCAVisibleFromDecoratedType(
BOOL bResult = TRUE;
BEGIN_QCALL;
- TypeHandle sourceHandle = TypeHandle::FromPtr(sourceTypeHandle);
- TypeHandle targetHandle = TypeHandle::FromPtr(targetTypeHandle);
+ TypeHandle sourceHandle = sourceTypeHandle.AsTypeHandle();
+ TypeHandle targetHandle = targetTypeHandle.AsTypeHandle();
_ASSERTE((sourceHandle.IsNull() || !sourceHandle.IsTypeDesc()) &&
!targetHandle.IsNull() &&
@@ -727,14 +727,14 @@ void QCALLTYPE RuntimeMethodHandle::ConstructInstantiation(MethodDesc * pMethod,
END_QCALL;
}
-void QCALLTYPE RuntimeTypeHandle::ConstructName(EnregisteredTypeHandle pTypeHandle, DWORD format, QCall::StringHandleOnStack retString)
+void QCALLTYPE RuntimeTypeHandle::ConstructName(QCall::TypeHandle pTypeHandle, DWORD format, QCall::StringHandleOnStack retString)
{
QCALL_CONTRACT;
BEGIN_QCALL;
StackSString ss;
- TypeString::AppendType(ss, TypeHandle::FromPtr(pTypeHandle), format);
+ TypeString::AppendType(ss, pTypeHandle.AsTypeHandle(), format);
retString.Set(ss);
END_QCALL;
@@ -785,7 +785,7 @@ PTRARRAYREF CopyRuntimeTypeHandles(TypeHandle * prgTH, FixupPointer<TypeHandle>
return refReturn;
}
-void QCALLTYPE RuntimeTypeHandle::GetConstraints(EnregisteredTypeHandle pTypeHandle, QCall::ObjectHandleOnStack retTypeArray)
+void QCALLTYPE RuntimeTypeHandle::GetConstraints(QCall::TypeHandle pTypeHandle, QCall::ObjectHandleOnStack retTypeArray)
{
QCALL_CONTRACT;
@@ -793,7 +793,7 @@ void QCALLTYPE RuntimeTypeHandle::GetConstraints(EnregisteredTypeHandle pTypeHan
BEGIN_QCALL;
- TypeHandle typeHandle = TypeHandle::FromPtr(pTypeHandle);
+ TypeHandle typeHandle = pTypeHandle.AsTypeHandle();
if (!typeHandle.IsGenericVariable())
COMPlusThrow(kArgumentException, W("Arg_InvalidHandle"));
@@ -965,7 +965,7 @@ FCIMPLEND
BOOL
QCALLTYPE
RuntimeTypeHandle::IsVisible(
- EnregisteredTypeHandle pTypeHandle)
+ QCall::TypeHandle pTypeHandle)
{
CONTRACTL
{
@@ -977,7 +977,7 @@ RuntimeTypeHandle::IsVisible(
BEGIN_QCALL;
- TypeHandle typeHandle = TypeHandle::FromPtr(pTypeHandle);
+ TypeHandle typeHandle = pTypeHandle.AsTypeHandle();
_ASSERTE(!typeHandle.IsNull());
@@ -1089,7 +1089,7 @@ FCIMPL1(INT32, RuntimeTypeHandle::GetToken, ReflectClassBaseObject *pTypeUNSAFE)
}
FCIMPLEND
-PVOID QCALLTYPE RuntimeTypeHandle::GetGCHandle(EnregisteredTypeHandle pTypeHandle, INT32 handleType)
+PVOID QCALLTYPE RuntimeTypeHandle::GetGCHandle(QCall::TypeHandle pTypeHandle, INT32 handleType)
{
QCALL_CONTRACT;
@@ -1099,7 +1099,7 @@ PVOID QCALLTYPE RuntimeTypeHandle::GetGCHandle(EnregisteredTypeHandle pTypeHandl
GCX_COOP();
- TypeHandle th = TypeHandle::FromPtr(pTypeHandle);
+ TypeHandle th = pTypeHandle.AsTypeHandle();
assert(handleType >= HNDTYPE_WEAK_SHORT && handleType <= HNDTYPE_WEAK_WINRT);
objHandle = AppDomain::GetCurrentDomain()->CreateTypedHandle(NULL, static_cast<HandleType>(handleType));
th.GetLoaderAllocator()->RegisterHandleForCleanup(objHandle);
@@ -1109,14 +1109,14 @@ PVOID QCALLTYPE RuntimeTypeHandle::GetGCHandle(EnregisteredTypeHandle pTypeHandl
return objHandle;
}
-void QCALLTYPE RuntimeTypeHandle::VerifyInterfaceIsImplemented(EnregisteredTypeHandle pTypeHandle, EnregisteredTypeHandle pIFaceHandle)
+void QCALLTYPE RuntimeTypeHandle::VerifyInterfaceIsImplemented(QCall::TypeHandle pTypeHandle, QCall::TypeHandle pIFaceHandle)
{
QCALL_CONTRACT;
BEGIN_QCALL;
- TypeHandle typeHandle = TypeHandle::FromPtr(pTypeHandle);
- TypeHandle ifaceHandle = TypeHandle::FromPtr(pIFaceHandle);
+ TypeHandle typeHandle = pTypeHandle.AsTypeHandle();
+ TypeHandle ifaceHandle = pIFaceHandle.AsTypeHandle();
if (typeHandle.IsGenericVariable())
COMPlusThrow(kArgumentException, W("Arg_InvalidHandle"));
@@ -1146,7 +1146,7 @@ void QCALLTYPE RuntimeTypeHandle::VerifyInterfaceIsImplemented(EnregisteredTypeH
END_QCALL;
}
-MethodDesc* QCALLTYPE RuntimeTypeHandle::GetInterfaceMethodImplementation(EnregisteredTypeHandle pTypeHandle, EnregisteredTypeHandle pOwner, MethodDesc * pMD)
+MethodDesc* QCALLTYPE RuntimeTypeHandle::GetInterfaceMethodImplementation(QCall::TypeHandle pTypeHandle, QCall::TypeHandle pOwner, MethodDesc * pMD)
{
QCALL_CONTRACT;
@@ -1154,8 +1154,8 @@ MethodDesc* QCALLTYPE RuntimeTypeHandle::GetInterfaceMethodImplementation(Enregi
BEGIN_QCALL;
- TypeHandle typeHandle = TypeHandle::FromPtr(pTypeHandle);
- TypeHandle thOwnerOfMD = TypeHandle::FromPtr(pOwner);
+ TypeHandle typeHandle = pTypeHandle.AsTypeHandle();
+ TypeHandle thOwnerOfMD = pOwner.AsTypeHandle();
// Ok to have INVALID_SLOT in the case where abstract class does not implement an interface method.
// This case can not be reproed using C# "implements" all interface methods
@@ -1171,7 +1171,7 @@ MethodDesc* QCALLTYPE RuntimeTypeHandle::GetInterfaceMethodImplementation(Enregi
return pResult;
}
-void QCALLTYPE RuntimeTypeHandle::GetDefaultConstructor(EnregisteredTypeHandle pTypeHandle, QCall::ObjectHandleOnStack retMethod)
+void QCALLTYPE RuntimeTypeHandle::GetDefaultConstructor(QCall::TypeHandle pTypeHandle, QCall::ObjectHandleOnStack retMethod)
{
QCALL_CONTRACT;
@@ -1179,7 +1179,7 @@ void QCALLTYPE RuntimeTypeHandle::GetDefaultConstructor(EnregisteredTypeHandle p
MethodDesc* pCtor = NULL;
- TypeHandle typeHandle = TypeHandle::FromPtr(pTypeHandle);
+ TypeHandle typeHandle = pTypeHandle.AsTypeHandle();
if (!typeHandle.IsTypeDesc())
{
@@ -1498,13 +1498,13 @@ FCIMPL6(FC_BOOL_RET, RuntimeTypeHandle::SatisfiesConstraints, PTR_ReflectClassBa
}
FCIMPLEND
-void QCALLTYPE RuntimeTypeHandle::GetInstantiation(EnregisteredTypeHandle pType, QCall::ObjectHandleOnStack retTypes, BOOL fAsRuntimeTypeArray)
+void QCALLTYPE RuntimeTypeHandle::GetInstantiation(QCall::TypeHandle pType, QCall::ObjectHandleOnStack retTypes, BOOL fAsRuntimeTypeArray)
{
QCALL_CONTRACT;
BEGIN_QCALL;
- TypeHandle typeHandle = TypeHandle::FromPtr(pType);
+ TypeHandle typeHandle = pType.AsTypeHandle();
Instantiation inst = typeHandle.GetInstantiation();
GCX_COOP();
retTypes.Set(CopyRuntimeTypeHandles(NULL, inst.GetRawArgs(), inst.GetNumArgs(), fAsRuntimeTypeArray ? CLASS__CLASS : CLASS__TYPE));
@@ -1513,14 +1513,14 @@ void QCALLTYPE RuntimeTypeHandle::GetInstantiation(EnregisteredTypeHandle pType,
return;
}
-void QCALLTYPE RuntimeTypeHandle::MakeArray(EnregisteredTypeHandle pTypeHandle, INT32 rank, QCall::ObjectHandleOnStack retType)
+void QCALLTYPE RuntimeTypeHandle::MakeArray(QCall::TypeHandle pTypeHandle, INT32 rank, QCall::ObjectHandleOnStack retType)
{
QCALL_CONTRACT;
TypeHandle arrayHandle;
BEGIN_QCALL;
- arrayHandle = TypeHandle::FromPtr(pTypeHandle).MakeArray(rank);
+ arrayHandle = pTypeHandle.AsTypeHandle().MakeArray(rank);
GCX_COOP();
retType.Set(arrayHandle.GetManagedClassObject());
END_QCALL;
@@ -1528,14 +1528,14 @@ void QCALLTYPE RuntimeTypeHandle::MakeArray(EnregisteredTypeHandle pTypeHandle,
return;
}
-void QCALLTYPE RuntimeTypeHandle::MakeSZArray(EnregisteredTypeHandle pTypeHandle, QCall::ObjectHandleOnStack retType)
+void QCALLTYPE RuntimeTypeHandle::MakeSZArray(QCall::TypeHandle pTypeHandle, QCall::ObjectHandleOnStack retType)
{
QCALL_CONTRACT;
TypeHandle arrayHandle;
BEGIN_QCALL;
- arrayHandle = TypeHandle::FromPtr(pTypeHandle).MakeSZArray();
+ arrayHandle = pTypeHandle.AsTypeHandle().MakeSZArray();
GCX_COOP();
retType.Set(arrayHandle.GetManagedClassObject());
END_QCALL;
@@ -1543,14 +1543,14 @@ void QCALLTYPE RuntimeTypeHandle::MakeSZArray(EnregisteredTypeHandle pTypeHandle
return;
}
-void QCALLTYPE RuntimeTypeHandle::MakePointer(EnregisteredTypeHandle pTypeHandle, QCall::ObjectHandleOnStack retType)
+void QCALLTYPE RuntimeTypeHandle::MakePointer(QCall::TypeHandle pTypeHandle, QCall::ObjectHandleOnStack retType)
{
QCALL_CONTRACT;
TypeHandle pointerHandle;
BEGIN_QCALL;
- pointerHandle = TypeHandle::FromPtr(pTypeHandle).MakePointer();
+ pointerHandle = pTypeHandle.AsTypeHandle().MakePointer();
GCX_COOP();
retType.Set(pointerHandle.GetManagedClassObject());
END_QCALL;
@@ -1558,14 +1558,14 @@ void QCALLTYPE RuntimeTypeHandle::MakePointer(EnregisteredTypeHandle pTypeHandle
return;
}
-void QCALLTYPE RuntimeTypeHandle::MakeByRef(EnregisteredTypeHandle pTypeHandle, QCall::ObjectHandleOnStack retType)
+void QCALLTYPE RuntimeTypeHandle::MakeByRef(QCall::TypeHandle pTypeHandle, QCall::ObjectHandleOnStack retType)
{
QCALL_CONTRACT;
TypeHandle byRefHandle;
BEGIN_QCALL;
- byRefHandle = TypeHandle::FromPtr(pTypeHandle).MakeByRef();
+ byRefHandle = pTypeHandle.AsTypeHandle().MakeByRef();
GCX_COOP();
retType.Set(byRefHandle.GetManagedClassObject());
END_QCALL;
@@ -1573,27 +1573,27 @@ void QCALLTYPE RuntimeTypeHandle::MakeByRef(EnregisteredTypeHandle pTypeHandle,
return;
}
-BOOL QCALLTYPE RuntimeTypeHandle::IsCollectible(EnregisteredTypeHandle pTypeHandle)
+BOOL QCALLTYPE RuntimeTypeHandle::IsCollectible(QCall::TypeHandle pTypeHandle)
{
QCALL_CONTRACT;
BOOL retVal = FALSE;
BEGIN_QCALL;
- retVal = TypeHandle::FromPtr(pTypeHandle).GetLoaderAllocator()->IsCollectible();
+ retVal = pTypeHandle.AsTypeHandle().GetLoaderAllocator()->IsCollectible();
END_QCALL;
return retVal;
}
-void QCALLTYPE RuntimeTypeHandle::Instantiate(EnregisteredTypeHandle pTypeHandle, TypeHandle * pInstArray, INT32 cInstArray, QCall::ObjectHandleOnStack retType)
+void QCALLTYPE RuntimeTypeHandle::Instantiate(QCall::TypeHandle pTypeHandle, TypeHandle * pInstArray, INT32 cInstArray, QCall::ObjectHandleOnStack retType)
{
QCALL_CONTRACT;
TypeHandle type;
BEGIN_QCALL;
- type = TypeHandle::FromPtr(pTypeHandle).Instantiate(Instantiation(pInstArray, cInstArray));
+ type = pTypeHandle.AsTypeHandle().Instantiate(Instantiation(pInstArray, cInstArray));
GCX_COOP();
retType.Set(type.GetManagedClassObject());
END_QCALL;
@@ -1601,7 +1601,7 @@ void QCALLTYPE RuntimeTypeHandle::Instantiate(EnregisteredTypeHandle pTypeHandle
return;
}
-void QCALLTYPE RuntimeTypeHandle::GetGenericTypeDefinition(EnregisteredTypeHandle pTypeHandle, QCall::ObjectHandleOnStack retType)
+void QCALLTYPE RuntimeTypeHandle::GetGenericTypeDefinition(QCall::TypeHandle pTypeHandle, QCall::ObjectHandleOnStack retType)
{
QCALL_CONTRACT;
@@ -1609,7 +1609,7 @@ void QCALLTYPE RuntimeTypeHandle::GetGenericTypeDefinition(EnregisteredTypeHandl
BEGIN_QCALL;
- TypeHandle genericType = TypeHandle::FromPtr(pTypeHandle);
+ TypeHandle genericType = pTypeHandle.AsTypeHandle();
typeDef = ClassLoader::LoadTypeDefThrowing(genericType.GetModule(),
genericType.GetMethodTable()->GetCl(),
diff --git a/src/vm/runtimehandles.h b/src/vm/runtimehandles.h
index c83461a8a5..f0e0caad0e 100644
--- a/src/vm/runtimehandles.h
+++ b/src/vm/runtimehandles.h
@@ -134,18 +134,18 @@ public:
static FCDECL2(Object*, CreateCaInstance, ReflectClassBaseObject* refCaType, ReflectMethodObject* pCtorUNSAFE);
static
- void QCALLTYPE MakeByRef(EnregisteredTypeHandle pTypeHandle, QCall::ObjectHandleOnStack retType);
+ void QCALLTYPE MakeByRef(QCall::TypeHandle pTypeHandle, QCall::ObjectHandleOnStack retType);
static
- void QCALLTYPE MakePointer(EnregisteredTypeHandle pTypeHandle, QCall::ObjectHandleOnStack retType);
+ void QCALLTYPE MakePointer(QCall::TypeHandle pTypeHandle, QCall::ObjectHandleOnStack retType);
static
- void QCALLTYPE MakeSZArray(EnregisteredTypeHandle pTypeHandle, QCall::ObjectHandleOnStack retType);
+ void QCALLTYPE MakeSZArray(QCall::TypeHandle pTypeHandle, QCall::ObjectHandleOnStack retType);
static
- void QCALLTYPE MakeArray(EnregisteredTypeHandle pTypeHandle, INT32 rank, QCall::ObjectHandleOnStack retType);
+ void QCALLTYPE MakeArray(QCall::TypeHandle pTypeHandle, INT32 rank, QCall::ObjectHandleOnStack retType);
- static BOOL QCALLTYPE IsCollectible(EnregisteredTypeHandle pTypeHandle);
+ static BOOL QCALLTYPE IsCollectible(QCall::TypeHandle pTypeHandle);
static FCDECL1(ReflectClassBaseObject*, GetRuntimeType, void *th);
@@ -166,10 +166,10 @@ public:
#endif //FEATURE_COMINTEROP
static
- void QCALLTYPE PrepareMemberInfoCache(EnregisteredTypeHandle pMemberInfoCache);
+ void QCALLTYPE PrepareMemberInfoCache(QCall::TypeHandle pMemberInfoCache);
static
- void QCALLTYPE ConstructName(EnregisteredTypeHandle pTypeHandle, DWORD format, QCall::StringHandleOnStack retString);
+ void QCALLTYPE ConstructName(QCall::TypeHandle pTypeHandle, DWORD format, QCall::StringHandleOnStack retString);
static
void QCALLTYPE GetTypeByNameUsingCARules(LPCWSTR pwzClassName, QCall::ModuleHandle pModule, QCall::ObjectHandleOnStack retType);
@@ -192,7 +192,7 @@ public:
static FCDECL1(ReflectMethodObject*, GetDeclaringMethod, ReflectClassBaseObject *pType);
static
- void QCALLTYPE GetDefaultConstructor(EnregisteredTypeHandle pTypeHandle, QCall::ObjectHandleOnStack retMethod);
+ void QCALLTYPE GetDefaultConstructor(QCall::TypeHandle pTypeHandle, QCall::ObjectHandleOnStack retMethod);
static FCDECL1(ReflectClassBaseObject*, GetDeclaringType, ReflectClassBaseObject* pType);
static FCDECL1(FC_BOOL_RET, IsValueType, ReflectClassBaseObject* pType);
@@ -200,7 +200,7 @@ public:
static FCDECL1(FC_BOOL_RET, IsByRefLike, ReflectClassBaseObject* pType);
static
- BOOL QCALLTYPE IsVisible(EnregisteredTypeHandle pTypeHandle);
+ BOOL QCALLTYPE IsVisible(QCall::TypeHandle pTypeHandle);
static FCDECL2(FC_BOOL_RET, IsComObject, ReflectClassBaseObject *pType, CLR_BOOL isGenericCOM);
static FCDECL2(FC_BOOL_RET, CanCastTo, ReflectClassBaseObject *pType, ReflectClassBaseObject *pTarget);
@@ -223,23 +223,23 @@ public:
FCDECL1(FC_BOOL_RET, ContainsGenericVariables, PTR_ReflectClassBaseObject pType);
static
- void QCALLTYPE GetInstantiation(EnregisteredTypeHandle pTypeHandle, QCall::ObjectHandleOnStack retType, BOOL fAsRuntimeTypeArray);
+ void QCALLTYPE GetInstantiation(QCall::TypeHandle pTypeHandle, QCall::ObjectHandleOnStack retType, BOOL fAsRuntimeTypeArray);
static
- void QCALLTYPE Instantiate(EnregisteredTypeHandle pTypeHandle, TypeHandle * pInstArray, INT32 cInstArray, QCall::ObjectHandleOnStack retType);
+ void QCALLTYPE Instantiate(QCall::TypeHandle pTypeHandle, TypeHandle * pInstArray, INT32 cInstArray, QCall::ObjectHandleOnStack retType);
static
- void QCALLTYPE GetGenericTypeDefinition(EnregisteredTypeHandle pTypeHandle, QCall::ObjectHandleOnStack retType);
+ void QCALLTYPE GetGenericTypeDefinition(QCall::TypeHandle pTypeHandle, QCall::ObjectHandleOnStack retType);
static FCDECL2(FC_BOOL_RET, CompareCanonicalHandles, PTR_ReflectClassBaseObject pLeft, PTR_ReflectClassBaseObject pRight);
static FCDECL1(PtrArray*, GetInterfaces, ReflectClassBaseObject *pType);
static
- void QCALLTYPE GetConstraints(EnregisteredTypeHandle pTypeHandle, QCall::ObjectHandleOnStack retTypes);
+ void QCALLTYPE GetConstraints(QCall::TypeHandle pTypeHandle, QCall::ObjectHandleOnStack retTypes);
static
- PVOID QCALLTYPE GetGCHandle(EnregisteredTypeHandle pTypeHandle, INT32 handleType);
+ PVOID QCALLTYPE GetGCHandle(QCall::TypeHandle pTypeHandle, INT32 handleType);
static FCDECL1(INT32, GetCorElementType, PTR_ReflectClassBaseObject pType);
static FCDECL1(ReflectClassBaseObject*, GetElementType, ReflectClassBaseObject* pType);
@@ -248,10 +248,10 @@ public:
static FCDECL1(INT32, GetNumVirtuals, ReflectClassBaseObject *pType);
static
- void QCALLTYPE VerifyInterfaceIsImplemented(EnregisteredTypeHandle pTypeHandle, EnregisteredTypeHandle pIFaceHandle);
+ void QCALLTYPE VerifyInterfaceIsImplemented(QCall::TypeHandle pTypeHandle, QCall::TypeHandle pIFaceHandle);
static
- MethodDesc* QCALLTYPE GetInterfaceMethodImplementation(EnregisteredTypeHandle pTypeHandle, EnregisteredTypeHandle pOwner, MethodDesc * pMD);
+ MethodDesc* QCALLTYPE GetInterfaceMethodImplementation(QCall::TypeHandle pTypeHandle, QCall::TypeHandle pOwner, MethodDesc * pMD);
static FCDECL3(FC_BOOL_RET, GetFields, ReflectClassBaseObject *pType, INT32 **result, INT32 *pCount);
@@ -301,9 +301,9 @@ public:
static
BOOL QCALLTYPE IsCAVisibleFromDecoratedType(
- EnregisteredTypeHandle targetTypeHandle,
+ QCall::TypeHandle targetTypeHandle,
MethodDesc * pTargetCtor,
- EnregisteredTypeHandle sourceTypeHandle,
+ QCall::TypeHandle sourceTypeHandle,
QCall::ModuleHandle sourceModuleHandle);
static FCDECL4(void, SerializationInvoke, ReflectMethodObject *pMethodUNSAFE, Object* targetUNSAFE,