Skip to content

Commit

Permalink
Fix incorrect CCW decoding in GetObjectForCCW (#61193) (#61342)
Browse files Browse the repository at this point in the history
* Fix incorrect CCW decoding in GetObjectForCCW

* Fix linux/mac build
  • Loading branch information
tommcdon authored Nov 11, 2021
1 parent ddd0a9c commit 9d91089
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 10 deletions.
7 changes: 7 additions & 0 deletions src/coreclr/src/debug/daccess/dacdbiimpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4977,13 +4977,20 @@ VMPTR_OBJECTHANDLE DacDbiInterfaceImpl::GetObjectForCCW(CORDB_ADDRESS ccwPtr)

OBJECTHANDLE ohCCW = NULL;

#ifdef FEATURE_COMWRAPPERS
if (DACTryGetComWrappersHandleFromCCW(ccwPtr, &ohCCW) != S_OK)
{
#endif
#ifdef FEATURE_COMINTEROP
ComCallWrapper *pCCW = DACGetCCWFromAddress(ccwPtr);
if (pCCW)
{
ohCCW = pCCW->GetObjectHandle();
}
#endif
#ifdef FEATURE_COMWRAPPERS
}
#endif

VMPTR_OBJECTHANDLE vmObjHandle;
vmObjHandle.SetDacTargetPtr(ohCCW);
Expand Down
5 changes: 5 additions & 0 deletions src/coreclr/src/debug/daccess/dacimpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -1490,6 +1490,11 @@ class ClrDataAccess

static LONG s_procInit;

protected:
#ifdef FEATURE_COMWRAPPERS
HRESULT DACTryGetComWrappersHandleFromCCW(CLRDATA_ADDRESS ccwPtr, OBJECTHANDLE* objHandle);
#endif

public:
// APIs for picking up the info needed for a debugger to look up an ngen image or IL image
// from it's search path.
Expand Down
46 changes: 36 additions & 10 deletions src/coreclr/src/debug/daccess/request.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4138,41 +4138,67 @@ TADDR ClrDataAccess::DACGetManagedObjectWrapperFromCCW(CLRDATA_ADDRESS ccwPtr)
return managedObjectWrapperPtr;
}

HRESULT ClrDataAccess::DACTryGetComWrappersObjectFromCCW(CLRDATA_ADDRESS ccwPtr, OBJECTREF* objRef)
HRESULT ClrDataAccess::DACTryGetComWrappersHandleFromCCW(CLRDATA_ADDRESS ccwPtr, OBJECTHANDLE* objHandle)
{
if (ccwPtr == 0 || objRef == NULL)
return E_INVALIDARG;
HRESULT hr = E_FAIL;
TADDR ccw, managedObjectWrapperPtr;
ULONG32 bytesRead = 0;
OBJECTHANDLE handle;

SOSDacEnter();
if (ccwPtr == 0 || objHandle == NULL)
{
hr = E_INVALIDARG;
goto ErrExit;
}

if (!DACIsComWrappersCCW(ccwPtr))
{
hr = E_FAIL;
goto ErrExit;
}

TADDR ccw = CLRDATA_ADDRESS_TO_TADDR(ccwPtr);
ccw = CLRDATA_ADDRESS_TO_TADDR(ccwPtr);

// Return ManagedObjectWrapper as an OBJECTHANDLE. (The OBJECTHANDLE is guaranteed to live at offset 0).
TADDR managedObjectWrapperPtr = DACGetManagedObjectWrapperFromCCW(ccwPtr);
managedObjectWrapperPtr = DACGetManagedObjectWrapperFromCCW(ccwPtr);
if (managedObjectWrapperPtr == NULL)
{
hr = E_FAIL;
goto ErrExit;
}

ULONG32 bytesRead = 0;
OBJECTHANDLE handle;
IfFailGo(m_pTarget->ReadVirtual(managedObjectWrapperPtr, (PBYTE)&handle, sizeof(OBJECTHANDLE), &bytesRead));
if (bytesRead != sizeof(OBJECTHANDLE))
{
hr = E_FAIL;
goto ErrExit;
}

*objRef = ObjectFromHandle(handle);
*objHandle = handle;

SOSDacLeave();
return S_OK;

ErrExit: return hr;
}

HRESULT ClrDataAccess::DACTryGetComWrappersObjectFromCCW(CLRDATA_ADDRESS ccwPtr, OBJECTREF* objRef)
{
HRESULT hr = E_FAIL;

if (ccwPtr == 0 || objRef == NULL)
{
hr = E_INVALIDARG;
goto ErrExit;
}

OBJECTHANDLE handle;
if (DACTryGetComWrappersHandleFromCCW(ccwPtr, &handle) != S_OK)
{
hr = E_FAIL;
goto ErrExit;
}

*objRef = ObjectFromHandle(handle);

return S_OK;

Expand Down

0 comments on commit 9d91089

Please sign in to comment.