Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1228,7 +1228,7 @@ private static void AddCustomAttributes(
}
else
{
attribute = attributeType.CreateInstanceDefaultCtor(publicOnly: false, skipCheckThis: true, fillCache: true, wrapExceptions: false)!;
attribute = attributeType.CreateInstanceDefaultCtor(publicOnly: false, wrapExceptions: false)!;

// It is allowed by the ECMA spec to have an empty signature blob
int blobLen = (int)((byte*)blobEnd - (byte*)blobStart);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ public sealed override Delegate CreateDelegate(Type delegateType)
// Compile the method since accessibility checks are done as part of compilation.
GetMethodDescriptor();
IRuntimeMethodInfo? methodHandle = m_methodHandle;
System.Runtime.CompilerServices.RuntimeHelpers._CompileMethod(methodHandle != null ? methodHandle.Value : RuntimeMethodHandleInternal.EmptyHandle);
System.Runtime.CompilerServices.RuntimeHelpers.CompileMethod(methodHandle != null ? methodHandle.Value : RuntimeMethodHandleInternal.EmptyHandle);
GC.KeepAlive(methodHandle);
}

Expand All @@ -363,7 +363,7 @@ public sealed override Delegate CreateDelegate(Type delegateType, object? target
// Compile the method since accessibility checks are done as part of compilation
GetMethodDescriptor();
IRuntimeMethodInfo? methodHandle = m_methodHandle;
System.Runtime.CompilerServices.RuntimeHelpers._CompileMethod(methodHandle != null ? methodHandle.Value : RuntimeMethodHandleInternal.EmptyHandle);
System.Runtime.CompilerServices.RuntimeHelpers.CompileMethod(methodHandle != null ? methodHandle.Value : RuntimeMethodHandleInternal.EmptyHandle);
GC.KeepAlive(methodHandle);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@

using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Serialization;
using Internal.Runtime.CompilerServices;

namespace System.Runtime.CompilerServices
Expand Down Expand Up @@ -39,12 +42,16 @@ public static partial class RuntimeHelpers
// This call will generate an exception if the specified class constructor threw an
// exception when it ran.

[MethodImpl(MethodImplOptions.InternalCall)]
private static extern void _RunClassConstructor(RuntimeType type);
[DllImport(RuntimeHelpers.QCall, CharSet = CharSet.Unicode)]
private static extern void RunClassConstructor(QCallTypeHandle type);

public static void RunClassConstructor(RuntimeTypeHandle type)
{
_RunClassConstructor(type.GetRuntimeType());
RuntimeType rt = type.GetRuntimeType();
if (rt is null)
throw new ArgumentException(SR.InvalidOperation_HandleIsNotInitialized, nameof(type));

RunClassConstructor(new QCallTypeHandle(ref rt));
}

// RunModuleConstructor causes the module constructor for the given type to be triggered
Expand All @@ -55,42 +62,41 @@ public static void RunClassConstructor(RuntimeTypeHandle type)
// This call will generate an exception if the specified module constructor threw an
// exception when it ran.

[MethodImpl(MethodImplOptions.InternalCall)]
private static extern void _RunModuleConstructor(System.Reflection.RuntimeModule module);
[DllImport(RuntimeHelpers.QCall, CharSet = CharSet.Unicode)]
private static extern void RunModuleConstructor(QCallModule module);

public static void RunModuleConstructor(ModuleHandle module)
{
_RunModuleConstructor(module.GetRuntimeModule());
RuntimeModule rm = module.GetRuntimeModule();
if (rm is null)
throw new ArgumentException(SR.InvalidOperation_HandleIsNotInitialized, nameof(module));

RunModuleConstructor(new QCallModule(ref rm));
}

[DllImport(RuntimeHelpers.QCall, CharSet = CharSet.Unicode)]
internal static extern void CompileMethod(RuntimeMethodHandleInternal method);

[DllImport(RuntimeHelpers.QCall, CharSet = CharSet.Unicode)]
internal static extern void _CompileMethod(RuntimeMethodHandleInternal method);
private static extern unsafe void PrepareMethod(RuntimeMethodHandleInternal method, IntPtr* pInstantiation, int cInstantiation);

[MethodImpl(MethodImplOptions.InternalCall)]
private static extern unsafe void _PrepareMethod(IRuntimeMethodInfo method, IntPtr* pInstantiation, int cInstantiation);
public static void PrepareMethod(RuntimeMethodHandle method) => PrepareMethod(method, null);

public static void PrepareMethod(RuntimeMethodHandle method)
public static unsafe void PrepareMethod(RuntimeMethodHandle method, RuntimeTypeHandle[]? instantiation)
{
unsafe
{
_PrepareMethod(method.GetMethodInfo(), null, 0);
}
}
IRuntimeMethodInfo methodInfo = method.GetMethodInfo();
if (methodInfo == null)
throw new ArgumentException(SR.InvalidOperation_HandleIsNotInitialized, nameof(method));

public static void PrepareMethod(RuntimeMethodHandle method, RuntimeTypeHandle[]? instantiation)
{
// defensive copy of user-provided array, per CopyRuntimeTypeHandles contract
instantiation = (RuntimeTypeHandle[]?)instantiation?.Clone();

unsafe
IntPtr[]? instantiationHandles = RuntimeTypeHandle.CopyRuntimeTypeHandles(instantiation, out int length);
fixed (IntPtr* pInstantiation = instantiationHandles)
{
IntPtr[]? instantiationHandles = RuntimeTypeHandle.CopyRuntimeTypeHandles(instantiation, out int length);
fixed (IntPtr* pInstantiation = instantiationHandles)
{
_PrepareMethod(method.GetMethodInfo(), pInstantiation, length);
GC.KeepAlive(instantiation);
}
PrepareMethod(methodInfo.Value, pInstantiation, length);
GC.KeepAlive(instantiation);
GC.KeepAlive(methodInfo);
}
}

Expand Down Expand Up @@ -138,15 +144,32 @@ public static int OffsetToStringData
[MethodImpl(MethodImplOptions.InternalCall)]
public static extern bool TryEnsureSufficientExecutionStack();

[MethodImpl(MethodImplOptions.InternalCall)]
private static extern object GetUninitializedObjectInternal(
public static object GetUninitializedObject(
// This API doesn't call any constructors, but the type needs to be seen as constructed.
// A type is seen as constructed if a constructor is kept.
// This obviously won't cover a type with no constructor. Reference types with no
// constructor are an academic problem. Valuetypes with no constructors are a problem,
// but IL Linker currently treats them as always implicitly boxed.
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)]
Type type);
Type type)
{
if (type is not RuntimeType rt)
{
if (type is null)
{
throw new ArgumentNullException(nameof(type), SR.ArgumentNull_Type);
}

throw new SerializationException(SR.Format(SR.Serialization_InvalidType, type));
}

object? obj = null;
GetUninitializedObject(new QCallTypeHandle(ref rt), ObjectHandleOnStack.Create(ref obj));
return obj!;
}

