Convert more COM interop MethodDescCallSite to UnmanagedCallersOnly (UCO)#125849
Convert more COM interop MethodDescCallSite to UnmanagedCallersOnly (UCO)#125849
Conversation
Converts COM interop code from MethodDescCallSite to UnmanagedCallersOnly (UCO) pattern for three sites: 1. DispatchEx_GetMemberProperties (Property case): replaces two MethodDescCallSite invocations (for CanRead/CanWrite) with a single UCO helper GetDispatchExPropertyFlags in StubHelpers. 2. ICustomQueryInterface.GetInterface: replaces the callback struct pattern with a UCO helper CallICustomQueryInterface. Also removes the cached MethodDesc field m_pICustomQueryInterfaceGetInterfaceMD from ComCallWrapperTemplate. 3. ConnectionPoint.InvokeProviderMethod: replaces MethodDescCallSite calls for delegate construction and provider invocation with a single UCO helper InvokeConnectionPointProviderMethod. Removes the UIntPtr ctor fallback path (addressing pending feedback). Also removes the m_ohDelegate field and related methods (GetOHDelegate/SetOHDelegate/GetObjCreateDelegate/SetObjCreateDelegate) from EEClass/MethodTable since the delegate-based COM object creation callback feature in CreateAggregatedInstance is removed. Adds [RequiresUnsafe] to GetIEnumeratorToEnumVariantMarshaler UCO overload to be consistent with the new UCO methods. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
Tagging subscribers to this area: @agocke |
There was a problem hiding this comment.
Pull request overview
This PR continues the CoreCLR COM interop migration away from MethodDescCallSite toward the UnmanagedCallersOnly (UCO) reverse-P/Invoke calling pattern, and removes now-dead COM interop callback/delegate infrastructure in the VM.
Changes:
- Added new UCO helpers in
StubHelpers.csand updated native call sites to useUnmanagedCallersOnlyCaller. - Converted COM interop call paths in
stdinterfaces.cpp,comconnectionpoints.cpp, andcomcallablewrapper.cppfromMethodDescCallSiteto UCO-based helpers. - Removed dead COM interop delegate/callback code paths and related cached fields/helpers in VM types.
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/coreclr/vm/stdinterfaces.cpp | Uses UCO helper to query PropertyInfo.CanRead/CanWrite flags instead of two MethodDescCallSite calls. |
| src/coreclr/vm/runtimecallablewrapper.cpp | Removes unused delegate-based aggregated COM instance creation path and related logic. |
| src/coreclr/vm/methodtable.h | Removes delegate-handle-related APIs from MethodTable. |
| src/coreclr/vm/methodtable.cpp | Removes implementations for COM object-creation delegate storage/retrieval. |
| src/coreclr/vm/metasig.h | Adds COM-interp UCO metasig definitions for new StubHelpers methods. |
| src/coreclr/vm/corelib.h | Registers new StubHelpers methods (including a NoSig entry). |
| src/coreclr/vm/comconnectionpoints.cpp | Uses a single UCO helper to construct delegate + invoke provider method. |
| src/coreclr/vm/comcallablewrapper.h | Removes cached ICustomQueryInterface.GetInterface MethodDesc field/API. |
| src/coreclr/vm/comcallablewrapper.cpp | Replaces callback/cached-MD pattern with UCO helper that calls ICustomQueryInterface.GetInterface. |
| src/coreclr/vm/class.h | Removes now-dead delegate handle storage from EEClass COM interop union. |
| src/coreclr/System.Private.CoreLib/src/System/StubHelpers.cs | Adds UCO helpers for DispatchEx property flags, ICustomQueryInterface, and connection point invocation. |
| enum : INT32 | ||
| { | ||
| ObjToArgSlot(MemberInfoObj) | ||
| DispatchExPropertyCanRead = 1, | ||
| DispatchExPropertyCanWrite = 2, | ||
| }; |
There was a problem hiding this comment.
The DispatchExPropertyCanRead/DispatchExPropertyCanWrite bit values are duplicated here and in StubHelpers.GetDispatchExPropertyFlags. Consider centralizing them (e.g., a shared header/enum or a single source of truth) or at least adding a note/assertion to keep the native and managed definitions in sync to prevent silent flag drift.
Continues the COM interop UCO migration (group 5), converting three
MethodDescCallSitecall sites to the UCO pattern and removing associated dead code. Addresses all pending feedback from #125508.Changes
New UCO helpers in
StubHelpers.csGetDispatchExPropertyFlags– replaces twoMethodDescCallSitecalls forPropertyInfo.CanRead/CanWriteinDispatchEx_GetMemberPropertiesCallICustomQueryInterface– replaces theInvokeICustomQueryInterfaceGetInterface_CallBackstruct/callback pattern; returnsintdirectly (usesInvokeThrowing_Ret)InvokeConnectionPointProviderMethod– replaces twoMethodDescCallSitecalls inConnectionPoint::InvokeProviderMethod; always usesnintfor the delegate ctor (dropsuseUIntPtrCtorbool per feedback)[RequiresUnsafe]to the existingGetIEnumeratorToEnumVariantMarshalerUCO overload for consistencyFeedback addressed from #125508
INVOKE_CONNECTION_POINT_PROVIDER_METHODregistered asNoSigincorelib.h(has unmanaged fn-ptr params — encoding in metasig not worth the pain)CallICustomQueryInterfaceusesInvokeThrowing_Ret<INT32>and passesppUnkOutdirectly — no local copy neededuseUIntPtrCtorbool removed — delegate ctors always have an(object, nint)overloadDead code removed
InvokeICustomQueryInterfaceGetInterface_CallBack+ arg struct incomcallablewrapper.cppGetICustomQueryInterfaceGetInterfaceMD/m_pICustomQueryInterfaceGetInterfaceMDfromComCallWrapperTemplatem_ohDelegateunion field andGetOHDelegate/SetOHDelegate/GetObjCreateDelegate/SetObjCreateDelegatefromEEClass/MethodTable—SetObjCreateDelegatehad no callers; the delegate-basedCreateAggregatedInstancepath was effectively dead