[Tizen] Add coreclr_preload_assembly to CoreCLR host API
[platform/upstream/coreclr.git] / src / inc / corhost.h
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 //
5
6 //
7 //*****************************************************************************
8 // CorHost.h
9 //
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>.
13 //
14 //*****************************************************************************
15
16 #ifndef __CorHost__h__
17 #define __CorHost__h__
18
19
20 #include "windows.h" // worth to include before mscoree.h so we are guaranteed to pick few definitions
21 #ifdef CreateSemaphore
22 #undef CreateSemaphore
23 #endif
24
25 #include "mscoree.h"
26
27 #include "clrinternal.h"
28
29 #include "holder.h"
30
31 #include "clrprivhosting.h"
32
33 #ifdef FEATURE_COMINTEROP
34 #include "activation.h" // WinRT activation.
35 #endif
36
37 class DangerousNonHostedSpinLock;
38
39 #define INVALID_STACK_BASE_MARKER_FOR_CHECK_STATE 2
40
41 class AppDomain;
42 class Assembly;
43
44
45 class CorRuntimeHostBase
46 {
47 protected:
48     CorRuntimeHostBase()
49     :m_Started(FALSE),
50      m_cRef(0)
51     {LIMITED_METHOD_CONTRACT;}
52
53     STDMETHODIMP_(ULONG) AddRef(void);
54
55     // Starts the runtime. This is equivalent to CoInitializeCor()
56     STDMETHODIMP Start();
57
58     STDMETHODIMP MapFile(                       // Return code.
59         HANDLE     hFile,                       // [in]  Handle for file
60         HMODULE   *hMapAddress                  // [out] HINSTANCE for mapped file
61         );
62
63     STDMETHODIMP LocksHeldByLogicalThread(      // Return code.
64         DWORD *pCount                           // [out] Number of locks that the current thread holds.
65         );
66
67 protected:
68     BOOL        m_Started;              // Has START been called?
69
70     LONG        m_cRef;                 // Ref count.
71
72     static ULONG       m_Version;              // Version of ICorRuntimeHost.
73                                         // Some functions are only available in ICLRRuntimeHost.
74                                         // Some functions are no-op in ICLRRuntimeHost.
75
76     STDMETHODIMP UnloadAppDomain(DWORD dwDomainId, BOOL fWaitUntilDone);
77
78     STDMETHODIMP UnloadAppDomain2(DWORD dwDomainId, BOOL fWaitUntilDone, int *pLatchedExitCode);
79 public:
80     static ULONG GetHostVersion()
81     {
82         LIMITED_METHOD_CONTRACT;
83         _ASSERTE (m_Version != 0);
84         return m_Version;
85     }
86
87 };
88
89
90 class ConnectionNameTable;
91 typedef DPTR(class ConnectionNameTable) PTR_ConnectionNameTable;
92
93 class CrstStatic;
94
95 // Defines the precedence (in increading oder) of the two symbol reading knobs
96 enum ESymbolReadingSetBy
97 {
98     eSymbolReadingSetByDefault,
99     eSymbolReadingSetByConfig,  // EEConfig - config file, env var, etc.
100     eSymbolReadingSetByHost,    // Hosting API - highest precedence
101     eSymbolReadingSetBy_COUNT
102 };
103
104 class CorHost2 :
105     public CorRuntimeHostBase
106 #ifndef FEATURE_PAL    
107     , public IPrivateManagedExceptionReporting /* This interface is for internal Watson testing only*/
108 #endif // FEATURE_PAL    
109     , public ICLRRuntimeHost4
110 {
111     friend struct _DacGlobals;
112
113 public:
114     CorHost2();
115     virtual ~CorHost2() {}
116
117     // *** IUnknown methods ***
118     STDMETHODIMP    QueryInterface(REFIID riid, void** ppv);
119     STDMETHODIMP_(ULONG) AddRef(void)
120     {
121         WRAPPER_NO_CONTRACT;
122         return CorRuntimeHostBase::AddRef();
123     }
124     STDMETHODIMP_(ULONG) Release(void);
125
126
127     // *** ICorRuntimeHost methods ***
128
129 #ifndef FEATURE_PAL    
130     // defined in IPrivateManagedExceptionReporting interface for internal Watson testing only
131     STDMETHODIMP GetBucketParametersForCurrentException(BucketParameters *pParams);
132 #endif // FEATURE_PAL    
133
134     // Starts the runtime. This is equivalent to CoInitializeCor().
135     STDMETHODIMP Start();
136     STDMETHODIMP Stop();
137
138     STDMETHODIMP ExecuteInAppDomain(DWORD dwAppDomainId,
139                                     FExecuteInAppDomainCallback pCallback,
140                                     void * cookie);
141
142     STDMETHODIMP LocksHeldByLogicalThread(      // Return code.
143         DWORD *pCount                           // [out] Number of locks that the current thread holds.
144         )
145     {
146         WRAPPER_NO_CONTRACT;
147         return CorRuntimeHostBase::LocksHeldByLogicalThread(pCount);
148     }
149
150     // Class factory hook-up.
151     static HRESULT CreateObject(REFIID riid, void **ppUnk);
152
153     STDMETHODIMP MapFile(                       // Return code.
154         HANDLE     hFile,                       // [in]  Handle for file
155         HMODULE   *hMapAddress                  // [out] HINSTANCE for mapped file
156         )
157     {
158         WRAPPER_NO_CONTRACT;
159         return CorRuntimeHostBase::MapFile(hFile,hMapAddress);
160     }
161
162     STDMETHODIMP STDMETHODCALLTYPE SetHostControl(
163         IHostControl* pHostControl);
164
165     STDMETHODIMP STDMETHODCALLTYPE GetCLRControl(
166         ICLRControl** pCLRControl);
167
168     STDMETHODIMP UnloadAppDomain(DWORD dwDomainId, BOOL fWaitUntilDone);
169
170     STDMETHODIMP UnloadAppDomain2(DWORD dwDomainId, BOOL fWaitUntilDone, int *pLatchedExitCode);
171
172     STDMETHODIMP GetCurrentAppDomainId(DWORD *pdwAppDomainId);
173
174     STDMETHODIMP ExecuteApplication(LPCWSTR  pwzAppFullName,
175                                     DWORD    dwManifestPaths,
176                                     LPCWSTR  *ppwzManifestPaths,
177                                     DWORD    dwActivationData,
178                                     LPCWSTR  *ppwzActivationData,
179                                     int      *pReturnValue);
180
181     STDMETHODIMP ExecuteInDefaultAppDomain(LPCWSTR pwzAssemblyPath,
182                                            LPCWSTR pwzTypeName,
183                                            LPCWSTR pwzMethodName,
184                                            LPCWSTR pwzArgument,
185                                            DWORD   *pReturnValue);
186
187     // *** ICLRRuntimeHost2 methods ***
188     STDMETHODIMP CreateAppDomainWithManager(
189         LPCWSTR wszFriendlyName,
190         DWORD  dwSecurityFlags,
191         LPCWSTR wszAppDomainManagerAssemblyName, 
192         LPCWSTR wszAppDomainManagerTypeName, 
193         int nProperties, 
194         LPCWSTR* pPropertyNames, 
195         LPCWSTR* pPropertyValues, 
196         DWORD* pAppDomainID);
197
198     STDMETHODIMP CreateDelegate(
199         DWORD appDomainID,
200         LPCWSTR wszAssemblyName,     
201         LPCWSTR wszClassName,     
202         LPCWSTR wszMethodName,
203         INT_PTR* fnPtr);
204
205     STDMETHODIMP Authenticate(ULONGLONG authKey);
206
207     STDMETHODIMP RegisterMacEHPort();
208     STDMETHODIMP SetStartupFlags(STARTUP_FLAGS flag);
209     STDMETHODIMP DllGetActivationFactory(
210         DWORD appDomainID, 
211         LPCWSTR wszTypeName,
212         IActivationFactory ** factory);
213
214     STDMETHODIMP ExecuteAssembly(
215         DWORD dwAppDomainId,
216         LPCWSTR pwzAssemblyPath,
217         int argc,
218         LPCWSTR* argv,
219         DWORD* pReturnValue);
220
221     static HRESULT PreloadAssembly(
222         LPCSTR szPath);
223
224     static HRESULT UnloadPreloadedAssemblies();
225
226     static STARTUP_FLAGS GetStartupFlags();
227
228     static BOOL HasStarted()
229     {
230         return m_RefCount != 0;
231     }
232
233 private:
234     // This flag indicates if this instance was the first to load and start CoreCLR
235     BOOL m_fFirstToLoadCLR;
236
237     // This flag will be used to ensure that a CoreCLR host can invoke Start/Stop in pairs only.
238     BOOL m_fStarted;
239     BOOL m_fAppDomainCreated; // this flag is used when an appdomain can only create a single appdomain
240
241     // Helpers for both ICLRRuntimeHost2 and ICLRPrivRuntime
242     HRESULT _CreateAppDomain(
243         LPCWSTR wszFriendlyName,
244         DWORD  dwFlags,
245         LPCWSTR wszAppDomainManagerAssemblyName, 
246         LPCWSTR wszAppDomainManagerTypeName, 
247         int nProperties, 
248         LPCWSTR* pPropertyNames, 
249         LPCWSTR* pPropertyValues,
250         DWORD* pAppDomainID);
251
252     HRESULT _CreateDelegate(
253         DWORD appDomainID,
254         LPCWSTR wszAssemblyName,     
255         LPCWSTR wszClassName,     
256         LPCWSTR wszMethodName,
257         INT_PTR* fnPtr);
258
259     // entrypoint helper to be wrapped in a filter to process unhandled exceptions
260     VOID ExecuteMainInner(Assembly* pRootAssembly);
261
262     static LONG  m_RefCount;
263
264     SVAL_DECL(STARTUP_FLAGS, m_dwStartupFlags);
265 };
266
267 #ifdef FEATURE_COMINTEROP
268 extern "C"
269 HRESULT STDMETHODCALLTYPE DllGetActivationFactoryImpl(
270                                                       LPCWSTR wszAssemblyName, 
271                                                       LPCWSTR wszTypeName, 
272                                                       LPCWSTR wszCodeBase,
273                                                       IActivationFactory ** factory);
274
275 #endif // defined(FEATURE_COMINTEROP)
276
277 extern SIZE_T Host_SegmentSize;
278 extern SIZE_T Host_MaxGen0Size;
279 extern BOOL  Host_fSegmentSizeSet;
280 extern BOOL  Host_fMaxGen0SizeSet;
281
282 #define PARTIAL_TRUST_VISIBLE_ASSEMBLIES_PROPERTY W("PARTIAL_TRUST_VISIBLE_ASSEMBLIES")
283 #endif // __CorHost__h__