1 // Licensed to the .NET Foundation under one or more agreements.
2 // The .NET Foundation licenses this file to you under the MIT license.
3 // See the LICENSE file in the project root for more information.
4 /*============================================================
10 ** Purpose: Implements AppDomain (loader domain) architecture
14 ===========================================================*/
18 #ifndef DACCESS_COMPILE
20 #include "appdomain.hpp"
22 inline void AppDomain::SetUnloadInProgress(AppDomain *pThis)
26 SystemDomain::System()->SetUnloadInProgress(pThis);
29 inline void AppDomain::SetUnloadComplete(AppDomain *pThis)
33 SystemDomain::System()->SetUnloadComplete();
36 inline void AppDomain::EnterContext(Thread* pThread, Context* pCtx,ContextTransitionFrame *pFrame)
42 PRECONDITION(CheckPointer(pThread));
43 PRECONDITION(CheckPointer(pCtx));
44 PRECONDITION(CheckPointer(pFrame));
45 PRECONDITION(pCtx->GetDomain()==this);
48 pThread->EnterContextRestricted(pCtx,pFrame);
52 inline AppDomainFromIDHolder::~AppDomainFromIDHolder()
61 inline void AppDomainFromIDHolder::Release()
63 //do not use real contract here!
68 if (m_type==SyncType_GC)
69 #ifdef ENABLE_CONTRACTS_IMPL
73 STRESS_LOG1(LF_APPDOMAIN, LL_INFO10000, "AppDomainFromIDHolder::Assign is allowing GC - %08x",this);
74 GetThread()->EndForbidGC();
80 _ASSERTE(!"Should not be called from a non GC thread");
88 if (m_type==SyncType_ADLock)
89 SystemDomain::m_SystemDomainCrst.SetCantLeave(FALSE);
92 _ASSERTE(!"Unknown type");
100 inline void AppDomainFromIDHolder::Assign(ADID id, BOOL bUnsafePoint)
102 //do not use real contract here!
104 TESTHOOKCALL(AppDomainCanBeUnloaded(id.m_dwId, bUnsafePoint));
107 if (m_type==SyncType_GC)
109 #ifdef ENABLE_CONTRACTS_IMPL
112 _ASSERTE(GetThread()->PreemptiveGCDisabled());
113 STRESS_LOG1(LF_APPDOMAIN, LL_INFO10000, "AppDomainFromIDHolder::Assign is forbidding GC - %08x",this);
114 GetThread()->BeginForbidGC(__FILE__, __LINE__);
120 _ASSERTE(!"Should not be called from a non GC thread");
126 if (m_type==SyncType_ADLock)
128 _ASSERTE(SystemDomain::m_SystemDomainCrst.OwnedByCurrentThread());
129 SystemDomain::m_SystemDomainCrst.SetCantLeave(TRUE);
138 m_pDomain=SystemDomain::GetAppDomainAtId(id);
144 inline void AppDomainFromIDHolder::ThrowIfUnloaded()
146 STATIC_CONTRACT_THROWS;
149 COMPlusThrow(kAppDomainUnloadedException);
156 inline AppDomain* AppDomainFromIDHolder::operator ->()
158 LIMITED_METHOD_CONTRACT;
159 _ASSERTE(m_bChecked && m_bAcquired);
163 inline DomainAssembly* AppDomain::FindDomainAssembly(Assembly* assembly)
169 PRECONDITION(CheckPointer(assembly));
172 return assembly->FindDomainAssembly(this);
175 inline BOOL AppDomain::IsRunningIn(Thread* pThread)
178 if (IsDefaultDomain())
180 return pThread->IsRunningIn(this, NULL)!=NULL;
185 inline void AppDomain::AddMemoryPressure()
187 STANDARD_VM_CONTRACT;
188 m_MemoryPressure=EstimateSize();
189 GCInterface::AddMemoryPressure(m_MemoryPressure);
192 inline void AppDomain::RemoveMemoryPressure()
196 GCInterface::RemoveMemoryPressure(m_MemoryPressure);
199 #endif // DACCESS_COMPILE
201 inline void AppDomain::SetAppDomainManagerInfo(LPCWSTR szAssemblyName, LPCWSTR szTypeName, EInitializeNewDomainFlags dwInitializeDomainFlags)
210 m_AppDomainManagerAssembly=szAssemblyName;
211 m_AppDomainManagerType=szTypeName;
212 m_dwAppDomainManagerInitializeDomainFlags = dwInitializeDomainFlags;
215 inline BOOL AppDomain::HasAppDomainManagerInfo()
218 return !m_AppDomainManagerAssembly.IsEmpty() && !m_AppDomainManagerType.IsEmpty();
221 inline LPCWSTR AppDomain::GetAppDomainManagerAsm()
224 return m_AppDomainManagerAssembly;
228 inline LPCWSTR AppDomain::GetAppDomainManagerType()
231 return m_AppDomainManagerType;
235 inline EInitializeNewDomainFlags AppDomain::GetAppDomainManagerInitializeNewDomainFlags()
237 LIMITED_METHOD_CONTRACT;
238 return m_dwAppDomainManagerInitializeDomainFlags;
241 inline AppDomain::PathIterator AppDomain::IterateNativeDllSearchDirectories()
245 i.m_i = m_NativeDllSearchDirectories.Iterate();
249 inline BOOL AppDomain::HasNativeDllSearchDirectories()
252 return m_NativeDllSearchDirectories.GetCount() !=0;
256 inline BOOL AppDomain::CanReversePInvokeEnter()
258 LIMITED_METHOD_CONTRACT;
259 return m_ReversePInvokeCanEnter;
262 inline void AppDomain::SetReversePInvokeCannotEnter()
264 LIMITED_METHOD_CONTRACT;
265 m_ReversePInvokeCanEnter=FALSE;
268 inline bool AppDomain::MustForceTrivialWaitOperations()
270 LIMITED_METHOD_CONTRACT;
271 return m_ForceTrivialWaitOperations;
274 inline void AppDomain::SetForceTrivialWaitOperations()
276 LIMITED_METHOD_CONTRACT;
277 m_ForceTrivialWaitOperations = true;
280 inline PTR_LoaderHeap AppDomain::GetHighFrequencyHeap()
283 return GetLoaderAllocator()->GetHighFrequencyHeap();
286 inline PTR_LoaderHeap AppDomain::GetLowFrequencyHeap()
289 return GetLoaderAllocator()->GetLowFrequencyHeap();
292 inline PTR_LoaderHeap AppDomain::GetStubHeap()
295 return GetLoaderAllocator()->GetStubHeap();
298 inline PTR_LoaderAllocator AppDomain::GetLoaderAllocator()
301 return PTR_LoaderAllocator(PTR_HOST_MEMBER_TADDR(AppDomain,this,m_LoaderAllocator));
305 inline DWORD DomainLocalModule::DynamicEntry::GetOffsetOfDataBlob()
307 LIMITED_METHOD_CONTRACT;
308 _ASSERTE(DWORD(offsetof(NormalDynamicEntry, m_pDataBlob)) == offsetof(NormalDynamicEntry, m_pDataBlob));
309 return (DWORD)offsetof(NormalDynamicEntry, m_pDataBlob);
313 #endif // _APPDOMAIN_I