Add a fourth parameter to the DEFINE_DACVAR macro that is the actual fully qualified...
[platform/upstream/coreclr.git] / src / vm / ceemain.h
1 //
2 // Copyright (c) Microsoft. All rights reserved.
3 // Licensed under the MIT license. See LICENSE file in the project root for full license information.
4 //
5 // ===========================================================================
6 // File: CEEMAIN.H
7 // 
8
9 // 
10 //
11
12 // CEEMAIN.H defines the entrypoints into the Virtual Execution Engine and
13 // gets the load/run process going.
14 // ===========================================================================
15
16 #ifndef CEEMain_H
17 #define CEEMain_H
18
19 #include <windef.h> // for HFILE, HANDLE, HMODULE
20
21 class EEDbgInterfaceImpl;
22
23 // Ensure the EE is started up.
24 HRESULT EnsureEEStarted(COINITIEE flags);
25
26 // Wrapper around EnsureEEStarted which also sets startup mode.
27 HRESULT InitializeEE(COINITIEE flags);
28
29 // Has the EE been started up?
30 BOOL IsRuntimeStarted(DWORD *pdwStartupFlags);
31
32 // Enum to control what happens at the end of EE shutdown. There are two options:
33 // 1. Call ::ExitProcess to cause the process to terminate gracefully. This is how
34 //    shutdown normally ends. "Shutdown" methods that take this action as an argument
35 //    do not return when SCA_ExitProcessWhenShutdownComplete is passed.
36 //
37 // 2. Return after performing all shutdown processing. This is a special case used
38 //    by a shutdown initiated via the Shim, and is used to ensure that all runtimes
39 //    loaded SxS are shutdown gracefully. "Shutdown" methods that take this action
40 //    as an argument return when SCA_ReturnWhenShutdownComplete is passed.
41 enum ShutdownCompleteAction
42 {
43     SCA_ExitProcessWhenShutdownComplete,
44     SCA_ReturnWhenShutdownComplete
45 };
46
47 // Force shutdown of the EE
48 void ForceEEShutdown(ShutdownCompleteAction sca = SCA_ExitProcessWhenShutdownComplete);
49 void InnerCoEEShutDownCOM();
50
51 // We have an internal class that can be used to expose EE functionality to other CLR
52 // DLLs, via the deliberately obscure IEE DLL exports from the shim and the EE
53 // NOTE:  This class must not ever contain any instance variables.  The reason for
54 //        this is that the IEE function (corhost.cpp) relies on the fact that you
55 //        may initialize the object more than once without ill effects.  If you
56 //        change this class so that this condition is violated, you must rewrite
57 //        how the g_pCEE and related variables are initialized.
58 class CExecutionEngine : public IExecutionEngine, public IEEMemoryManager
59 {
60     friend struct _DacGlobals;
61
62     //***************************************************************************
63     // public API:
64     //***************************************************************************
65 public:
66
67     // Notification of a DLL_THREAD_DETACH or a Thread Terminate.
68     static void ThreadDetaching(void **pTlsData);
69
70     // Delete on TLS block
71     static void DeleteTLS(void **pTlsData);
72
73     // Fiber switch notifications
74     static void SwitchIn();
75     static void SwitchOut();
76
77     static void **CheckThreadState(DWORD slot, BOOL force = TRUE);
78     static void **CheckThreadStateNoCreate(DWORD slot
79 #ifdef _DEBUG
80                                            , BOOL fForDestruction = FALSE
81 #endif // _DEBUG
82                                            );
83
84     // Setup FLS simulation block, including ClrDebugState and StressLog.
85     static void SetupTLSForThread(Thread *pThread);
86
87     static DWORD GetTlsIndex () {return TlsIndex;}
88
89     static LPVOID* GetTlsData();
90     static BOOL SetTlsData (void** ppTlsInfo);
91
92     static BOOL HasDetachedTlsInfo();
93
94     static void CleanupDetachedTlsInfo();
95
96     static void DetachTlsInfo(void **pTlsData);
97
98     //***************************************************************************
99     // private implementation:
100     //***************************************************************************
101 private:
102
103     // The debugger needs access to the TlsIndex so that we can read it from OOP.
104     friend class EEDbgInterfaceImpl;
105
106     SVAL_DECL (DWORD, TlsIndex);
107
108     static PTLS_CALLBACK_FUNCTION Callbacks[MAX_PREDEFINED_TLS_SLOT];
109
110     //***************************************************************************
111     // IUnknown methods
112     //***************************************************************************
113
114     HRESULT STDMETHODCALLTYPE QueryInterface(
115             REFIID id,
116             void **pInterface);
117
118     ULONG STDMETHODCALLTYPE AddRef();
119
120     ULONG STDMETHODCALLTYPE Release();
121
122     //***************************************************************************
123     // IExecutionEngine methods for TLS
124     //***************************************************************************
125
126     // Associate a callback for cleanup with a TLS slot
127     VOID  STDMETHODCALLTYPE TLS_AssociateCallback(
128             DWORD slot,
129             PTLS_CALLBACK_FUNCTION callback);
130
131     // Get the TLS block for fast Get/Set operations
132     LPVOID* STDMETHODCALLTYPE TLS_GetDataBlock();
133
134     // Get the value at a slot
135     LPVOID STDMETHODCALLTYPE TLS_GetValue(DWORD slot);
136
137     // Get the value at a slot, return FALSE if TLS info block doesn't exist
138     BOOL STDMETHODCALLTYPE TLS_CheckValue(DWORD slot, LPVOID * pValue);
139
140     // Set the value at a slot
141     VOID STDMETHODCALLTYPE TLS_SetValue(DWORD slot, LPVOID pData);
142
143     // Free TLS memory block and make callback
144     VOID STDMETHODCALLTYPE TLS_ThreadDetaching();
145     
146     //***************************************************************************
147     // IExecutionEngine methods for locking
148     //***************************************************************************
149
150     CRITSEC_COOKIE STDMETHODCALLTYPE CreateLock(LPCSTR szTag, LPCSTR level, CrstFlags flags);
151
152     void STDMETHODCALLTYPE DestroyLock(CRITSEC_COOKIE lock);
153
154     void STDMETHODCALLTYPE AcquireLock(CRITSEC_COOKIE lock);
155
156     void STDMETHODCALLTYPE ReleaseLock(CRITSEC_COOKIE lock);
157
158     EVENT_COOKIE STDMETHODCALLTYPE CreateAutoEvent(BOOL bInitialState);
159     EVENT_COOKIE STDMETHODCALLTYPE CreateManualEvent(BOOL bInitialState);
160     void STDMETHODCALLTYPE CloseEvent(EVENT_COOKIE event);
161     BOOL STDMETHODCALLTYPE ClrSetEvent(EVENT_COOKIE event);
162     BOOL STDMETHODCALLTYPE ClrResetEvent(EVENT_COOKIE event);
163     DWORD STDMETHODCALLTYPE WaitForEvent(EVENT_COOKIE event, DWORD dwMilliseconds, BOOL bAlertable);
164     DWORD STDMETHODCALLTYPE WaitForSingleObject(HANDLE handle, DWORD dwMilliseconds);
165
166     SEMAPHORE_COOKIE STDMETHODCALLTYPE ClrCreateSemaphore(DWORD dwInitial, DWORD dwMax);
167     void STDMETHODCALLTYPE ClrCloseSemaphore(SEMAPHORE_COOKIE semaphore);
168     DWORD STDMETHODCALLTYPE ClrWaitForSemaphore(SEMAPHORE_COOKIE semaphore, DWORD dwMilliseconds, BOOL bAlertable);
169     BOOL STDMETHODCALLTYPE ClrReleaseSemaphore(SEMAPHORE_COOKIE semaphore, LONG lReleaseCount, LONG *lpPreviousCount);
170
171     MUTEX_COOKIE STDMETHODCALLTYPE ClrCreateMutex(LPSECURITY_ATTRIBUTES lpMutexAttributes,
172                                                   BOOL bInitialOwner,
173                                                   LPCTSTR lpName);
174     void STDMETHODCALLTYPE ClrCloseMutex(MUTEX_COOKIE mutex);
175     BOOL STDMETHODCALLTYPE ClrReleaseMutex(MUTEX_COOKIE mutex);
176     DWORD STDMETHODCALLTYPE ClrWaitForMutex(MUTEX_COOKIE mutex,
177                                             DWORD dwMilliseconds,
178                                             BOOL bAlertable);
179
180     DWORD STDMETHODCALLTYPE ClrSleepEx(DWORD dwMilliseconds, BOOL bAlertable);
181
182     BOOL STDMETHODCALLTYPE ClrAllocationDisallowed();
183
184     void STDMETHODCALLTYPE GetLastThrownObjectExceptionFromThread(void **ppvException);
185
186     //***************************************************************************
187     // IEEMemoryManager methods for locking
188     //***************************************************************************
189     LPVOID STDMETHODCALLTYPE ClrVirtualAlloc(LPVOID lpAddress, SIZE_T dwSize, DWORD flAllocationType, DWORD flProtect);
190     BOOL STDMETHODCALLTYPE ClrVirtualFree(LPVOID lpAddress, SIZE_T dwSize, DWORD dwFreeType);
191     SIZE_T STDMETHODCALLTYPE ClrVirtualQuery(LPCVOID lpAddress, PMEMORY_BASIC_INFORMATION lpBuffer, SIZE_T dwLength);
192     BOOL STDMETHODCALLTYPE ClrVirtualProtect(LPVOID lpAddress, SIZE_T dwSize, DWORD flNewProtect, PDWORD lpflOldProtect);
193     HANDLE STDMETHODCALLTYPE ClrGetProcessHeap();
194     HANDLE STDMETHODCALLTYPE ClrHeapCreate(DWORD flOptions, SIZE_T dwInitialSize, SIZE_T dwMaximumSize);
195     BOOL STDMETHODCALLTYPE ClrHeapDestroy(HANDLE hHeap);
196     LPVOID STDMETHODCALLTYPE ClrHeapAlloc(HANDLE hHeap, DWORD dwFlags, SIZE_T dwBytes);
197     BOOL STDMETHODCALLTYPE ClrHeapFree(HANDLE hHeap, DWORD dwFlags, LPVOID lpMem);
198     BOOL STDMETHODCALLTYPE ClrHeapValidate(HANDLE hHeap, DWORD dwFlags, LPCVOID lpMem);
199     HANDLE STDMETHODCALLTYPE ClrGetProcessExecutableHeap();
200     
201 };
202
203 #ifdef _DEBUG
204 extern void DisableGlobalAllocStore ();
205 #endif //_DEBUG 
206
207 void SetLatchedExitCode (INT32 code);
208 INT32 GetLatchedExitCode (void);
209
210 // Tells whether the garbage collector is fully initialized
211 // Stronger than IsGCHeapInitialized
212 BOOL IsGarbageCollectorFullyInitialized();
213
214 #ifndef FEATURE_CORECLR
215 //---------------------------------------------------------------------------------------
216 // 
217 // Class to encapsulate Cor Command line processing
218 // 
219 class CorCommandLine
220 {
221 public:
222
223 //********** TYPES
224
225     // Note: We don't bother with interlocked operations as we manipulate these bits,
226     // because we don't anticipate free-threaded access.  (Most of this is used only
227     // during startup / shutdown).
228
229 //********** DATA
230
231     // Hold the current (possibly parsed) command line here
232     static DWORD            m_NumArgs;
233     static LPWSTR          *m_ArgvW;
234
235     static LPWSTR          m_pwszAppFullName;
236     static DWORD           m_dwManifestPaths;
237     static LPWSTR         *m_ppwszManifestPaths;
238     static DWORD           m_dwActivationData;
239     static LPWSTR         *m_ppwszActivationData;
240
241 //********** METHODS
242
243     // parse the command line
244     static HRESULT         SetArgvW(LPCWSTR lpCommandLine);
245
246     // Retrieve the parsed command line
247     static LPWSTR          *GetArgvW(DWORD *pNumArgs);
248
249 private:
250     static HRESULT ReadClickOnceEnvVariables();
251 };
252 #endif // !FEATURE_CORECLR
253
254 #endif