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_TESTHOOKMGR_H
9#define CLR_TESTHOOKMGR_H
10
11#include "testhook.h"
12
13#if defined(_DEBUG) && !defined(CROSSGEN_COMPILE)
14#define FEATURE_TESTHOOKS
15#endif
16
17#ifdef FEATURE_TESTHOOKS
18#define TESTHOOKCALL(function) \
19 do { if(CLRTestHookManager::Enabled()) \
20 CLRTestHookManager::TestHook()->function;} while(0)
21
22#define TESTHOOKENABLED CLRTestHookManager::Enabled()
23#define TESTHOOKSLOWPATH CLRTestHookManager::SlowPathEnabled()
24
25#define MAX_TEST_HOOKS 32
26
27//Forward declarations
28template <typename T> class Volatile;
29extern "C" Volatile<LONG> g_TrapReturningThreads;
30
31
32struct CLRTestHookInfo
33{
34protected:
35 int m_Version;
36 union
37 {
38 ICLRTestHook* v1;
39 ICLRTestHook2* v2;
40 ICLRTestHook3* v3;
41 } m_Hook;
42public:
43 void Set(ICLRTestHook*);
44 ICLRTestHook* v1();
45 ICLRTestHook2* v2();
46 ICLRTestHook3* v3();
47};
48
49class CLRTestHookManager: public ICLRTestHookManager2, public ICLRTestHook3
50{
51protected:
52 static CLRTestHookManager* g_pManager;
53 Volatile<LONG> m_nHooks;
54 Volatile<LONG> m_cRef;
55 CLRTestHookInfo m_pHooks[MAX_TEST_HOOKS];
56 virtual ~CLRTestHookManager();
57public:
58 CLRTestHookManager();
59 STDMETHOD(AddTestHook)(ICLRTestHook* hook);
60 static ICLRTestHookManager* Start();
61 static BOOL Enabled() {return g_pManager!=NULL;};
62 static BOOL SlowPathEnabled() {return Enabled() && g_TrapReturningThreads;};
63 static CLRTestHookManager* TestHook() {return g_pManager;};
64 static HRESULT CheckConfig();
65 STDMETHOD_(ULONG,AddRef) ();
66 STDMETHOD_(ULONG, Release());
67 STDMETHOD (QueryInterface)(REFIID riid, void * *ppvObject);
68 STDMETHOD(AppDomainStageChanged)(DWORD adid,DWORD oldstage,DWORD newstage);
69 STDMETHOD(NextFileLoadLevel)(DWORD adid, LPVOID domainfile,DWORD newlevel);
70 STDMETHOD(CompletingFileLoadLevel)(DWORD adid, LPVOID domainfile,DWORD newlevel);
71 STDMETHOD(CompletedFileLoadLevel)(DWORD adid, LPVOID domainfile,DWORD newlevel);
72 STDMETHOD(EnteringAppDomain)(DWORD adid);
73 STDMETHOD(EnteredAppDomain)(DWORD adid);
74 STDMETHOD(LeavingAppDomain)(DWORD adid);
75 STDMETHOD(LeftAppDomain)(DWORD adid);
76 STDMETHOD(UnwindingThreads)(DWORD adid);
77 STDMETHOD(UnwoundThreads)(DWORD adid);
78 STDMETHOD(AppDomainCanBeUnloaded)(DWORD adid, BOOL bUnsafePoint);
79 STDMETHOD(AppDomainDestroyed)(DWORD adid);
80 STDMETHOD(EnableSlowPath) (BOOL bEnable);
81 STDMETHOD(UnloadAppDomain)(DWORD adid,DWORD flags);
82 STDMETHOD(StartingNativeImageBind)(LPCWSTR wszAsmName, BOOL bIsCompilationProcess);
83 STDMETHOD(CompletedNativeImageBind)(LPVOID pFile,LPCUTF8 simpleName, BOOL hasNativeImage);
84 STDMETHOD(AboutToLockImage)(LPCWSTR wszPath, BOOL bIsCompilationProcess);
85 STDMETHOD_(VOID,DoAppropriateWait)( int cObjs, HANDLE *pObjs, INT32 iTimeout, BOOL bWaitAll, int* res);
86 STDMETHOD(GC)(int generation);
87 STDMETHOD(GetSimpleName)(LPVOID domainfile,LPCUTF8* name);
88 STDMETHOD(RuntimeStarted)(DWORD code);
89 STDMETHOD_(INT_PTR,GetCurrentThreadType)(VOID);
90 STDMETHOD_(INT_PTR,GetCurrentThreadLockCount) (VOID);
91 STDMETHOD_(BOOL,IsPreemptiveGC)(VOID);
92 STDMETHOD_(BOOL,ThreadCanBeAborted) (VOID);
93 STDMETHOD(ImageMapped(LPCWSTR wszPath, LPCVOID pBaseAddress,DWORD flags));
94 STDMETHOD(HasNativeImage)(LPVOID domainfile,BOOL* pHasNativeImage);
95};
96#else
97#define TESTHOOKCALL(function)
98#define TESTHOOKENABLED FALSE
99#define TESTHOOKSLOWPATH FALSE
100#endif
101#endif
102