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#ifndef _IExecutionEngine
7#define _IExecutionEngine
8
9#include "ieememorymanager.h"
10
11/*
12interface IExecutionEngine : IUnknown
13{
14 // Thread Local Storage is based on logical threads. The underlying
15 // implementation could be threads, fibers, or something more exotic.
16 // Slot numbers are predefined. This is not a general extensibility
17 // mechanism.
18
19 // Associate a callback function for releasing TLS on thread/fiber death.
20 // This can be NULL.
21 void TLS_AssociateCallback([in] DWORD slot, [in] PTLS_CALLBACK_FUNCTION callback)
22
23 // May be called once to get the master TLS block slot for fast Get/Set operations
24 DWORD TLS_GetMasterSlotIndex()
25
26 // Get the value at a slot
27 PVOID TLS_GetValue([in] DWORD slot)
28
29 // Get the value at a slot, return FALSE if TLS info block doesn't exist
30 BOOL TLS_CheckValue([in] DWORD slot, [out] PVOID * pValue)
31
32 // Set the value at a slot
33 void TLS_SetValue([in] DWORD slot, [in] PVOID pData)
34
35 // Free TLS memory block and make callback
36 void TLS_ThreadDetaching()
37
38 // Critical Sections are sometimes exposed to the host and therefore need to be
39 // reflected from all CLR DLLs to the EE.
40 //
41 // In addition, we always monitor interactions between the lock & the GC, based
42 // on the GC mode in which the lock is acquired and we restrict what operations
43 // are permitted while holding the lock based on this.
44 //
45 // Finally, we we rank all our locks to prevent deadlock across all the DLLs of
46 // the CLR. This is the level argument to CreateLock.
47 //
48 // All usage of these locks must be exception-safe. To achieve this, we suggest
49 // using Holders (see holder.h & crst.h). In fact, within the EE code cannot
50 // hold locks except by using exception-safe holders.
51
52 CRITSEC_COOKIE CreateLock([in] LPCSTR szTag, [in] LPCSTR level, [in] CrstFlags flags)
53
54 void DestroyLock([in] CRITSEC_COOKIE lock)
55
56 void AcquireLock([in] CRITSEC_COOKIE lock)
57
58 void ReleaseLock([in] CRITSEC_COOKIE lock)
59
60 EVENT_COOKIE CreateAutoEvent([in] BOOL bInitialState)
61 EVENT_COOKIE CreateManualEvent([in] BOOL bInitialState)
62 void CloseEvent([in] EVENT_COOKIE event)
63 BOOL ClrSetEvent([in] EVENT_COOKIE event)
64 BOOL ClrResetEvent([in] EVENT_COOKIE event)
65 DWORD WaitForEvent([in] EVENT_COOKIE event, [in] DWORD dwMilliseconds, [in] BOOL bAlertable)
66 DWORD WaitForSingleObject([in] HANDLE handle, [in] DWORD dwMilliseconds)
67
68 // OS header file defines CreateSemaphore.
69 SEMAPHORE_COOKIE ClrCreateSemaphore([in] DWORD dwInitial, [in] DWORD dwMax)
70 void ClrCloseSemaphore([in] SEMAPHORE_COOKIE semaphore)
71 DWORD ClrWaitForSemaphore([in] SEMAPHORE_COOKIE semaphore, [in] DWORD dwMilliseconds, [in] BOOL bAlertable)
72 BOOL ClrReleaseSemaphore([in] SEMAPHORE_COOKIE semaphore, [in] LONG lReleaseCount, [in] LONG *lpPreviousCount)
73
74 MUTEX_COOKIE ClrCreateMutex([in]LPSECURITY_ATTRIBUTES lpMutexAttributes, [in]BOOL bInitialOwner, [in]LPCTSTR lpName)
75 DWORD ClrWaitForMutex([in] MUTEX_COOKIE mutex, [in] DWORD dwMilliseconds, [in] BOOL bAlertable)
76 BOOL ClrReleaseMutex([in] MUTEX_COOKIE mutex)
77 void ClrCloseMutex([in] MUTEX_COOKIE mutex)
78
79 DWORD ClrSleepEx([in] DWORD dwMilliseconds, [in] BOOL bAlertable)
80
81 BOOL ClrAllocationDisallowed()
82
83 void GetLastThrownObjectExceptionFromThread([out] void **ppvException)
84
85}; // interface IExecutionEngine
86*/
87
88class interceptor_IEE : public IExecutionEngine
89{
90private:
91 //***************************************************************************
92 // IUnknown methods
93 //***************************************************************************
94 HRESULT STDMETHODCALLTYPE QueryInterface(REFIID id, void** pInterface);
95 ULONG STDMETHODCALLTYPE AddRef();
96 ULONG STDMETHODCALLTYPE Release();
97
98 //***************************************************************************
99 // IExecutionEngine methods for TLS
100 //***************************************************************************
101 // Associate a callback for cleanup with a TLS slot
102 VOID STDMETHODCALLTYPE TLS_AssociateCallback(DWORD slot, PTLS_CALLBACK_FUNCTION callback);
103 // Get the TLS block for fast Get/Set operations
104 LPVOID* STDMETHODCALLTYPE TLS_GetDataBlock();
105 // Get the value at a slot
106 LPVOID STDMETHODCALLTYPE TLS_GetValue(DWORD slot);
107 // Get the value at a slot, return FALSE if TLS info block doesn't exist
108 BOOL STDMETHODCALLTYPE TLS_CheckValue(DWORD slot, LPVOID* pValue);
109 // Set the value at a slot
110 VOID STDMETHODCALLTYPE TLS_SetValue(DWORD slot, LPVOID pData);
111 // Free TLS memory block and make callback
112 VOID STDMETHODCALLTYPE TLS_ThreadDetaching();
113
114 //***************************************************************************
115 // IExecutionEngine methods for locking
116 //***************************************************************************
117 CRITSEC_COOKIE STDMETHODCALLTYPE CreateLock(LPCSTR szTag, LPCSTR level, CrstFlags flags);
118 void STDMETHODCALLTYPE DestroyLock(CRITSEC_COOKIE lock);
119 void STDMETHODCALLTYPE AcquireLock(CRITSEC_COOKIE lock);
120 void STDMETHODCALLTYPE ReleaseLock(CRITSEC_COOKIE lock);
121 EVENT_COOKIE STDMETHODCALLTYPE CreateAutoEvent(BOOL bInitialState);
122 EVENT_COOKIE STDMETHODCALLTYPE CreateManualEvent(BOOL bInitialState);
123 void STDMETHODCALLTYPE CloseEvent(EVENT_COOKIE event);
124 BOOL STDMETHODCALLTYPE ClrSetEvent(EVENT_COOKIE event);
125 BOOL STDMETHODCALLTYPE ClrResetEvent(EVENT_COOKIE event);
126 DWORD STDMETHODCALLTYPE WaitForEvent(EVENT_COOKIE event, DWORD dwMilliseconds, BOOL bAlertable);
127 DWORD STDMETHODCALLTYPE WaitForSingleObject(HANDLE handle, DWORD dwMilliseconds);
128 SEMAPHORE_COOKIE STDMETHODCALLTYPE ClrCreateSemaphore(DWORD dwInitial, DWORD dwMax);
129 void STDMETHODCALLTYPE ClrCloseSemaphore(SEMAPHORE_COOKIE semaphore);
130 DWORD STDMETHODCALLTYPE ClrWaitForSemaphore(SEMAPHORE_COOKIE semaphore, DWORD dwMilliseconds, BOOL bAlertable);
131 BOOL STDMETHODCALLTYPE ClrReleaseSemaphore(SEMAPHORE_COOKIE semaphore, LONG lReleaseCount, LONG* lpPreviousCount);
132 MUTEX_COOKIE STDMETHODCALLTYPE ClrCreateMutex(LPSECURITY_ATTRIBUTES lpMutexAttributes,
133 BOOL bInitialOwner,
134 LPCTSTR lpName);
135 void STDMETHODCALLTYPE ClrCloseMutex(MUTEX_COOKIE mutex);
136 BOOL STDMETHODCALLTYPE ClrReleaseMutex(MUTEX_COOKIE mutex);
137 DWORD STDMETHODCALLTYPE ClrWaitForMutex(MUTEX_COOKIE mutex, DWORD dwMilliseconds, BOOL bAlertable);
138 DWORD STDMETHODCALLTYPE ClrSleepEx(DWORD dwMilliseconds, BOOL bAlertable);
139 BOOL STDMETHODCALLTYPE ClrAllocationDisallowed();
140 void STDMETHODCALLTYPE GetLastThrownObjectExceptionFromThread(void** ppvException);
141
142public:
143 // Added so we know where to make the real calls to.
144 IExecutionEngine* original_IEE;
145};
146
147#endif