Merge pull request #14619 from briansull/emitter-cleanup
[platform/upstream/coreclr.git] / src / vm / ceemain.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 // File: CEEMAIN.H
6 // 
7
8 // 
9 //
10
11 // CEEMAIN.H defines the entrypoints into the Virtual Execution Engine and
12 // gets the load/run process going.
13 // ===========================================================================
14
15 #ifndef CEEMain_H
16 #define CEEMain_H
17
18 #include <windef.h> // for HFILE, HANDLE, HMODULE
19
20 class EEDbgInterfaceImpl;
21
22 // Ensure the EE is started up.
23 HRESULT EnsureEEStarted(COINITIEE flags);
24
25 // Wrapper around EnsureEEStarted which also sets startup mode.
26 HRESULT InitializeEE(COINITIEE flags);
27
28 // Has the EE been started up?
29 BOOL IsRuntimeStarted(DWORD *pdwStartupFlags);
30
31 // Enum to control what happens at the end of EE shutdown. There are two options:
32 // 1. Call ::ExitProcess to cause the process to terminate gracefully. This is how
33 //    shutdown normally ends. "Shutdown" methods that take this action as an argument
34 //    do not return when SCA_ExitProcessWhenShutdownComplete is passed.
35 //
36 // 2. Return after performing all shutdown processing. This is a special case used
37 //    by a shutdown initiated via the Shim, and is used to ensure that all runtimes
38 //    loaded SxS are shutdown gracefully. "Shutdown" methods that take this action
39 //    as an argument return when SCA_ReturnWhenShutdownComplete is passed.
40 enum ShutdownCompleteAction
41 {
42     SCA_ExitProcessWhenShutdownComplete,
43     SCA_ReturnWhenShutdownComplete
44 };
45
46 // Force shutdown of the EE
47 void ForceEEShutdown(ShutdownCompleteAction sca = SCA_ExitProcessWhenShutdownComplete);
48 void InnerCoEEShutDownCOM();
49
50 // We have an internal class that can be used to expose EE functionality to other CLR
51 // DLLs, via the deliberately obscure IEE DLL exports from the shim and the EE
52 // NOTE:  This class must not ever contain any instance variables.  The reason for
53 //        this is that the IEE function (corhost.cpp) relies on the fact that you
54 //        may initialize the object more than once without ill effects.  If you
55 //        change this class so that this condition is violated, you must rewrite
56 //        how the g_pCEE and related variables are initialized.
57 class CExecutionEngine : public IExecutionEngine, public IEEMemoryManager
58 {
59     friend struct _DacGlobals;
60
61     //***************************************************************************
62     // public API:
63     //***************************************************************************
64 public:
65
66     // Notification of a DLL_THREAD_DETACH or a Thread Terminate.
67     static void ThreadDetaching(void **pTlsData);
68
69     // Delete on TLS block
70     static void DeleteTLS(void **pTlsData);
71
72     // Fiber switch notifications
73     static void SwitchIn();
74     static void SwitchOut();
75
76     static void **CheckThreadState(DWORD slot, BOOL force = TRUE);
77     static void **CheckThreadStateNoCreate(DWORD slot
78 #ifdef _DEBUG
79                                            , BOOL fForDestruction = FALSE
80 #endif // _DEBUG
81                                            );
82
83     // Setup FLS simulation block, including ClrDebugState and StressLog.
84     static void SetupTLSForThread(Thread *pThread);
85
86     static LPVOID* GetTlsData();
87     static BOOL SetTlsData (void** ppTlsInfo);
88
89     //***************************************************************************
90     // private implementation:
91     //***************************************************************************
92 private:
93     static PTLS_CALLBACK_FUNCTION Callbacks[MAX_PREDEFINED_TLS_SLOT];
94
95     //***************************************************************************
96     // IUnknown methods
97     //***************************************************************************
98
99     HRESULT STDMETHODCALLTYPE QueryInterface(
100             REFIID id,
101             void **pInterface);
102
103     ULONG STDMETHODCALLTYPE AddRef();
104
105     ULONG STDMETHODCALLTYPE Release();
106
107     //***************************************************************************
108     // IExecutionEngine methods for TLS
109     //***************************************************************************
110
111     // Associate a callback for cleanup with a TLS slot
112     VOID  STDMETHODCALLTYPE TLS_AssociateCallback(
113             DWORD slot,
114             PTLS_CALLBACK_FUNCTION callback);
115
116     // Get the TLS block for fast Get/Set operations
117     LPVOID* STDMETHODCALLTYPE TLS_GetDataBlock();
118
119     // Get the value at a slot
120     LPVOID STDMETHODCALLTYPE TLS_GetValue(DWORD slot);
121
122     // Get the value at a slot, return FALSE if TLS info block doesn't exist
123     BOOL STDMETHODCALLTYPE TLS_CheckValue(DWORD slot, LPVOID * pValue);
124
125     // Set the value at a slot
126     VOID STDMETHODCALLTYPE TLS_SetValue(DWORD slot, LPVOID pData);
127
128     // Free TLS memory block and make callback
129     VOID STDMETHODCALLTYPE TLS_ThreadDetaching();
130     
131     //***************************************************************************
132     // IExecutionEngine methods for locking
133     //***************************************************************************
134
135     CRITSEC_COOKIE STDMETHODCALLTYPE CreateLock(LPCSTR szTag, LPCSTR level, CrstFlags flags);
136
137     void STDMETHODCALLTYPE DestroyLock(CRITSEC_COOKIE lock);
138
139     void STDMETHODCALLTYPE AcquireLock(CRITSEC_COOKIE lock);
140
141     void STDMETHODCALLTYPE ReleaseLock(CRITSEC_COOKIE lock);
142
143     EVENT_COOKIE STDMETHODCALLTYPE CreateAutoEvent(BOOL bInitialState);
144     EVENT_COOKIE STDMETHODCALLTYPE CreateManualEvent(BOOL bInitialState);
145     void STDMETHODCALLTYPE CloseEvent(EVENT_COOKIE event);
146     BOOL STDMETHODCALLTYPE ClrSetEvent(EVENT_COOKIE event);
147     BOOL STDMETHODCALLTYPE ClrResetEvent(EVENT_COOKIE event);
148     DWORD STDMETHODCALLTYPE WaitForEvent(EVENT_COOKIE event, DWORD dwMilliseconds, BOOL bAlertable);
149     DWORD STDMETHODCALLTYPE WaitForSingleObject(HANDLE handle, DWORD dwMilliseconds);
150
151     SEMAPHORE_COOKIE STDMETHODCALLTYPE ClrCreateSemaphore(DWORD dwInitial, DWORD dwMax);
152     void STDMETHODCALLTYPE ClrCloseSemaphore(SEMAPHORE_COOKIE semaphore);
153     DWORD STDMETHODCALLTYPE ClrWaitForSemaphore(SEMAPHORE_COOKIE semaphore, DWORD dwMilliseconds, BOOL bAlertable);
154     BOOL STDMETHODCALLTYPE ClrReleaseSemaphore(SEMAPHORE_COOKIE semaphore, LONG lReleaseCount, LONG *lpPreviousCount);
155
156     MUTEX_COOKIE STDMETHODCALLTYPE ClrCreateMutex(LPSECURITY_ATTRIBUTES lpMutexAttributes,
157                                                   BOOL bInitialOwner,
158                                                   LPCTSTR lpName);
159     void STDMETHODCALLTYPE ClrCloseMutex(MUTEX_COOKIE mutex);
160     BOOL STDMETHODCALLTYPE ClrReleaseMutex(MUTEX_COOKIE mutex);
161     DWORD STDMETHODCALLTYPE ClrWaitForMutex(MUTEX_COOKIE mutex,
162                                             DWORD dwMilliseconds,
163                                             BOOL bAlertable);
164
165     DWORD STDMETHODCALLTYPE ClrSleepEx(DWORD dwMilliseconds, BOOL bAlertable);
166
167     BOOL STDMETHODCALLTYPE ClrAllocationDisallowed();
168
169     void STDMETHODCALLTYPE GetLastThrownObjectExceptionFromThread(void **ppvException);
170
171     //***************************************************************************
172     // IEEMemoryManager methods for locking
173     //***************************************************************************
174     LPVOID STDMETHODCALLTYPE ClrVirtualAlloc(LPVOID lpAddress, SIZE_T dwSize, DWORD flAllocationType, DWORD flProtect);
175     BOOL STDMETHODCALLTYPE ClrVirtualFree(LPVOID lpAddress, SIZE_T dwSize, DWORD dwFreeType);
176     SIZE_T STDMETHODCALLTYPE ClrVirtualQuery(LPCVOID lpAddress, PMEMORY_BASIC_INFORMATION lpBuffer, SIZE_T dwLength);
177     BOOL STDMETHODCALLTYPE ClrVirtualProtect(LPVOID lpAddress, SIZE_T dwSize, DWORD flNewProtect, PDWORD lpflOldProtect);
178     HANDLE STDMETHODCALLTYPE ClrGetProcessHeap();
179     HANDLE STDMETHODCALLTYPE ClrHeapCreate(DWORD flOptions, SIZE_T dwInitialSize, SIZE_T dwMaximumSize);
180     BOOL STDMETHODCALLTYPE ClrHeapDestroy(HANDLE hHeap);
181     LPVOID STDMETHODCALLTYPE ClrHeapAlloc(HANDLE hHeap, DWORD dwFlags, SIZE_T dwBytes);
182     BOOL STDMETHODCALLTYPE ClrHeapFree(HANDLE hHeap, DWORD dwFlags, LPVOID lpMem);
183     BOOL STDMETHODCALLTYPE ClrHeapValidate(HANDLE hHeap, DWORD dwFlags, LPCVOID lpMem);
184     HANDLE STDMETHODCALLTYPE ClrGetProcessExecutableHeap();
185     
186 };
187
188 #ifdef _DEBUG
189 extern void DisableGlobalAllocStore ();
190 #endif //_DEBUG 
191
192 void SetLatchedExitCode (INT32 code);
193 INT32 GetLatchedExitCode (void);
194
195 // Tells whether the garbage collector is fully initialized
196 // Stronger than IsGCHeapInitialized
197 BOOL IsGarbageCollectorFullyInitialized();
198
199
200 #endif