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 | #ifndef CLR_TESTHOOK_H |
9 | #define CLR_TESTHOOK_H |
10 | |
11 | // {CCB32DA2-2544-4195-8552-AC1986A83C73} |
12 | static const GUID IID_ICLRTestHook = |
13 | { 0xccb32da2, 0x2544, 0x4195, { 0x85, 0x52, 0xac, 0x19, 0x86, 0xa8, 0x3c, 0x73 } }; |
14 | static const GUID IID_ICLRTestHook2 = |
15 | { 0xccb32da2, 0x2544, 0x4195, { 0x85, 0x52, 0xac, 0x19, 0x86, 0xa8, 0x3c, 0x83 } }; |
16 | static const GUID IID_ICLRTestHook3 = |
17 | { 0xccb32da2, 0x2544, 0x4195, { 0x85, 0x52, 0xac, 0x19, 0x86, 0xa8, 0x3c, 0x84 } }; |
18 | static const GUID IID_ICLRTestHookManager = |
19 | { 0xccb32da2, 0x2544, 0x4195, { 0x85, 0x52, 0xac, 0x19, 0x86, 0xa8, 0x3c, 0x74 } }; |
20 | |
21 | enum |
22 | { |
23 | ADUF_ASYNCHRONOUS, //no wait |
24 | ADUF_NORMAL, //wait, might be kicked out |
25 | ADUF_FORCEFULLGC, //same as normal, but does full gc |
26 | }; |
27 | |
28 | enum |
29 | { |
30 | RTS_INITIALIZED, |
31 | RTS_DEFAULTADREADY, |
32 | RTS_CALLINGENTRYPOINT |
33 | }; |
34 | |
35 | enum |
36 | { |
37 | IM_FLAT=1, |
38 | IM_IMAGEMAP=2, |
39 | IM_FIXEDUP=4, |
40 | IM_LOADLIBRARY=0xc //always fixed up |
41 | }; |
42 | |
43 | class ICLRTestHook : public IUnknown |
44 | { |
45 | public: |
46 | STDMETHOD(AppDomainStageChanged)(DWORD adid,DWORD oldstage,DWORD newstage)=0; |
47 | STDMETHOD(NextFileLoadLevel)(DWORD adid, LPVOID domainfile,DWORD newlevel)=0; |
48 | STDMETHOD(CompletingFileLoadLevel)(DWORD adid, LPVOID domainfile,DWORD newlevel)=0; |
49 | STDMETHOD(CompletedFileLoadLevel)(DWORD adid, LPVOID domainfile,DWORD newlevel)=0; |
50 | STDMETHOD(EnteringAppDomain)(DWORD id)=0; |
51 | STDMETHOD(EnteredAppDomain)(DWORD id)=0; |
52 | STDMETHOD(LeavingAppDomain)(DWORD id)=0; |
53 | STDMETHOD(LeftAppDomain)(DWORD id)=0; |
54 | STDMETHOD(UnwindingThreads)(DWORD id) = 0; |
55 | STDMETHOD(UnwoundThreads)(DWORD id) = 0; |
56 | STDMETHOD(AppDomainCanBeUnloaded)(DWORD id, BOOL bUnsafePoint)=0; |
57 | STDMETHOD(AppDomainDestroyed)(DWORD id)=0; |
58 | STDMETHOD(RuntimeStarted)(DWORD code)=0; |
59 | }; |
60 | |
61 | class ICLRTestHook2 : public ICLRTestHook |
62 | { |
63 | public: |
64 | STDMETHOD(ImageMapped(LPCWSTR wszPath, LPCVOID pBaseAddress,DWORD flags))=0; |
65 | }; |
66 | |
67 | class ICLRTestHook3 : public ICLRTestHook2 |
68 | { |
69 | public: |
70 | STDMETHOD(CompletedNativeImageBind)(LPVOID pFile,LPCUTF8 simpleName, BOOL hasNativeImage)=0; |
71 | STDMETHOD(AboutToLockImage)(LPCWSTR wszPath, BOOL bIsCompilationProcess)=0; |
72 | STDMETHOD(StartingNativeImageBind)(LPCWSTR wszAsmName, BOOL bIsCompilationProcess)=0; |
73 | }; |
74 | |
75 | class ICLRTestHookManager |
76 | { |
77 | public: |
78 | STDMETHOD(AddTestHook)(ICLRTestHook* hook)=0; |
79 | STDMETHOD(EnableSlowPath) (BOOL bEnable) =0; |
80 | STDMETHOD(UnloadAppDomain)(DWORD adid,DWORD flags)=0; |
81 | STDMETHOD_(VOID,DoAppropriateWait)( int cObjs, HANDLE *pObjs, INT32 iTimeout, BOOL bWaitAll, int* res)=0; |
82 | STDMETHOD(GC)(int generation)=0; |
83 | STDMETHOD(GetSimpleName)(LPVOID domainfile,LPCUTF8* name)=0; |
84 | STDMETHOD_(INT_PTR,GetCurrentThreadType)(VOID)=0; //see clrhost.h |
85 | STDMETHOD_(INT_PTR,GetCurrentThreadLockCount) (VOID) =0; |
86 | STDMETHOD_(BOOL,IsPreemptiveGC)(VOID) =0; |
87 | STDMETHOD_(BOOL,ThreadCanBeAborted) (VOID) = 0; |
88 | }; |
89 | |
90 | class ICLRTestHookManager2 : public ICLRTestHookManager |
91 | { |
92 | public: |
93 | STDMETHOD(HasNativeImage)(LPVOID domainfile,BOOL* pHasNativeImage) = 0; |
94 | }; |
95 | |
96 | //sample implementation |
97 | class CLRTestHook : public ICLRTestHook3 |
98 | { |
99 | private: |
100 | LONG m_cRef; |
101 | public: |
102 | CLRTestHook() |
103 | { |
104 | m_cRef=0; |
105 | } |
106 | virtual ~CLRTestHook() {} |
107 | STDMETHOD(AppDomainStageChanged)(DWORD adid,DWORD oldstage,DWORD newstage){ return S_OK;}; |
108 | STDMETHOD(NextFileLoadLevel)(DWORD adid, LPVOID domainfile,DWORD newlevel){ return S_OK;}; |
109 | STDMETHOD(CompletingFileLoadLevel)(DWORD adid, LPVOID domainfile,DWORD newlevel){ return S_OK;}; |
110 | STDMETHOD(CompletedFileLoadLevel)(DWORD adid, LPVOID domainfile,DWORD newlevel){ return S_OK;}; |
111 | STDMETHOD(EnteringAppDomain)(DWORD id){ return S_OK;}; |
112 | STDMETHOD(EnteredAppDomain)(DWORD id){ return S_OK;}; |
113 | STDMETHOD(LeavingAppDomain)(DWORD id){ return S_OK;}; |
114 | STDMETHOD(LeftAppDomain)(DWORD id){ return S_OK;}; |
115 | STDMETHOD(UnwindingThreads)(DWORD id) {return S_OK;}; |
116 | STDMETHOD(UnwoundThreads)(DWORD id) {return S_OK;}; |
117 | STDMETHOD(AppDomainCanBeUnloaded)(DWORD id, BOOL bUnsafePoint){ return S_OK;}; |
118 | STDMETHOD(AppDomainDestroyed)(DWORD id){ return S_OK;}; |
119 | STDMETHOD(RuntimeStarted)(DWORD code){ return S_OK;}; |
120 | STDMETHOD(ImageMapped(LPCWSTR wszPath, LPCVOID pBaseAddress,DWORD flags)){return S_OK;}; |
121 | STDMETHOD(CompletedNativeImageBind)(LPVOID pFile,LPCUTF8 simpleName, BOOL hasNativeImage){return S_OK;}; |
122 | STDMETHOD(AboutToLockImage)(LPCWSTR wszPath, BOOL bIsCompilationProcess){return S_OK;}; |
123 | STDMETHOD(StartingNativeImageBind)(LPCWSTR wszAsmName, BOOL bIsCompilationProcess){return S_OK;}; |
124 | STDMETHOD_(ULONG,AddRef)() |
125 | { |
126 | return InterlockedIncrement(&m_cRef); |
127 | }; |
128 | STDMETHOD_(ULONG,Release)() |
129 | { |
130 | ULONG ulRef = InterlockedDecrement(&m_cRef); |
131 | if (!ulRef) |
132 | delete this; |
133 | return ulRef; |
134 | }; |
135 | STDMETHOD(QueryInterface)(REFIID riid, void** ppv) |
136 | { |
137 | if (!ppv) |
138 | return E_POINTER; |
139 | |
140 | if ( IsEqualIID(riid, IID_IUnknown) |
141 | || IsEqualIID(riid, IID_ICLRTestHook) |
142 | || IsEqualIID(riid, IID_ICLRTestHook2) |
143 | || IsEqualIID(riid, IID_ICLRTestHook3)) |
144 | { |
145 | AddRef(); |
146 | *ppv = static_cast<ICLRTestHook3*>(this); |
147 | return S_OK; |
148 | } |
149 | else |
150 | { |
151 | *ppv = NULL; |
152 | return E_NOINTERFACE; |
153 | } |
154 | }; |
155 | }; |
156 | |
157 | typedef void CALLBACK CLRTESTHOOKPROC(ICLRTestHookManager*); |
158 | |
159 | #endif |
160 | |