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.
7 //*****************************************************************************
10 // Class factories are used by the pluming in COM to activate new objects.
11 // This module contains the class factory code to instantiate the debugger
12 // objects described in <cordb.h>.
14 //*****************************************************************************
16 #ifndef __CorHost__h__
17 #define __CorHost__h__
20 #include "windows.h" // worth to include before mscoree.h so we are guaranteed to pick few definitions
21 #ifdef CreateSemaphore
22 #undef CreateSemaphore
27 #include "clrinternal.h"
31 #include "clrprivhosting.h"
33 #ifdef FEATURE_COMINTEROP
34 #include "activation.h" // WinRT activation.
37 class DangerousNonHostedSpinLock;
39 #define INVALID_STACK_BASE_MARKER_FOR_CHECK_STATE 2
45 class CorRuntimeHostBase
51 {LIMITED_METHOD_CONTRACT;}
53 STDMETHODIMP_(ULONG) AddRef(void);
55 // Starts the runtime. This is equivalent to CoInitializeCor()
58 STDMETHODIMP MapFile( // Return code.
59 HANDLE hFile, // [in] Handle for file
60 HMODULE *hMapAddress // [out] HINSTANCE for mapped file
63 STDMETHODIMP LocksHeldByLogicalThread( // Return code.
64 DWORD *pCount // [out] Number of locks that the current thread holds.
68 BOOL m_Started; // Has START been called?
70 LONG m_cRef; // Ref count.
72 static ULONG m_Version; // Version of ICorRuntimeHost.
73 // Some functions are only available in ICLRRuntimeHost.
74 // Some functions are no-op in ICLRRuntimeHost.
76 STDMETHODIMP UnloadAppDomain(DWORD dwDomainId, BOOL fWaitUntilDone);
78 STDMETHODIMP UnloadAppDomain2(DWORD dwDomainId, BOOL fWaitUntilDone, int *pLatchedExitCode);
80 static ULONG GetHostVersion()
82 LIMITED_METHOD_CONTRACT;
83 _ASSERTE (m_Version != 0);
90 class ConnectionNameTable;
91 typedef DPTR(class ConnectionNameTable) PTR_ConnectionNameTable;
95 // Defines the precedence (in increading oder) of the two symbol reading knobs
96 enum ESymbolReadingSetBy
98 eSymbolReadingSetByDefault,
99 eSymbolReadingSetByConfig, // EEConfig - config file, env var, etc.
100 eSymbolReadingSetByHost, // Hosting API - highest precedence
101 eSymbolReadingSetBy_COUNT
105 public CorRuntimeHostBase
107 , public IPrivateManagedExceptionReporting /* This interface is for internal Watson testing only*/
108 #endif // FEATURE_PAL
109 , public ICLRRuntimeHost4
111 friend struct _DacGlobals;
115 virtual ~CorHost2() {}
117 // *** IUnknown methods ***
118 STDMETHODIMP QueryInterface(REFIID riid, void** ppv);
119 STDMETHODIMP_(ULONG) AddRef(void)
122 return CorRuntimeHostBase::AddRef();
124 STDMETHODIMP_(ULONG) Release(void);
127 // *** ICorRuntimeHost methods ***
130 // defined in IPrivateManagedExceptionReporting interface for internal Watson testing only
131 STDMETHODIMP GetBucketParametersForCurrentException(BucketParameters *pParams);
132 #endif // FEATURE_PAL
134 // Starts the runtime. This is equivalent to CoInitializeCor().
135 STDMETHODIMP Start();
138 STDMETHODIMP ExecuteInAppDomain(DWORD dwAppDomainId,
139 FExecuteInAppDomainCallback pCallback,
142 STDMETHODIMP LocksHeldByLogicalThread( // Return code.
143 DWORD *pCount // [out] Number of locks that the current thread holds.
147 return CorRuntimeHostBase::LocksHeldByLogicalThread(pCount);
150 // Class factory hook-up.
151 static HRESULT CreateObject(REFIID riid, void **ppUnk);
153 STDMETHODIMP MapFile( // Return code.
154 HANDLE hFile, // [in] Handle for file
155 HMODULE *hMapAddress // [out] HINSTANCE for mapped file
159 return CorRuntimeHostBase::MapFile(hFile,hMapAddress);
162 STDMETHODIMP STDMETHODCALLTYPE SetHostControl(
163 IHostControl* pHostControl);
165 STDMETHODIMP STDMETHODCALLTYPE GetCLRControl(
166 ICLRControl** pCLRControl);
168 STDMETHODIMP UnloadAppDomain(DWORD dwDomainId, BOOL fWaitUntilDone);
170 STDMETHODIMP UnloadAppDomain2(DWORD dwDomainId, BOOL fWaitUntilDone, int *pLatchedExitCode);
172 STDMETHODIMP GetCurrentAppDomainId(DWORD *pdwAppDomainId);
174 STDMETHODIMP ExecuteApplication(LPCWSTR pwzAppFullName,
175 DWORD dwManifestPaths,
176 LPCWSTR *ppwzManifestPaths,
177 DWORD dwActivationData,
178 LPCWSTR *ppwzActivationData,
181 STDMETHODIMP ExecuteInDefaultAppDomain(LPCWSTR pwzAssemblyPath,
183 LPCWSTR pwzMethodName,
185 DWORD *pReturnValue);
187 // *** ICLRRuntimeHost2 methods ***
188 STDMETHODIMP CreateAppDomainWithManager(
189 LPCWSTR wszFriendlyName,
190 DWORD dwSecurityFlags,
191 LPCWSTR wszAppDomainManagerAssemblyName,
192 LPCWSTR wszAppDomainManagerTypeName,
194 LPCWSTR* pPropertyNames,
195 LPCWSTR* pPropertyValues,
196 DWORD* pAppDomainID);
198 STDMETHODIMP CreateDelegate(
200 LPCWSTR wszAssemblyName,
201 LPCWSTR wszClassName,
202 LPCWSTR wszMethodName,
205 STDMETHODIMP Authenticate(ULONGLONG authKey);
207 STDMETHODIMP RegisterMacEHPort();
208 STDMETHODIMP SetStartupFlags(STARTUP_FLAGS flag);
209 STDMETHODIMP DllGetActivationFactory(
212 IActivationFactory ** factory);
214 STDMETHODIMP ExecuteAssembly(
216 LPCWSTR pwzAssemblyPath,
219 DWORD* pReturnValue);
221 static HRESULT PreloadAssembly(
224 static HRESULT UnloadPreloadedAssemblies();
226 static STARTUP_FLAGS GetStartupFlags();
228 static BOOL HasStarted()
230 return m_RefCount != 0;
234 // This flag indicates if this instance was the first to load and start CoreCLR
235 BOOL m_fFirstToLoadCLR;
237 // This flag will be used to ensure that a CoreCLR host can invoke Start/Stop in pairs only.
239 BOOL m_fAppDomainCreated; // this flag is used when an appdomain can only create a single appdomain
241 // Helpers for both ICLRRuntimeHost2 and ICLRPrivRuntime
242 HRESULT _CreateAppDomain(
243 LPCWSTR wszFriendlyName,
245 LPCWSTR wszAppDomainManagerAssemblyName,
246 LPCWSTR wszAppDomainManagerTypeName,
248 LPCWSTR* pPropertyNames,
249 LPCWSTR* pPropertyValues,
250 DWORD* pAppDomainID);
252 HRESULT _CreateDelegate(
254 LPCWSTR wszAssemblyName,
255 LPCWSTR wszClassName,
256 LPCWSTR wszMethodName,
259 // entrypoint helper to be wrapped in a filter to process unhandled exceptions
260 VOID ExecuteMainInner(Assembly* pRootAssembly);
262 static LONG m_RefCount;
264 SVAL_DECL(STARTUP_FLAGS, m_dwStartupFlags);
267 #ifdef FEATURE_COMINTEROP
269 HRESULT STDMETHODCALLTYPE DllGetActivationFactoryImpl(
270 LPCWSTR wszAssemblyName,
273 IActivationFactory ** factory);
275 #endif // defined(FEATURE_COMINTEROP)
277 extern SIZE_T Host_SegmentSize;
278 extern SIZE_T Host_MaxGen0Size;
279 extern BOOL Host_fSegmentSizeSet;
280 extern BOOL Host_fMaxGen0SizeSet;
282 #define PARTIAL_TRUST_VISIBLE_ASSEMBLIES_PROPERTY W("PARTIAL_TRUST_VISIBLE_ASSEMBLIES")
283 #endif // __CorHost__h__