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 @@ -762,10 +762,17 @@ private static extern bool Contains(
[UnsafeAccessorType(LicInfoHelperLicenseContextTypeName)] object? licInfoHelperContext,
string assemblyName);

// Helper function to create an object from the native side
public static object Create()
[UnmanagedCallersOnly]
private static unsafe void Create(object* pResult, Exception* pException)
{
return new LicenseInteropProxy();
try
{
*pResult = new LicenseInteropProxy();
}
catch (Exception ex)
{
*pException = ex;
}
}

// Determine if the type supports licensing
Expand Down Expand Up @@ -877,6 +884,19 @@ public void GetCurrentContextInfo(RuntimeTypeHandle rth, out bool isDesignTime,
bstrKey = Marshal.StringToBSTR((string)key!);
}

[UnmanagedCallersOnly]
private static unsafe void GetCurrentContextInfo(LicenseInteropProxy* pProxy, Type* pType, bool* pIsDesignTime, IntPtr* pBstrKey, Exception* pException)
{
try
{
pProxy->GetCurrentContextInfo(pType->TypeHandle, out *pIsDesignTime, out *pBstrKey);
}
catch (Exception ex)
{
*pException = ex;
}
}

// The CLR invokes this when instantiating a licensed COM
// object inside a designtime license context.
// It's purpose is to save away the license key that the CLR
Expand All @@ -892,5 +912,18 @@ public void SaveKeyInCurrentContext(IntPtr bstrKey)

SetSavedLicenseKey(_licContext!, _targetRcwType!, key);
}

[UnmanagedCallersOnly]
private static unsafe void SaveKeyInCurrentContext(LicenseInteropProxy* pProxy, IntPtr bstrKey, Exception* pException)
{
try
{
pProxy->SaveKeyInCurrentContext(bstrKey);
}
catch (Exception ex)
{
*pException = ex;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4219,6 +4219,39 @@ private object InvokeDispMethod(
return ret;
}

[RequiresUnreferencedCode("The member might be removed")]
[UnmanagedCallersOnly]
private static unsafe void ForwardCallToInvokeMember(
RuntimeType* pRuntimeType,
string* pMemberName,
int flags,
object* pTarget,
object[]* pArgs,
bool[]* pArgsIsByRef,
int[]* pArgsWrapperTypes,
Type[]* pArgsTypes,
Type* pRetType,
object* pResult,
Exception* pException)
{
try
{
*pResult = pRuntimeType->ForwardCallToInvokeMember(
*pMemberName,
(BindingFlags)flags,
*pTarget,
*pArgs,
*pArgsIsByRef,
*pArgsWrapperTypes,
*pArgsTypes,
*pRetType);
}
catch (Exception ex)
{
*pException = ex;
}
}

private static void WrapArgsForInvokeCall(object[] aArgs, int[] aArgsWrapperTypes)
{
int cArgs = aArgs.Length;
Expand Down
14 changes: 14 additions & 0 deletions src/coreclr/System.Private.CoreLib/src/System/StubHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1491,6 +1491,20 @@ internal static void SetPendingExceptionObject(Exception? exception)
#if FEATURE_COMINTEROP
[SupportedOSPlatform("windows")]
internal static object GetIEnumeratorToEnumVariantMarshaler() => EnumeratorToEnumVariantMarshaler.GetInstance(string.Empty);

[SupportedOSPlatform("windows")]
[UnmanagedCallersOnly]
private static unsafe void GetIEnumeratorToEnumVariantMarshaler(object* pResult, Exception* pException)
{
try
{
*pResult = GetIEnumeratorToEnumVariantMarshaler();
}
catch (Exception ex)
{
*pException = ex;
}
}
#endif

internal static object CreateCustomMarshaler(IntPtr pMD, int paramToken, IntPtr hndManagedType)
Expand Down
39 changes: 39 additions & 0 deletions src/coreclr/System.Private.CoreLib/src/System/Variant.cs
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,19 @@ internal static void MarshalHelperConvertObjectToVariant(object? o, out ComVaria
}
}

[UnmanagedCallersOnly]
private static unsafe void MarshalHelperConvertObjectToVariant(object* pObject, ComVariant* pOle, Exception* pException)
{
try
{
MarshalHelperConvertObjectToVariant(*pObject, out *pOle);
}
catch (Exception ex)
{
*pException = ex;
}
}

// Helper code for marshaling VARIANTS to managed objects
internal static unsafe object? MarshalHelperConvertVariantToObject(ref readonly ComVariant pOle)
{
Expand Down Expand Up @@ -320,6 +333,19 @@ internal static void MarshalHelperConvertObjectToVariant(object? o, out ComVaria
}
}

[UnmanagedCallersOnly]
private static unsafe void MarshalHelperConvertVariantToObject(ComVariant* pOle, object* pResult, Exception* pException)
{
try
{
*pResult = MarshalHelperConvertVariantToObject(in *pOle);
}
catch (Exception ex)
{
*pException = ex;
}
}

// Helper code: on the back propagation path where a VT_BYREF VARIANT*
// is marshaled to a "ref Object", we use this helper to force the
// updated object back to the original type.
Expand Down Expand Up @@ -396,5 +422,18 @@ internal static void MarshalHelperCastVariant(object pValue, int vt, out ComVari
};
}
}

