Skip to content

Commit d42e645

Browse files
elinor-fungsirntar
authored andcommitted
Make DAC and ProfToEEInterfaceImpl stop using BaseDomain (dotnet#107570)
`BaseDomain` should no longer be needed now that we only have one `AppDomain` and the `SystemDomain` can be treated as separate. This makes the DAC and ProfToEEInterfaceImpl use `AppDomain` directly and check against `SystemDomain::System()` to determine if a pointer is the system domain.
1 parent 65c5abf commit d42e645

File tree

5 files changed

+39
-68
lines changed

5 files changed

+39
-68
lines changed

src/coreclr/debug/daccess/dacimpl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1061,7 +1061,7 @@ class ClrDataAccess
10611061
virtual HRESULT STDMETHODCALLTYPE GetAppDomainData(CLRDATA_ADDRESS addr, struct DacpAppDomainData *data);
10621062
virtual HRESULT STDMETHODCALLTYPE GetAppDomainName(CLRDATA_ADDRESS addr, unsigned int count, _Inout_updates_z_(count) WCHAR *name, unsigned int *pNeeded);
10631063
virtual HRESULT STDMETHODCALLTYPE GetAssemblyList(CLRDATA_ADDRESS appDomain, int count, CLRDATA_ADDRESS values[], int *fetched);
1064-
virtual HRESULT STDMETHODCALLTYPE GetAssemblyData(CLRDATA_ADDRESS baseDomainPtr, CLRDATA_ADDRESS assembly, struct DacpAssemblyData *data);
1064+
virtual HRESULT STDMETHODCALLTYPE GetAssemblyData(CLRDATA_ADDRESS domainPtr, CLRDATA_ADDRESS assembly, struct DacpAssemblyData *data);
10651065
virtual HRESULT STDMETHODCALLTYPE GetAssemblyName(CLRDATA_ADDRESS assembly, unsigned int count, _Inout_updates_z_(count) WCHAR *name, unsigned int *pNeeded);
10661066
virtual HRESULT STDMETHODCALLTYPE GetThreadData(CLRDATA_ADDRESS thread, struct DacpThreadData *data);
10671067
virtual HRESULT STDMETHODCALLTYPE GetThreadFromThinlockID(UINT thinLockId, CLRDATA_ADDRESS *pThread);

src/coreclr/debug/daccess/request.cpp

Lines changed: 19 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2834,19 +2834,17 @@ ClrDataAccess::GetAppDomainData(CLRDATA_ADDRESS addr, struct DacpAppDomainData *
28342834
}
28352835
else
28362836
{
2837-
PTR_BaseDomain pBaseDomain = PTR_BaseDomain(TO_TADDR(addr));
2838-
28392837
ZeroMemory(appdomainData, sizeof(DacpAppDomainData));
2840-
appdomainData->AppDomainPtr = PTR_CDADDR(pBaseDomain);
2838+
appdomainData->AppDomainPtr = addr;
28412839
PTR_LoaderAllocator pLoaderAllocator = SystemDomain::GetGlobalLoaderAllocator();
28422840
appdomainData->pHighFrequencyHeap = HOST_CDADDR(pLoaderAllocator->GetHighFrequencyHeap());
28432841
appdomainData->pLowFrequencyHeap = HOST_CDADDR(pLoaderAllocator->GetLowFrequencyHeap());
28442842
appdomainData->pStubHeap = HOST_CDADDR(pLoaderAllocator->GetStubHeap());
28452843
appdomainData->appDomainStage = STAGE_OPEN;
28462844

2847-
if (pBaseDomain->IsAppDomain())
2845+
if (addr != HOST_CDADDR(SystemDomain::System()))
28482846
{
2849-
AppDomain * pAppDomain = pBaseDomain->AsAppDomain();
2847+
PTR_AppDomain pAppDomain = PTR_AppDomain(TO_TADDR(addr));
28502848
appdomainData->DomainLocalBlock = 0;
28512849
appdomainData->pDomainLocalModules = 0;
28522850

@@ -2963,15 +2961,19 @@ ClrDataAccess::GetAssemblyList(CLRDATA_ADDRESS addr, int count, CLRDATA_ADDRESS
29632961

29642962
SOSDacEnter();
29652963

2966-
BaseDomain* pBaseDomain = PTR_BaseDomain(TO_TADDR(addr));
2967-
2968-
int n=0;
2969-
if (pBaseDomain->IsAppDomain())
2964+
if (addr == HOST_CDADDR(SystemDomain::System()))
2965+
{
2966+
// We shouldn't be asking for the assemblies in SystemDomain
2967+
hr = E_INVALIDARG;
2968+
}
2969+
else
29702970
{
2971-
AppDomain::AssemblyIterator i = pBaseDomain->AsAppDomain()->IterateAssembliesEx(
2971+
PTR_AppDomain pAppDomain = PTR_AppDomain(TO_TADDR(addr));
2972+
AppDomain::AssemblyIterator i = pAppDomain->IterateAssembliesEx(
29722973
(AssemblyIterationFlags)(kIncludeLoading | kIncludeLoaded | kIncludeExecution));
29732974
CollectibleAssemblyHolder<DomainAssembly *> pDomainAssembly;
29742975

2976+
int n = 0;
29752977
if (values)
29762978
{
29772979
while (i.Next(pDomainAssembly.This()) && (n < count))
@@ -2994,13 +2996,6 @@ ClrDataAccess::GetAssemblyList(CLRDATA_ADDRESS addr, int count, CLRDATA_ADDRESS
29942996
if (pNeeded)
29952997
*pNeeded = n;
29962998
}
2997-
else
2998-
{
2999-
// The only other type of BaseDomain is the SystemDomain, and we shouldn't be asking
3000-
// for the assemblies in it.
3001-
_ASSERTE(false);
3002-
hr = E_INVALIDARG;
3003-
}
30042999

30053000
SOSDacLeave();
30063001
return hr;
@@ -3040,19 +3035,17 @@ ClrDataAccess::GetAppDomainName(CLRDATA_ADDRESS addr, unsigned int count, _Inout
30403035
{
30413036
SOSDacEnter();
30423037

3043-
PTR_BaseDomain pBaseDomain = PTR_BaseDomain(TO_TADDR(addr));
3044-
if (!pBaseDomain->IsAppDomain())
3038+
if (addr == HOST_CDADDR(SystemDomain::System()))
30453039
{
3046-
// Shared domain and SystemDomain don't have this field.
3040+
// SystemDomain doesn't have this field.
30473041
if (pNeeded)
30483042
*pNeeded = 1;
30493043
if (name)
30503044
name[0] = 0;
30513045
}
30523046
else
30533047
{
3054-
AppDomain* pAppDomain = pBaseDomain->AsAppDomain();
3055-
3048+
PTR_AppDomain pAppDomain = PTR_AppDomain(TO_TADDR(addr));
30563049
if (!pAppDomain->m_friendlyName.IsEmpty())
30573050
{
30583051
if (!pAppDomain->m_friendlyName.DacGetUnicode(count, name, pNeeded))
@@ -3103,9 +3096,9 @@ ClrDataAccess::GetAppDomainConfigFile(CLRDATA_ADDRESS appDomain, int count,
31033096
}
31043097

31053098
HRESULT
3106-
ClrDataAccess::GetAssemblyData(CLRDATA_ADDRESS cdBaseDomainPtr, CLRDATA_ADDRESS assembly, struct DacpAssemblyData *assemblyData)
3099+
ClrDataAccess::GetAssemblyData(CLRDATA_ADDRESS domain, CLRDATA_ADDRESS assembly, struct DacpAssemblyData *assemblyData)
31073100
{
3108-
if (assembly == (CLRDATA_ADDRESS)NULL && cdBaseDomainPtr == (CLRDATA_ADDRESS)NULL)
3101+
if (assembly == (CLRDATA_ADDRESS)NULL && domain == (CLRDATA_ADDRESS)NULL)
31093102
{
31103103
return E_INVALIDARG;
31113104
}
@@ -3117,14 +3110,9 @@ ClrDataAccess::GetAssemblyData(CLRDATA_ADDRESS cdBaseDomainPtr, CLRDATA_ADDRESS
31173110
// Make sure conditionally-assigned fields like AssemblySecDesc, LoadContext, etc. are zeroed
31183111
ZeroMemory(assemblyData, sizeof(DacpAssemblyData));
31193112

3120-
// If the specified BaseDomain is an AppDomain, get a pointer to it
3121-
AppDomain * pDomain = NULL;
3122-
if (cdBaseDomainPtr != (CLRDATA_ADDRESS)NULL)
3113+
if (domain != (CLRDATA_ADDRESS)NULL)
31233114
{
3124-
assemblyData->BaseDomainPtr = cdBaseDomainPtr;
3125-
PTR_BaseDomain baseDomain = PTR_BaseDomain(TO_TADDR(cdBaseDomainPtr));
3126-
if( baseDomain->IsAppDomain() )
3127-
pDomain = baseDomain->AsAppDomain();
3115+
assemblyData->DomainPtr = domain;
31283116
}
31293117

31303118
assemblyData->AssemblyPtr = HOST_CDADDR(pAssembly);

src/coreclr/inc/dacprivate.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -425,11 +425,11 @@ enum DacpAppDomainDataStage {
425425
STAGE_CLOSED
426426
};
427427

428-
// Information about a BaseDomain (AppDomain, SharedDomain or SystemDomain).
428+
// Information about an AppDomain or SystemDomain.
429429
// For types other than AppDomain, some fields (like dwID, DomainLocalBlock, etc.) will be 0/null.
430430
struct MSLAYOUT DacpAppDomainData
431431
{
432-
// The pointer to the BaseDomain (not necessarily an AppDomain).
432+
// The pointer to the AppDomain or SystemDomain.
433433
// It's useful to keep this around in the structure
434434
CLRDATA_ADDRESS AppDomainPtr = 0;
435435
CLRDATA_ADDRESS AppSecDesc = 0;
@@ -455,17 +455,17 @@ struct MSLAYOUT DacpAssemblyData
455455
CLRDATA_ADDRESS AssemblyPtr = 0; //useful to have
456456
CLRDATA_ADDRESS ClassLoader = 0;
457457
CLRDATA_ADDRESS ParentDomain = 0;
458-
CLRDATA_ADDRESS BaseDomainPtr = 0;
458+
CLRDATA_ADDRESS DomainPtr = 0;
459459
CLRDATA_ADDRESS AssemblySecDesc = 0;
460460
BOOL isDynamic = FALSE;
461461
UINT ModuleCount = FALSE;
462462
UINT LoadContext = FALSE;
463463
BOOL isDomainNeutral = FALSE; // Always false, preserved for backward compatibility
464464
DWORD dwLocationFlags = 0;
465465

466-
HRESULT Request(ISOSDacInterface *sos, CLRDATA_ADDRESS addr, CLRDATA_ADDRESS baseDomainPtr)
466+
HRESULT Request(ISOSDacInterface *sos, CLRDATA_ADDRESS addr, CLRDATA_ADDRESS domainPtr)
467467
{
468-
return sos->GetAssemblyData(baseDomainPtr, addr, this);
468+
return sos->GetAssemblyData(domainPtr, addr, this);
469469
}
470470

471471
HRESULT Request(ISOSDacInterface *sos, CLRDATA_ADDRESS addr)

src/coreclr/vm/appdomain.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1546,15 +1546,15 @@ void SystemDomain::NotifyProfilerStartup()
15461546

15471547
{
15481548
BEGIN_PROFILER_CALLBACK(CORProfilerTrackAppDomainLoads());
1549-
_ASSERTE(System()->DefaultDomain());
1550-
(&g_profControlBlock)->AppDomainCreationStarted((AppDomainID) System()->DefaultDomain());
1549+
_ASSERTE(AppDomain::GetCurrentDomain());
1550+
(&g_profControlBlock)->AppDomainCreationStarted((AppDomainID) AppDomain::GetCurrentDomain());
15511551
END_PROFILER_CALLBACK();
15521552
}
15531553

15541554
{
15551555
BEGIN_PROFILER_CALLBACK(CORProfilerTrackAppDomainLoads());
1556-
_ASSERTE(System()->DefaultDomain());
1557-
(&g_profControlBlock)->AppDomainCreationFinished((AppDomainID) System()->DefaultDomain(), S_OK);
1556+
_ASSERTE(AppDomain::GetCurrentDomain());
1557+
(&g_profControlBlock)->AppDomainCreationFinished((AppDomainID) AppDomain::GetCurrentDomain(), S_OK);
15581558
END_PROFILER_CALLBACK();
15591559
}
15601560
}
@@ -1585,15 +1585,15 @@ HRESULT SystemDomain::NotifyProfilerShutdown()
15851585

15861586
{
15871587
BEGIN_PROFILER_CALLBACK(CORProfilerTrackAppDomainLoads());
1588-
_ASSERTE(System()->DefaultDomain());
1589-
(&g_profControlBlock)->AppDomainShutdownStarted((AppDomainID) System()->DefaultDomain());
1588+
_ASSERTE(AppDomain::GetCurrentDomain());
1589+
(&g_profControlBlock)->AppDomainShutdownStarted((AppDomainID) AppDomain::GetCurrentDomain());
15901590
END_PROFILER_CALLBACK();
15911591
}
15921592

15931593
{
15941594
BEGIN_PROFILER_CALLBACK(CORProfilerTrackAppDomainLoads());
1595-
_ASSERTE(System()->DefaultDomain());
1596-
(&g_profControlBlock)->AppDomainShutdownFinished((AppDomainID) System()->DefaultDomain(), S_OK);
1595+
_ASSERTE(AppDomain::GetCurrentDomain());
1596+
(&g_profControlBlock)->AppDomainShutdownFinished((AppDomainID) AppDomain::GetCurrentDomain(), S_OK);
15971597
END_PROFILER_CALLBACK();
15981598
}
15991599
return (S_OK);

src/coreclr/vm/proftoeeinterfaceimpl.cpp

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3148,9 +3148,9 @@ HRESULT ProfToEEInterfaceImpl::GetAppDomainStaticAddress(ClassID classId,
31483148
return E_INVALIDARG;
31493149
}
31503150

3151-
// Some domains, like the system domain, aren't APP domains, and thus don't contain any
3151+
// The system domain isn't an APP domain and thus doesn't contain any
31523152
// statics. See if the profiler is trying to be naughty.
3153-
if (!((BaseDomain*) appDomainId)->IsAppDomain())
3153+
if (appDomainId == (AppDomainID)SystemDomain::System())
31543154
{
31553155
return E_INVALIDARG;
31563156
}
@@ -3382,9 +3382,9 @@ HRESULT ProfToEEInterfaceImpl::GetThreadStaticAddress2(ClassID classId,
33823382
return E_INVALIDARG;
33833383
}
33843384

3385-
// Some domains, like the system domain, aren't APP domains, and thus don't contain any
3385+
// The system domain isn't an APP domain and thus doesn't contain any
33863386
// statics. See if the profiler is trying to be naughty.
3387-
if (!((BaseDomain*) appDomainId)->IsAppDomain())
3387+
if (appDomainId == (AppDomainID)SystemDomain::System())
33883388
{
33893389
return E_INVALIDARG;
33903390
}
@@ -5479,25 +5479,8 @@ HRESULT ProfToEEInterfaceImpl::GetAppDomainInfo(AppDomainID appDomainId,
54795479
return E_INVALIDARG;
54805480
}
54815481

5482-
BaseDomain *pDomain; // Internal data structure.
54835482
HRESULT hr = S_OK;
54845483

5485-
// <TODO>@todo:
5486-
// Right now, this ID is not a true AppDomain, since we use the old
5487-
// AppDomain/SystemDomain model in the profiling API. This means that
5488-
// the profiler exposes the SharedDomain and the SystemDomain to the
5489-
// outside world. It's not clear whether this is actually the right thing
5490-
// to do or not. - seantrow
5491-
//
5492-
// Postponed to V2.
5493-
// </TODO>
5494-
5495-
pDomain = (BaseDomain *) appDomainId;
5496-
5497-
// Make sure they've passed in a valid appDomainId
5498-
if (pDomain == NULL)
5499-
return (E_INVALIDARG);
5500-
55015484
// Pick sensible defaults.
55025485
if (pcchName)
55035486
*pcchName = 0;
@@ -5507,10 +5490,10 @@ HRESULT ProfToEEInterfaceImpl::GetAppDomainInfo(AppDomainID appDomainId,
55075490
*pProcessId = 0;
55085491

55095492
LPCWSTR szFriendlyName;
5510-
if (pDomain == SystemDomain::System())
5493+
if (appDomainId == (AppDomainID)SystemDomain::System())
55115494
szFriendlyName = g_pwBaseLibrary;
55125495
else
5513-
szFriendlyName = ((AppDomain*)pDomain)->GetFriendlyNameForDebugger();
5496+
szFriendlyName = ((AppDomain*)appDomainId)->GetFriendlyNameForDebugger();
55145497

55155498
if (szFriendlyName != NULL)
55165499
{

0 commit comments

Comments
 (0)