Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix incorrect CCW decoding in GetObjectForCCW #61193

Merged
merged 2 commits into from
Nov 8, 2021
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
7 changes: 7 additions & 0 deletions src/coreclr/debug/daccess/dacdbiimpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4898,13 +4898,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/debug/daccess/dacimpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -1498,6 +1498,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/debug/daccess/request.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4156,41 +4156,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();
tommcdon marked this conversation as resolved.
Show resolved Hide resolved
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