[UnmanagedCallersOnly]
private static unsafe void MarshalHelperCastVariant(object* pValue, int vt, ComVariant* pOle, Exception* pException)
{
try
{
MarshalHelperCastVariant(*pValue!, vt, out *pOle);
}
catch (Exception ex)
{
*pException = ex;
}
}
}
}
14 changes: 14 additions & 0 deletions src/coreclr/System.Private.CoreLib/src/System/__ComObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,20 @@ internal object GetEventProvider(
return CreateEventProvider(t);
}

[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2062:Value passed to parameter cannot be statically determined", Justification = "The runtime passes a RuntimeType describing the COM event provider. The dynamic constructor access requirements are enforced by runtime callsite semantics.")]
[UnmanagedCallersOnly]
private static unsafe void GetEventProvider(__ComObject* pComObject, RuntimeType* pProviderType, object* pResult, Exception* pException)
{
try
{
*pResult = pComObject->GetEventProvider(*pProviderType);
}
catch (Exception ex)
{
*pException = ex;
}
}

private object CreateEventProvider(
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)] RuntimeType t)
{
Expand Down
41 changes: 17 additions & 24 deletions src/coreclr/vm/clrtocomcall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -316,16 +316,10 @@ UINT32 CLRToCOMEventCallWorker(CLRToCOMMethodFrame* pFrame, CLRToCOMCallMethodDe
gc.EventProviderTypeObj = pEvProvMT->GetManagedClassObject();
gc.ThisObj = pFrame->GetThis();

MethodDescCallSite getEventProvider(METHOD__COM_OBJECT__GET_EVENT_PROVIDER, &gc.ThisObj);
UnmanagedCallersOnlyCaller getEventProvider(METHOD__COM_OBJECT__GET_EVENT_PROVIDER);

// Retrieve the event provider for the event interface type.
ARG_SLOT GetEventProviderArgs[] =
{
ObjToArgSlot(gc.ThisObj),
ObjToArgSlot(gc.EventProviderTypeObj)
};

gc.EventProviderObj = getEventProvider.Call_RetOBJECTREF(GetEventProviderArgs);
getEventProvider.InvokeThrowing(&gc.ThisObj, &gc.EventProviderTypeObj, &gc.EventProviderObj);

// Set up an arg iterator to retrieve the arguments from the frame.
MetaSig mSig(pMD);
Expand Down Expand Up @@ -601,6 +595,7 @@ UINT32 CLRToCOMLateBoundWorker(
{
OBJECTREF MemberName;
OBJECTREF ItfTypeObj;
OBJECTREF ThisObj;
PTRARRAYREF Args;
BOOLARRAYREF ArgsIsByRef;
PTRARRAYREF ArgsTypes;
Expand All @@ -610,6 +605,7 @@ UINT32 CLRToCOMLateBoundWorker(
} gc;
gc.MemberName = NULL;
gc.ItfTypeObj = NULL;
gc.ThisObj = NULL;
gc.Args = NULL;
gc.ArgsIsByRef = NULL;
gc.ArgsTypes = NULL;
Expand Down Expand Up @@ -648,6 +644,7 @@ UINT32 CLRToCOMLateBoundWorker(
// Return type
TypeHandle retValHandle = callsite.MetaSig.GetRetTypeHandleThrowing();
gc.RetValType = retValHandle.GetManagedClassObject();
gc.ThisObj = pFrame->GetThis();

// the return value is written into the Frame's neginfo, so we don't
// need to return it directly. We can just have the stub do that work.
Expand All @@ -662,24 +659,20 @@ UINT32 CLRToCOMLateBoundWorker(
}

// Create a call site for the invoke
MethodDescCallSite forwardCallToInvoke(METHOD__CLASS__FORWARD_CALL_TO_INVOKE, &gc.ItfTypeObj);

// Prepare the arguments that will be passed to the method.
ARG_SLOT invokeArgs[] =
{
ObjToArgSlot(gc.ItfTypeObj),
ObjToArgSlot(gc.MemberName),
(ARG_SLOT)binderFlags,
ObjToArgSlot(pFrame->GetThis()),
ObjToArgSlot(gc.Args),
ObjToArgSlot(gc.ArgsIsByRef),
ObjToArgSlot(gc.ArgsWrapperTypes),
ObjToArgSlot(gc.ArgsTypes),
ObjToArgSlot(gc.RetValType)
};
UnmanagedCallersOnlyCaller forwardCallToInvoke(METHOD__CLASS__FORWARD_CALL_TO_INVOKE);

// Invoke the method
gc.RetVal = forwardCallToInvoke.CallWithValueTypes_RetOBJECTREF(invokeArgs);
forwardCallToInvoke.InvokeThrowing(
&gc.ItfTypeObj,
&gc.MemberName,
(INT32)binderFlags,
&gc.ThisObj,
&gc.Args,
&gc.ArgsIsByRef,
&gc.ArgsWrapperTypes,
&gc.ArgsTypes,
&gc.RetValType,
&gc.RetVal);

// Ensure all outs and return values are moved back to the current callsite
CallsiteInspect::PropagateOutParametersBackToCallsite(gc.Args, gc.RetVal, callsite);
Expand Down
18 changes: 9 additions & 9 deletions src/coreclr/vm/corelib.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ DEFINE_METHOD(CLASS, CTOR, .ctor,
#endif // FOR_ILLINK

#ifdef FEATURE_COMINTEROP
DEFINE_METHOD(CLASS, FORWARD_CALL_TO_INVOKE, ForwardCallToInvokeMember, IM_Str_BindingFlags_Obj_ArrObj_ArrBool_ArrInt_ArrType_Type_RetObj)
DEFINE_METHOD(CLASS, FORWARD_CALL_TO_INVOKE, ForwardCallToInvokeMember, SM_PtrClass_PtrStr_Int_PtrObj_PtrArrObj_PtrArrBool_PtrArrInt_PtrArrType_PtrType_PtrObj_PtrException_RetVoid)
#endif // FEATURE_COMINTEROP

BEGIN_ILLINK_FEATURE_SWITCH(System.Runtime.InteropServices.BuiltInComInterop.IsSupported, true, true)
Expand All @@ -179,15 +179,15 @@ DEFINE_CLASS_U(System, __ComObject, ComObject)
DEFINE_FIELD_U(m_ObjectToDataMap, ComObject, m_ObjectToDataMap)
DEFINE_CLASS(COM_OBJECT, System, __ComObject)
DEFINE_METHOD(COM_OBJECT, RELEASE_ALL_DATA, ReleaseAllData, IM_RetVoid)
DEFINE_METHOD(COM_OBJECT, GET_EVENT_PROVIDER, GetEventProvider, IM_Class_RetObj)
DEFINE_METHOD(COM_OBJECT, GET_EVENT_PROVIDER, GetEventProvider, SM_PtrComObject_PtrClass_PtrObj_PtrException_RetVoid)
#ifdef FOR_ILLINK
DEFINE_METHOD(COM_OBJECT, CTOR, .ctor, IM_RetVoid)
#endif // FOR_ILLINK

DEFINE_CLASS(LICENSE_INTEROP_PROXY, InternalInteropServices, LicenseInteropProxy)
DEFINE_METHOD(LICENSE_INTEROP_PROXY, CREATE, Create, SM_RetObj)
DEFINE_METHOD(LICENSE_INTEROP_PROXY, GETCURRENTCONTEXTINFO, GetCurrentContextInfo, IM_RuntimeTypeHandle_RefBool_RefIntPtr_RetVoid)
DEFINE_METHOD(LICENSE_INTEROP_PROXY, SAVEKEYINCURRENTCONTEXT, SaveKeyInCurrentContext, IM_IntPtr_RetVoid)
DEFINE_METHOD(LICENSE_INTEROP_PROXY, CREATE, Create, SM_PtrObj_PtrException_RetVoid)
DEFINE_METHOD(LICENSE_INTEROP_PROXY, GETCURRENTCONTEXTINFO, GetCurrentContextInfo, SM_PtrLicenseInteropProxy_PtrType_PtrBool_PtrIntPtr_PtrException_RetVoid)
DEFINE_METHOD(LICENSE_INTEROP_PROXY, SAVEKEYINCURRENTCONTEXT, SaveKeyInCurrentContext, SM_PtrLicenseInteropProxy_IntPtr_PtrException_RetVoid)

#endif // FEATURE_COMINTEROP
END_ILLINK_FEATURE_SWITCH()
Expand Down Expand Up @@ -384,9 +384,9 @@ DEFINE_CLASS(GUID, System, Guid)
BEGIN_ILLINK_FEATURE_SWITCH(System.Runtime.InteropServices.BuiltInComInterop.IsSupported, true, true)
#ifdef FEATURE_COMINTEROP
DEFINE_CLASS(VARIANT, System, Variant)
DEFINE_METHOD(VARIANT, CONVERT_OBJECT_TO_VARIANT,MarshalHelperConvertObjectToVariant,SM_Obj_RefComVariant_RetVoid)
DEFINE_METHOD(VARIANT, CAST_VARIANT, MarshalHelperCastVariant, SM_Obj_Int_RefComVariant_RetVoid)
DEFINE_METHOD(VARIANT, CONVERT_VARIANT_TO_OBJECT,MarshalHelperConvertVariantToObject,SM_RefComVariant_RetObject)
DEFINE_METHOD(VARIANT, CONVERT_OBJECT_TO_VARIANT, MarshalHelperConvertObjectToVariant, SM_PtrObj_PtrComVariant_PtrException_RetVoid)
DEFINE_METHOD(VARIANT, CAST_VARIANT, MarshalHelperCastVariant, SM_PtrObj_Int_PtrComVariant_PtrException_RetVoid)
DEFINE_METHOD(VARIANT, CONVERT_VARIANT_TO_OBJECT, MarshalHelperConvertVariantToObject, SM_PtrComVariant_PtrObj_PtrException_RetVoid)

#endif // FEATURE_COMINTEROP
END_ILLINK_FEATURE_SWITCH()
Expand Down Expand Up @@ -1045,7 +1045,7 @@ DEFINE_METHOD(STUBHELPERS, GET_HR_EXCEPTION_OBJECT, GetHRExceptionObjec
DEFINE_METHOD(STUBHELPERS, GET_PENDING_EXCEPTION_OBJECT, GetPendingExceptionObject, SM_RetException)
DEFINE_METHOD(STUBHELPERS, CREATE_CUSTOM_MARSHALER, CreateCustomMarshaler, SM_IntPtr_Int_IntPtr_RetObj)
#ifdef FEATURE_COMINTEROP
DEFINE_METHOD(STUBHELPERS, GET_IENUMERATOR_TO_ENUM_VARIANT_MARSHALER, GetIEnumeratorToEnumVariantMarshaler, SM_RetObj)
DEFINE_METHOD(STUBHELPERS, GET_IENUMERATOR_TO_ENUM_VARIANT_MARSHALER, GetIEnumeratorToEnumVariantMarshaler, SM_PtrObj_PtrException_RetVoid)
#endif // FEATURE_COMINTEROP

DEFINE_METHOD(STUBHELPERS, CHECK_STRING_LENGTH, CheckStringLength, SM_Int_RetVoid)
Expand Down
4 changes: 2 additions & 2 deletions src/coreclr/vm/custommarshalerinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ CustomMarshalerInfo* CustomMarshalerInfo::CreateIEnumeratorMarshalerInfo(LoaderH
GCX_COOP();
GCPROTECT_BEGIN(IEnumeratorMarshalerObj);

MethodDescCallSite getMarshaler(METHOD__STUBHELPERS__GET_IENUMERATOR_TO_ENUM_VARIANT_MARSHALER);
IEnumeratorMarshalerObj = getMarshaler.Call_RetOBJECTREF(NULL);
UnmanagedCallersOnlyCaller getMarshaler(METHOD__STUBHELPERS__GET_IENUMERATOR_TO_ENUM_VARIANT_MARSHALER);
getMarshaler.InvokeThrowing(&IEnumeratorMarshalerObj);

pInfo = new (pHeap) CustomMarshalerInfo(pLoaderAllocator, pLoaderAllocator->AllocateHandle(IEnumeratorMarshalerObj));

Expand Down
14 changes: 14 additions & 0 deletions src/coreclr/vm/metasig.h
Original file line number Diff line number Diff line change
Expand Up @@ -427,8 +427,22 @@ DEFINE_METASIG_T(SM(PtrResolver_Int_PtrArrByte_PtrVoid_PtrException_RetVoid, P(C
DEFINE_METASIG_T(SM(PtrResolver_Int_PtrIntPtr_PtrIntPtr_PtrIntPtr_PtrException_RetVoid, P(C(RESOLVER)) i P(I) P(I) P(I) P(C(EXCEPTION)), v))
DEFINE_METASIG_T(SM(PtrResolver_Int_Int_PtrArrByte_PtrException_RetVoid, P(C(RESOLVER)) i i P(a(b)) P(C(EXCEPTION)), v))
DEFINE_METASIG_T(SM(PtrResolver_Int_PtrStr_PtrException_RetVoid, P(C(RESOLVER)) i P(s) P(C(EXCEPTION)), v))
#ifdef FEATURE_COMINTEROP
DEFINE_METASIG_T(SM(PtrClass_PtrStr_Int_PtrObj_PtrArrObj_PtrArrBool_PtrArrInt_PtrArrType_PtrType_PtrObj_PtrException_RetVoid, P(C(CLASS)) P(s) i P(j) P(a(j)) P(a(F)) P(a(i)) P(a(C(TYPE))) P(C(TYPE)) P(j) P(C(EXCEPTION)), v))
DEFINE_METASIG_T(SM(PtrComObject_PtrClass_PtrObj_PtrException_RetVoid, P(C(COM_OBJECT)) P(C(CLASS)) P(j) P(C(EXCEPTION)), v))
DEFINE_METASIG_T(SM(PtrLicenseInteropProxy_IntPtr_PtrException_RetVoid, P(C(LICENSE_INTEROP_PROXY)) I P(C(EXCEPTION)), v))
DEFINE_METASIG_T(SM(PtrLicenseInteropProxy_PtrType_PtrBool_PtrIntPtr_PtrException_RetVoid, P(C(LICENSE_INTEROP_PROXY)) P(C(TYPE)) P(F) P(I) P(C(EXCEPTION)), v))
#endif // FEATURE_COMINTEROP
DEFINE_METASIG_T(SM(PtrObj_PtrObj_PtrException_RetVoid, P(j) P(j) P(C(EXCEPTION)), v))
DEFINE_METASIG_T(SM(PtrObj_PtrObj_PtrObj_PtrException_RetVoid, P(j) P(j) P(j) P(C(EXCEPTION)), v))
DEFINE_METASIG_T(SM(PtrObj_PtrStr_PtrException_RetVoid, P(j) P(s) P(C(EXCEPTION)), v))
DEFINE_METASIG_T(SM(PtrObj_PtrObj_Int_PtrObj_PtrObj_PtrObj_PtrObj_PtrObj_PtrObj_PtrObj_PtrException_RetVoid, P(j) P(j) i P(j) P(j) P(j) P(j) P(j) P(j) P(j) P(C(EXCEPTION)), v))
DEFINE_METASIG_T(SM(PtrObj_PtrObj_PtrBool_PtrIntPtr_PtrException_RetVoid, P(j) P(j) P(F) P(I) P(C(EXCEPTION)), v))
DEFINE_METASIG_T(SM(PtrObj_PtrObj_PtrInt_PtrIntPtr_PtrException_RetVoid, P(j) P(j) P(i) P(I) P(C(EXCEPTION)), v))
DEFINE_METASIG_T(SM(PtrObj_IntPtr_PtrException_RetVoid, P(j) I P(C(EXCEPTION)), v))
DEFINE_METASIG_T(SM(PtrObj_PtrComVariant_PtrException_RetVoid, P(j) P(g(COMVARIANT)) P(C(EXCEPTION)), v))
DEFINE_METASIG_T(SM(PtrObj_Int_PtrComVariant_PtrException_RetVoid, P(j) i P(g(COMVARIANT)) P(C(EXCEPTION)), v))
DEFINE_METASIG_T(SM(PtrComVariant_PtrObj_PtrException_RetVoid, P(g(COMVARIANT)) P(j) P(C(EXCEPTION)), v))
DEFINE_METASIG_T(SM(PtrException_PtrException_RetVoid, P(C(EXCEPTION)) P(C(EXCEPTION)), v))
DEFINE_METASIG_T(SM(PtrChar_PtrException_PtrObj_PtrException_RetVoid, P(u) P(C(EXCEPTION)) P(j) P(C(EXCEPTION)), v))
DEFINE_METASIG_T(SM(PtrChar_PtrStr_PtrException_RetVoid, P(u) P(s) P(C(EXCEPTION)), v))
Expand Down
Loading
Loading