23
23
#ifdef FEATURE_COMWRAPPERS
24
24
#include < interoplibinterface.h>
25
25
#include < interoplibabi.h>
26
-
27
- // Public contract for ExternalObjectContext, keep in sync with definition in
28
- // interoplibinterface.cpp
29
- struct ExternalObjectContextDACnterface
30
- {
31
- INT_PTR sentinel;
32
- PTR_VOID identity;
33
- INT_PTR _padding1;
34
- DWORD _padding2;
35
- INT64 _padding3;
36
- };
37
-
38
- typedef DPTR (ExternalObjectContextDACnterface) PTR_ExternalObjectContext;
39
-
40
- // Public contract for ManagedObjectWrapper, keep in sync with definition in
41
- // comwrappers.hpp
42
- struct ManagedObjectWrapperDACInterface
43
- {
44
- PTR_VOID managedObject;
45
- INT32 _padding1;
46
- INT32 _padding2;
47
- INT_PTR _padding3;
48
- INT_PTR _padding4;
49
- INT_PTR _padding6;
50
- LONGLONG _refCount;
51
- INT32 _padding7;
52
- };
53
-
54
- typedef DPTR (ManagedObjectWrapperDACInterface) PTR_ManagedObjectWrapper;
55
-
56
26
#endif // FEATURE_COMWRAPPERS
57
27
58
28
#ifndef TARGET_UNIX
@@ -4105,22 +4075,23 @@ PTR_IUnknown ClrDataAccess::DACGetCOMIPFromCCW(PTR_ComCallWrapper pCCW, int vtab
4105
4075
#endif
4106
4076
4107
4077
#ifdef FEATURE_COMWRAPPERS
4108
- BOOL ClrDataAccess::DACIsComWrappersCCW (CLRDATA_ADDRESS ccwPtr)
4078
+ BOOL ClrDataAccess::DACGetComWrappersCCWVTableQIAddress (CLRDATA_ADDRESS ccwPtr, TADDR *vTableAddress, TADDR *qiAddress )
4109
4079
{
4110
- // Read CCWs QI address and compare it to the managed object wrapper's implementation.
4080
+ _ASSERTE (vTableAddress != NULL && qiAddress != NULL );
4081
+
4111
4082
HRESULT hr = S_OK;
4112
4083
ULONG32 bytesRead = 0 ;
4113
4084
TADDR ccw = CLRDATA_ADDRESS_TO_TADDR (ccwPtr);
4114
- TADDR vTableAddress = NULL ;
4115
- if (FAILED (m_pTarget->ReadVirtual (ccw, (PBYTE)& vTableAddress, sizeof (TADDR), &bytesRead))
4085
+ * vTableAddress = NULL ;
4086
+ if (FAILED (m_pTarget->ReadVirtual (ccw, (PBYTE)vTableAddress, sizeof (TADDR), &bytesRead))
4116
4087
|| bytesRead != sizeof (TADDR)
4117
4088
|| vTableAddress == NULL )
4118
4089
{
4119
4090
return FALSE ;
4120
4091
}
4121
4092
4122
- TADDR qiAddress = NULL ;
4123
- if (FAILED (m_pTarget->ReadVirtual (vTableAddress, (PBYTE)& qiAddress, sizeof (TADDR), &bytesRead))
4093
+ * qiAddress = NULL ;
4094
+ if (FAILED (m_pTarget->ReadVirtual (* vTableAddress, (PBYTE)qiAddress, sizeof (TADDR), &bytesRead))
4124
4095
|| bytesRead != sizeof (TADDR)
4125
4096
|| qiAddress == NULL )
4126
4097
{
@@ -4130,15 +4101,22 @@ BOOL ClrDataAccess::DACIsComWrappersCCW(CLRDATA_ADDRESS ccwPtr)
4130
4101
4131
4102
#ifdef TARGET_ARM
4132
4103
// clear the THUMB bit on qiAddress before comparing with known vtable entry
4133
- qiAddress &= ~THUMB_CODE;
4104
+ * qiAddress &= ~THUMB_CODE;
4134
4105
#endif
4135
4106
4136
- if (qiAddress != GetEEFuncEntryPoint (ManagedObjectWrapper_QueryInterface))
4107
+ return TRUE ;
4108
+ }
4109
+
4110
+ BOOL ClrDataAccess::DACIsComWrappersCCW (CLRDATA_ADDRESS ccwPtr)
4111
+ {
4112
+ TADDR vTableAddress = NULL ;
4113
+ TADDR qiAddress = NULL ;
4114
+ if (!DACGetComWrappersCCWVTableQIAddress (ccwPtr, &vTableAddress, &qiAddress))
4137
4115
{
4138
4116
return FALSE ;
4139
4117
}
4140
4118
4141
- return TRUE ;
4119
+ return qiAddress == GetEEFuncEntryPoint (ManagedObjectWrapper_QueryInterface) ;
4142
4120
}
4143
4121
4144
4122
TADDR ClrDataAccess::DACGetManagedObjectWrapperFromCCW (CLRDATA_ADDRESS ccwPtr)
@@ -4174,8 +4152,6 @@ HRESULT ClrDataAccess::DACTryGetComWrappersObjectFromCCW(CLRDATA_ADDRESS ccwPtr,
4174
4152
}
4175
4153
4176
4154
TADDR ccw = CLRDATA_ADDRESS_TO_TADDR (ccwPtr);
4177
- // Mask the "dispatch pointer" to get a double pointer to the ManagedObjectWrapper
4178
- TADDR managedObjectWrapperPtrPtr = ccw & InteropLib::ABI::DispatchThisPtrMask;
4179
4155
4180
4156
// Return ManagedObjectWrapper as an OBJECTHANDLE. (The OBJECTHANDLE is guaranteed to live at offset 0).
4181
4157
TADDR managedObjectWrapperPtr = DACGetManagedObjectWrapperFromCCW (ccwPtr);
@@ -4819,14 +4795,6 @@ HRESULT ClrDataAccess::GetObjectComWrappersData(CLRDATA_ADDRESS objAddr, CLRDATA
4819
4795
}
4820
4796
4821
4797
SOSDacEnter ();
4822
- auto ComWrapperCallback = [](void *mocw, void *additionalData)
4823
- {
4824
- CQuickArrayList<CLRDATA_ADDRESS> *comWrappers = (CQuickArrayList<CLRDATA_ADDRESS>*)additionalData;
4825
-
4826
- comWrappers->Push (TO_CDADDR (mocw));
4827
-
4828
- };
4829
-
4830
4798
if (pNeeded != NULL )
4831
4799
{
4832
4800
*pNeeded = 0 ;
@@ -4845,11 +4813,24 @@ HRESULT ClrDataAccess::GetObjectComWrappersData(CLRDATA_ADDRESS objAddr, CLRDATA
4845
4813
{
4846
4814
if (rcw != NULL )
4847
4815
{
4848
- *rcw = PTR_CDADDR (pInfo->m_externalComObjectContext );
4816
+ *rcw = TO_TADDR (pInfo->m_externalComObjectContext );
4849
4817
}
4850
4818
4819
+ DPTR (NewHolder<ManagedObjectComWrapperByIdMap>) mapHolder (PTR_TO_MEMBER_TADDR (InteropSyncBlockInfo, pInfo, m_managedObjectComWrapperMap));
4820
+ DPTR (ManagedObjectComWrapperByIdMap *)ppMap (PTR_TO_MEMBER_TADDR (NewHolder<ManagedObjectComWrapperByIdMap>, mapHolder, m_value));
4821
+ DPTR (ManagedObjectComWrapperByIdMap) pMap (TO_TADDR (*ppMap));
4822
+
4851
4823
CQuickArrayList<CLRDATA_ADDRESS> comWrappers;
4852
- pInfo->IterateComWrappers (ComWrapperCallback, (void *)&comWrappers);
4824
+ if (pMap != NULL )
4825
+ {
4826
+ ManagedObjectComWrapperByIdMap::Iterator iter = pMap->Begin ();
4827
+ while (iter != pMap->End ())
4828
+ {
4829
+ comWrappers.Push (TO_CDADDR (iter->Value ()));
4830
+ ++iter;
4831
+
4832
+ }
4833
+ }
4853
4834
4854
4835
if (pNeeded != NULL )
4855
4836
{
@@ -4963,16 +4944,48 @@ HRESULT ClrDataAccess::IsComWrappersRCW(CLRDATA_ADDRESS rcw, BOOL *isComWrappers
4963
4944
}
4964
4945
4965
4946
SOSDacEnter ();
4966
-
4967
- PTR_ExternalObjectContext pEOC (TO_TADDR (rcw));
4947
+
4968
4948
if (isComWrappersRCW != NULL )
4969
4949
{
4970
- *isComWrappersRCW = pEOC->sentinel == ExternalObjectContextSentinelValue;
4950
+ PTR_ExternalObjectContext pRCW (TO_TADDR (rcw));
4951
+ BOOL stillValid = TRUE ;
4952
+ if (pRCW->SyncBlockIndex >= SyncBlockCache::s_pSyncBlockCache->m_SyncTableSize )
4953
+ {
4954
+ stillValid = FALSE ;
4955
+ }
4956
+
4957
+ PTR_SyncBlock pSyncBlk = NULL ;
4958
+ if (stillValid)
4959
+ {
4960
+ PTR_SyncTableEntry ste = PTR_SyncTableEntry (dac_cast<TADDR>(g_pSyncTable) + (sizeof (SyncTableEntry) * pRCW->SyncBlockIndex ));
4961
+ pSyncBlk = ste->m_SyncBlock ;
4962
+ if (pSyncBlk == NULL )
4963
+ {
4964
+ stillValid = FALSE ;
4965
+ }
4966
+ }
4967
+
4968
+ PTR_InteropSyncBlockInfo pInfo = NULL ;
4969
+ if (stillValid)
4970
+ {
4971
+ pInfo = pSyncBlk->GetInteropInfoNoCreate ();
4972
+ if (pInfo == NULL )
4973
+ {
4974
+ stillValid = FALSE ;
4975
+ }
4976
+ }
4977
+
4978
+ if (stillValid)
4979
+ {
4980
+ stillValid = TO_TADDR (pInfo->m_externalComObjectContext ) == PTR_HOST_TO_TADDR (pRCW);
4981
+ }
4982
+
4983
+ *isComWrappersRCW = stillValid;
4971
4984
hr = *isComWrappersRCW ? S_OK : S_FALSE;
4972
4985
}
4973
4986
4974
4987
SOSDacLeave ();
4975
- return hr;
4988
+ return hr;
4976
4989
#else // FEATURE_COMWRAPPERS
4977
4990
return E_NOTIMPL;
4978
4991
#endif // FEATURE_COMWRAPPERS
@@ -4989,12 +5002,6 @@ HRESULT ClrDataAccess::GetComWrappersRCWData(CLRDATA_ADDRESS rcw, CLRDATA_ADDRES
4989
5002
SOSDacEnter ();
4990
5003
4991
5004
PTR_ExternalObjectContext pEOC (TO_TADDR (rcw));
4992
- if (pEOC->sentinel != ExternalObjectContextSentinelValue)
4993
- {
4994
- // Not a ComWrappers RCW
4995
- hr = E_INVALIDARG;
4996
- }
4997
-
4998
5005
if (identity != NULL )
4999
5006
{
5000
5007
*identity = PTR_CDADDR (pEOC->identity );
0 commit comments