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