[DllImport(RuntimeHelpers.QCall)]
private static extern void GetUninitializedObject(QCallTypeHandle type, ObjectHandleOnStack retObject);

[MethodImpl(MethodImplOptions.InternalCall)]
internal static extern object AllocateUninitializedClone(object obj);
Expand Down Expand Up @@ -280,11 +303,11 @@ public static IntPtr AllocateTypeAssociatedMemory(Type type, int size)
if (size < 0)
throw new ArgumentOutOfRangeException(nameof(size));

return AllocateTypeAssociatedMemoryInternal(new QCallTypeHandle(ref rt), (uint)size);
return AllocateTypeAssociatedMemory(new QCallTypeHandle(ref rt), (uint)size);
}

[DllImport(RuntimeHelpers.QCall)]
private static extern IntPtr AllocateTypeAssociatedMemoryInternal(QCallTypeHandle type, uint size);
private static extern IntPtr AllocateTypeAssociatedMemory(QCallTypeHandle type, uint size);

[MethodImpl(MethodImplOptions.InternalCall)]
private static extern IntPtr AllocTailCallArgBuffer(int size, IntPtr gcDesc);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ private static void PrelinkCore(MethodInfo m)
private static object PtrToStructureHelper(IntPtr ptr, Type structureType)
{
var rt = (RuntimeType)structureType;
object structure = rt.CreateInstanceDefaultCtor(publicOnly: false, skipCheckThis: false, fillCache: false, wrapExceptions: true)!;
object structure = rt.CreateInstanceDefaultCtor(publicOnly: false, wrapExceptions: true)!;
PtrToStructureHelper(ptr, structure, allowValueClasses: true);
return structure;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1218,16 +1218,10 @@ public void GetObjectData(SerializationInfo info, StreamingContext context)

public unsafe struct ModuleHandle
{
// Returns handle for interop with EE. The handle is guaranteed to be non-null.
#region Public Static Members
public static readonly ModuleHandle EmptyHandle = GetEmptyMH();
public static readonly ModuleHandle EmptyHandle;
#endregion

private static ModuleHandle GetEmptyMH()
{
return default;
}

#region Private Data Members
private readonly RuntimeModule m_ptr;
#endregion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3895,7 +3895,7 @@ private void CreateInstanceCheckThis()
if (args.Length == 0 && (bindingAttr & BindingFlags.Public) != 0 && (bindingAttr & BindingFlags.Instance) != 0
&& (IsGenericCOMObjectImpl() || IsValueType))
{
instance = CreateInstanceDefaultCtor(publicOnly, skipCheckThis: false, fillCache: true, wrapExceptions);
instance = CreateInstanceDefaultCtor(publicOnly, wrapExceptions);
}
else
{
Expand Down Expand Up @@ -3967,7 +3967,7 @@ private void CreateInstanceCheckThis()
/// </summary>
[DebuggerStepThrough]
[DebuggerHidden]
internal object? CreateInstanceDefaultCtor(bool publicOnly, bool skipCheckThis, bool fillCache, bool wrapExceptions)
internal object? CreateInstanceDefaultCtor(bool publicOnly, bool wrapExceptions)
{
// Get or create the cached factory. Creating the cache will fail if one
// of our invariant checks fails; e.g., no appropriate ctor found.
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/src/vm/corelib.h
Original file line number Diff line number Diff line change
Expand Up @@ -700,7 +700,7 @@ DEFINE_METHOD(RUNTIME_HELPERS, IS_BITWISE_EQUATABLE, IsBitwiseEquatable,
DEFINE_METHOD(RUNTIME_HELPERS, GET_METHOD_TABLE, GetMethodTable, NoSig)
DEFINE_METHOD(RUNTIME_HELPERS, GET_RAW_DATA, GetRawData, NoSig)
DEFINE_METHOD(RUNTIME_HELPERS, GET_RAW_ARRAY_DATA, GetRawArrayData, NoSig)
DEFINE_METHOD(RUNTIME_HELPERS, GET_UNINITIALIZED_OBJECT, GetUninitializedObject, NoSig)
DEFINE_METHOD(RUNTIME_HELPERS, GET_UNINITIALIZED_OBJECT, GetUninitializedObject, SM_Type_RetObj)
DEFINE_METHOD(RUNTIME_HELPERS, ENUM_EQUALS, EnumEquals, NoSig)
DEFINE_METHOD(RUNTIME_HELPERS, ENUM_COMPARE_TO, EnumCompareTo, NoSig)
DEFINE_METHOD(RUNTIME_HELPERS, ALLOC_TAILCALL_ARG_BUFFER, AllocTailCallArgBuffer, SM_Int_IntPtr_RetIntPtr)
Expand Down
12 changes: 6 additions & 6 deletions src/coreclr/src/vm/ecalllist.h
Original file line number Diff line number Diff line change
Expand Up @@ -871,18 +871,18 @@ FCFuncEnd()
FCFuncStart(gRuntimeHelpers)
FCFuncElement("GetObjectValue", ObjectNative::GetObjectValue)
FCIntrinsic("InitializeArray", ArrayNative::InitializeArray, CORINFO_INTRINSIC_InitializeArray)
FCFuncElement("_RunClassConstructor", ReflectionInvocation::RunClassConstructor)
FCFuncElement("_RunModuleConstructor", ReflectionInvocation::RunModuleConstructor)
QCFuncElement("_CompileMethod", ReflectionInvocation::CompileMethod)
FCFuncElement("_PrepareMethod", ReflectionInvocation::PrepareMethod)
QCFuncElement("RunClassConstructor", ReflectionInvocation::RunClassConstructor)
QCFuncElement("RunModuleConstructor", ReflectionInvocation::RunModuleConstructor)
QCFuncElement("CompileMethod", ReflectionInvocation::CompileMethod)
QCFuncElement("PrepareMethod", ReflectionInvocation::PrepareMethod)
FCFuncElement("PrepareDelegate", ReflectionInvocation::PrepareDelegate)
FCFuncElement("GetHashCode", ObjectNative::GetHashCode)
FCFuncElement("Equals", ObjectNative::Equals)
FCFuncElement("AllocateUninitializedClone", ObjectNative::AllocateUninitializedClone)
FCFuncElement("EnsureSufficientExecutionStack", ReflectionInvocation::EnsureSufficientExecutionStack)
FCFuncElement("TryEnsureSufficientExecutionStack", ReflectionInvocation::TryEnsureSufficientExecutionStack)
FCFuncElement("GetUninitializedObjectInternal", ReflectionSerialization::GetUninitializedObject)
QCFuncElement("AllocateTypeAssociatedMemoryInternal", RuntimeTypeHandle::AllocateTypeAssociatedMemory)
QCFuncElement("GetUninitializedObject", ReflectionSerialization::GetUninitializedObject)
QCFuncElement("AllocateTypeAssociatedMemory", RuntimeTypeHandle::AllocateTypeAssociatedMemory)
FCFuncElement("AllocTailCallArgBuffer", TailCallHelp::AllocTailCallArgBuffer)
FCFuncElement("GetTailCallInfo", TailCallHelp::GetTailCallInfo)
FCFuncElement("GetILBytesJitted", GetJittedBytes)
Expand Down
1 change: 1 addition & 0 deletions src/coreclr/src/vm/metasig.h
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,7 @@ DEFINE_METASIG(SM(Int_Str_IntPtr_Int_RetVoid, i s I i, v))
DEFINE_METASIG(SM(Str_IntPtr_RetIntPtr, s I, I))
DEFINE_METASIG(SM(Str_Bool_Int_RetV, s F i, v))

DEFINE_METASIG_T(SM(Type_RetObj, C(TYPE), j))
DEFINE_METASIG_T(SM(Type_RetInt, C(TYPE), i))
DEFINE_METASIG(SM(ArrByte_RetObj, a(b), j))
DEFINE_METASIG(SM(ArrByte_Bool_RetObj, a(b) F, j))
Expand Down
Loading