Skip to content

Commit

Permalink
Add support for the ISOSDacInterface14 api (#100364)
Browse files Browse the repository at this point in the history
* Add support for the ISOSDacInterface14 api
- This is a split out of the diagnostics changes associated with PR #99183
- This will allow the removal of the useability of the DomainLocalModule apis from ISOSDacInterface without changing the functionality of the interface by allowing consumers to move to the new apis - NOTE, the SOS_BREAKING_CHANGE number is expected to move from 4 to 5 at that point, so users of ISOSDacInterface which understand ISOSDacInterface14 should indicate that they understand version 5.
  • Loading branch information
davidwrighton authored Mar 28, 2024
1 parent 71177d9 commit 7c14f71
Show file tree
Hide file tree
Showing 10 changed files with 270 additions and 24 deletions.
4 changes: 4 additions & 0 deletions src/coreclr/debug/daccess/daccess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3231,6 +3231,10 @@ ClrDataAccess::QueryInterface(THIS_
{
ifaceRet = static_cast<ISOSDacInterface13*>(this);
}
else if (IsEqualIID(interfaceId, __uuidof(ISOSDacInterface14)))
{
ifaceRet = static_cast<ISOSDacInterface14*>(this);
}
else
{
*iface = NULL;
Expand Down
12 changes: 2 additions & 10 deletions src/coreclr/debug/daccess/dacdbiimpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1577,16 +1577,8 @@ void DacDbiInterfaceImpl::GetStaticsBases(TypeHandle thExact,
PTR_BYTE * ppNonGCStaticsBase)
{
MethodTable * pMT = thExact.GetMethodTable();
Module * pModuleForStatics = pMT->GetModuleForStatics();
if (pModuleForStatics != NULL)
{
PTR_DomainLocalModule pLocalModule = pModuleForStatics->GetDomainLocalModule();
if (pLocalModule != NULL)
{
*ppGCStaticsBase = pLocalModule->GetGCStaticsBasePointer(pMT);
*ppNonGCStaticsBase = pLocalModule->GetNonGCStaticsBasePointer(pMT);
}
}
*ppGCStaticsBase = pMT->GetGCStaticsBasePointer();
*ppNonGCStaticsBase = pMT->GetNonGCStaticsBasePointer();
} // DacDbiInterfaceImpl::GetStaticsBases

//-----------------------------------------------------------------------------
Expand Down
8 changes: 7 additions & 1 deletion src/coreclr/debug/daccess/dacimpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -816,7 +816,8 @@ class ClrDataAccess
public ISOSDacInterface10,
public ISOSDacInterface11,
public ISOSDacInterface12,
public ISOSDacInterface13
public ISOSDacInterface13,
public ISOSDacInterface14
{
public:
ClrDataAccess(ICorDebugDataTarget * pTarget, ICLRDataTarget * pLegacyTarget=0);
Expand Down Expand Up @@ -1216,6 +1217,11 @@ class ClrDataAccess
virtual HRESULT STDMETHODCALLTYPE GetGCFreeRegions(ISOSMemoryEnum **ppEnum);
virtual HRESULT STDMETHODCALLTYPE LockedFlush();

// ISOSDacInterface14
virtual HRESULT STDMETHODCALLTYPE GetStaticBaseAddress(CLRDATA_ADDRESS methodTable, CLRDATA_ADDRESS *nonGCStaticsAddress, CLRDATA_ADDRESS *GCStaticsAddress);
virtual HRESULT STDMETHODCALLTYPE GetThreadStaticBaseAddress(CLRDATA_ADDRESS methodTable, CLRDATA_ADDRESS thread, CLRDATA_ADDRESS *nonGCStaticsAddress, CLRDATA_ADDRESS *GCStaticsAddress);
virtual HRESULT STDMETHODCALLTYPE GetMethodTableInitializationFlags(CLRDATA_ADDRESS methodTable, MethodTableInitializationFlags *initializationStatus);

//
// ClrDataAccess.
//
Expand Down
116 changes: 116 additions & 0 deletions src/coreclr/debug/daccess/request.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5401,3 +5401,119 @@ HRESULT ClrDataAccess::LockedFlush()
SOSDacLeave();
return hr;
}

HRESULT STDMETHODCALLTYPE ClrDataAccess::GetStaticBaseAddress(CLRDATA_ADDRESS methodTable, CLRDATA_ADDRESS *nonGCStaticsAddress, CLRDATA_ADDRESS *GCStaticsAddress)
{
if (!nonGCStaticsAddress && !GCStaticsAddress)
return E_POINTER;

if (!methodTable)
return E_INVALIDARG;

SOSDacEnter();

PTR_MethodTable mTable = PTR_MethodTable(TO_TADDR(methodTable));

BOOL bIsFree = FALSE;
if (!DacValidateMethodTable(mTable, bIsFree))
{
hr = E_INVALIDARG;
}
else
{
if (GCStaticsAddress != NULL)
{
*GCStaticsAddress = PTR_CDADDR(mTable->GetGCStaticsBasePointer());
}
if (nonGCStaticsAddress != NULL)
{
*nonGCStaticsAddress = PTR_CDADDR(mTable->GetNonGCStaticsBasePointer());
}
}

SOSDacLeave();
return hr;
}


HRESULT STDMETHODCALLTYPE ClrDataAccess::GetThreadStaticBaseAddress(CLRDATA_ADDRESS methodTable, CLRDATA_ADDRESS threadPtr, CLRDATA_ADDRESS *nonGCStaticsAddress, CLRDATA_ADDRESS *GCStaticsAddress)
{
if (!nonGCStaticsAddress && !GCStaticsAddress)
return E_POINTER;

if (!methodTable)
return E_INVALIDARG;

if (!threadPtr)
return E_INVALIDARG;

SOSDacEnter();

PTR_MethodTable mTable = PTR_MethodTable(TO_TADDR(methodTable));
PTR_Thread thread = PTR_Thread(TO_TADDR(threadPtr));


BOOL bIsFree = FALSE;
if (!DacValidateMethodTable(mTable, bIsFree))
{
hr = E_INVALIDARG;
}
else
{
if (mTable->GetClass()->GetNumThreadStaticFields() == 0)
{
if (GCStaticsAddress != NULL)
{
*GCStaticsAddress = 0;
}
if (nonGCStaticsAddress != NULL)
{
*nonGCStaticsAddress = 0;
}
}
else
{
if (GCStaticsAddress != NULL)
{
*GCStaticsAddress = PTR_CDADDR(mTable->GetGCThreadStaticsBasePointer(thread));
}
if (nonGCStaticsAddress != NULL)
{
*nonGCStaticsAddress = PTR_CDADDR(mTable->GetNonGCThreadStaticsBasePointer(thread));
}
}
}

SOSDacLeave();
return hr;
}

HRESULT STDMETHODCALLTYPE ClrDataAccess::GetMethodTableInitializationFlags(CLRDATA_ADDRESS methodTable, MethodTableInitializationFlags *initializationStatus)
{
if (!methodTable)
return E_INVALIDARG;

if (!initializationStatus)
return E_POINTER;

SOSDacEnter();

*initializationStatus = (MethodTableInitializationFlags)0;
PTR_MethodTable mTable = PTR_MethodTable(TO_TADDR(methodTable));
BOOL bIsFree = FALSE;
if (!DacValidateMethodTable(mTable, bIsFree))
{
hr = E_INVALIDARG;
}
else
{
*initializationStatus = mTable->IsClassInited() ? MethodTableInitialized : (MethodTableInitializationFlags)0;
if (mTable->IsInitError())
{
*initializationStatus = (MethodTableInitializationFlags)(*initializationStatus | MethodTableInitializationFailed);
}
}

SOSDacLeave();
return hr;
}
14 changes: 14 additions & 0 deletions src/coreclr/inc/sospriv.idl
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,14 @@ typedef unsigned int size_t;
typedef int ModuleMapType;
typedef int VCSHeapType;
typedef int LoaderHeapKind;
typedef int MethodTableInitializationFlags;
cpp_quote("#endif")


cpp_quote("typedef enum { TYPEDEFTOMETHODTABLE, TYPEREFTOMETHODTABLE } ModuleMapType;")
cpp_quote("typedef enum {IndcellHeap, LookupHeap, ResolveHeap, DispatchHeap, CacheEntryHeap, VtableHeap} VCSHeapType;")
cpp_quote("typedef enum {LoaderHeapKindNormal = 0, LoaderHeapKindExplicitControl = 1} LoaderHeapKind;")
cpp_quote("typedef enum {MethodTableInitialized = 1, MethodTableInitializationFailed = 2} MethodTableInitializationFlags;")
cpp_quote("typedef enum {FreeUnknownRegion = 0, FreeGlobalHugeRegion = 1, FreeGlobalRegion = 2, FreeRegion = 3, FreeSohSegment = 4, FreeUohSegment = 5 } FreeRegionKind;")

typedef void (*MODULEMAPTRAVERSE)(UINT index, CLRDATA_ADDRESS methodTable,LPVOID token);
Expand Down Expand Up @@ -505,3 +507,15 @@ interface ISOSDacInterface13 : IUnknown
HRESULT GetGCFreeRegions(ISOSMemoryEnum **ppEnum);
HRESULT LockedFlush();
}

[
object,
local,
uuid(9aa22aca-6dc6-4a0c-b4e0-70d2416b9837)
]
interface ISOSDacInterface14 : IUnknown
{
HRESULT GetStaticBaseAddress(CLRDATA_ADDRESS methodTable, CLRDATA_ADDRESS *nonGCStaticsAddress, CLRDATA_ADDRESS *GCStaticsAddress);
HRESULT GetThreadStaticBaseAddress(CLRDATA_ADDRESS methodTable, CLRDATA_ADDRESS thread, CLRDATA_ADDRESS *nonGCStaticsAddress, CLRDATA_ADDRESS *GCStaticsAddress);
HRESULT GetMethodTableInitializationFlags(CLRDATA_ADDRESS methodTable, MethodTableInitializationFlags *initializationStatus);
}
9 changes: 5 additions & 4 deletions src/coreclr/pal/prebuilt/idl/sospriv_i.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@
/* link this file in with the server and any clients */


/* File created by MIDL compiler version 8.01.0622 */
/* at Mon Jan 18 19:14:07 2038
*/
/* File created by MIDL compiler version 8.01.0628 */
/* Compiler settings for sospriv.idl:
Oicf, W1, Zp8, env=Win64 (32b run), target_arch=AMD64 8.01.0622
Oicf, W1, Zp8, env=Win64 (32b run), target_arch=AMD64 8.01.0628
protocol : dce , ms_ext, c_ext, robust
error checks: allocation ref bounds_check enum stub_data
VC __declspec() decoration level:
Expand Down Expand Up @@ -120,6 +118,9 @@ MIDL_DEFINE_GUID(IID, IID_ISOSDacInterface12,0x1b93bacc,0x8ca4,0x432d,0x94,0x3a,

MIDL_DEFINE_GUID(IID, IID_ISOSDacInterface13,0x3176a8ed,0x597b,0x4f54,0xa7,0x1f,0x83,0x69,0x5c,0x6a,0x8c,0x5e);


MIDL_DEFINE_GUID(IID, IID_ISOSDacInterface14,0x9aa22aca,0x6dc6,0x4a0c,0xb4,0xe0,0x70,0xd2,0x41,0x6b,0x98,0x37);

#undef MIDL_DEFINE_GUID

#ifdef __cplusplus
Expand Down
114 changes: 114 additions & 0 deletions src/coreclr/pal/prebuilt/inc/sospriv.h
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ typedef int VCSHeapType;
typedef enum { TYPEDEFTOMETHODTABLE, TYPEREFTOMETHODTABLE } ModuleMapType;
typedef enum {IndcellHeap, LookupHeap, ResolveHeap, DispatchHeap, CacheEntryHeap, VtableHeap} VCSHeapType;
typedef enum {LoaderHeapKindNormal = 0, LoaderHeapKindExplicitControl = 1} LoaderHeapKind;
typedef enum {MethodTableInitialized = 1, MethodTableInitializationFailed = 2} MethodTableInitializationFlags;
typedef enum {FreeUnknownRegion = 0, FreeGlobalHugeRegion = 1, FreeGlobalRegion = 2, FreeRegion = 3, FreeSohSegment = 4, FreeUohSegment = 5 } FreeRegionKind;
typedef void ( *MODULEMAPTRAVERSE )(
UINT index,
Expand Down Expand Up @@ -3343,6 +3344,118 @@ EXTERN_C const IID IID_ISOSDacInterface13;
#endif /* __ISOSDacInterface13_INTERFACE_DEFINED__ */


#ifndef __ISOSDacInterface14_INTERFACE_DEFINED__
#define __ISOSDacInterface14_INTERFACE_DEFINED__

/* interface ISOSDacInterface14 */
/* [uuid][local][object] */


EXTERN_C const IID IID_ISOSDacInterface14;

#if defined(__cplusplus) && !defined(CINTERFACE)

MIDL_INTERFACE("9aa22aca-6dc6-4a0c-b4e0-70d2416b9837")
ISOSDacInterface14 : public IUnknown
{
public:
virtual HRESULT STDMETHODCALLTYPE GetStaticBaseAddress(
CLRDATA_ADDRESS methodTable,
CLRDATA_ADDRESS *nonGCStaticsAddress,
CLRDATA_ADDRESS *GCStaticsAddress) = 0;

virtual HRESULT STDMETHODCALLTYPE GetThreadStaticBaseAddress(
CLRDATA_ADDRESS methodTable,
CLRDATA_ADDRESS thread,
CLRDATA_ADDRESS *nonGCStaticsAddress,
CLRDATA_ADDRESS *GCStaticsAddress) = 0;

virtual HRESULT STDMETHODCALLTYPE GetMethodTableInitializationFlags(
CLRDATA_ADDRESS methodTable,
MethodTableInitializationFlags *initializationStatus) = 0;

};


#else /* C style interface */

typedef struct ISOSDacInterface14Vtbl
{
BEGIN_INTERFACE

HRESULT ( STDMETHODCALLTYPE *QueryInterface )(
ISOSDacInterface14 * This,
/* [in] */ REFIID riid,
/* [annotation][iid_is][out] */
_COM_Outptr_ void **ppvObject);

ULONG ( STDMETHODCALLTYPE *AddRef )(
ISOSDacInterface14 * This);

ULONG ( STDMETHODCALLTYPE *Release )(
ISOSDacInterface14 * This);

HRESULT ( STDMETHODCALLTYPE *GetStaticBaseAddress )(
ISOSDacInterface14 * This,
CLRDATA_ADDRESS methodTable,
CLRDATA_ADDRESS *nonGCStaticsAddress,
CLRDATA_ADDRESS *GCStaticsAddress);

HRESULT ( STDMETHODCALLTYPE *GetThreadStaticBaseAddress )(
ISOSDacInterface14 * This,
CLRDATA_ADDRESS methodTable,
CLRDATA_ADDRESS thread,
CLRDATA_ADDRESS *nonGCStaticsAddress,
CLRDATA_ADDRESS *GCStaticsAddress);

HRESULT ( STDMETHODCALLTYPE *GetMethodTableInitializationFlags )(
ISOSDacInterface14 * This,
CLRDATA_ADDRESS methodTable,
MethodTableInitializationFlags *initializationStatus);

END_INTERFACE
} ISOSDacInterface14Vtbl;

interface ISOSDacInterface14
{
CONST_VTBL struct ISOSDacInterface14Vtbl *lpVtbl;
};



#ifdef COBJMACROS


#define ISOSDacInterface14_QueryInterface(This,riid,ppvObject) \
( (This)->lpVtbl -> QueryInterface(This,riid,ppvObject) )

#define ISOSDacInterface14_AddRef(This) \
( (This)->lpVtbl -> AddRef(This) )

#define ISOSDacInterface14_Release(This) \
( (This)->lpVtbl -> Release(This) )


#define ISOSDacInterface14_GetStaticBaseAddress(This,methodTable,nonGCStaticsAddress,GCStaticsAddress) \
( (This)->lpVtbl -> GetStaticBaseAddress(This,methodTable,nonGCStaticsAddress,GCStaticsAddress) )

#define ISOSDacInterface14_GetThreadStaticBaseAddress(This,methodTable,thread,nonGCStaticsAddress,GCStaticsAddress) \
( (This)->lpVtbl -> GetThreadStaticBaseAddress(This,methodTable,thread,nonGCStaticsAddress,GCStaticsAddress) )

#define ISOSDacInterface14_GetMethodTableInitializationFlags(This,methodTable,initializationStatus) \
( (This)->lpVtbl -> GetMethodTableInitializationFlags(This,methodTable,initializationStatus) )

#endif /* COBJMACROS */


#endif /* C style interface */




#endif /* __ISOSDacInterface14_INTERFACE_DEFINED__ */


/* Additional Prototypes for ALL interfaces */

/* end of Additional Prototypes */
Expand All @@ -3353,3 +3466,4 @@ EXTERN_C const IID IID_ISOSDacInterface13;

#endif


6 changes: 3 additions & 3 deletions src/coreclr/vm/methodtable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,6 @@ BOOL MethodTable::ValidateWithPossibleAV()
(pEEClass && (pEEClass->GetMethodTableWithPossibleAV()->GetClassWithPossibleAV() == pEEClass))));
}

#ifndef DACCESS_COMPILE

//==========================================================================================
BOOL MethodTable::IsClassInited()
Expand All @@ -379,7 +378,7 @@ BOOL MethodTable::IsClassInited()
if (IsSharedByGenericInstantiations())
return FALSE;

DomainLocalModule *pLocalModule = GetDomainLocalModule();
PTR_DomainLocalModule pLocalModule = GetDomainLocalModule();

_ASSERTE(pLocalModule != NULL);

Expand All @@ -391,12 +390,13 @@ BOOL MethodTable::IsInitError()
{
WRAPPER_NO_CONTRACT;

DomainLocalModule *pLocalModule = GetDomainLocalModule();
PTR_DomainLocalModule pLocalModule = GetDomainLocalModule();
_ASSERTE(pLocalModule != NULL);

return pLocalModule->IsClassInitError(this);
}

#ifndef DACCESS_COMPILE
//==========================================================================================
// mark the class as having its .cctor run
void MethodTable::SetClassInited()
Expand Down
Loading

0 comments on commit 7c14f71

Please sign in to comment.