-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathHostContext.h
106 lines (73 loc) · 3.16 KB
/
HostContext.h
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
#ifndef CONTEXT_H_INCLUDED
#define CONTEXT_H_INCLUDED
#include "Common.h"
#include <map>
#include <list>
#import "SimpleHostRuntime.tlb" no_namespace named_guids
//using namespace SimpleHostRuntime;
#include "AppDomainInfo.h"
const int MAX_THREAD_PER_DOMAIN = 10;
const int MAX_ALLOCS_PER_DOMAIN = 1000;
const int MAX_BYTES_PER_DOMAIN = 10 * 1024 * 1024; // 10 MB
struct MemoryInfo {
DWORD appDomainId;
DWORD dwBytes;
};
class HostContext: public IHostContext {
private:
volatile LONG m_cRef;
LPCRITICAL_SECTION domainMapCrst;
std::map<DWORD, AppDomainInfo> appDomains;
#ifdef TRACK_THREAD_RELATIONSHIP
std::map<DWORD, DWORD> childThreadToParent;
#endif //TRACK_THREAD_RELATIONSHIP
std::map<DWORD, DWORD> threadAppDomain;
std::map<void*, MemoryInfo> memoryAppDomain;
volatile unsigned long numZombieDomains;
ISimpleHostDomainManager* defaultDomainManager;
DWORD defaultDomainId;
ICLRRuntimeHost* runtimeHost;
// Our "windows-style" message queue
std::list<HostEvent> messageQueue;
LPCRITICAL_SECTION messageQueueCrst;
HANDLE hMessageEvent;
public:
HostContext(ICLRRuntimeHost* runtimeHost);
virtual ~HostContext();
// IUnknown functions
STDMETHODIMP_(DWORD) AddRef();
STDMETHODIMP_(DWORD) Release();
STDMETHODIMP QueryInterface(const IID &riid, void **ppvObject);
// IHostContext functions
virtual STDMETHODIMP raw_GetThreadCount(
/*[in]*/ long appDomainId,
/*[out,retval]*/ long * pRetVal);
virtual STDMETHODIMP raw_GetMemoryUsage(
/*[in]*/ long appDomainId,
/*[out,retval]*/ long * pRetVal);
virtual STDMETHODIMP raw_GetNumberOfZombies(
/*[out,retval]*/ long * pRetVal);
virtual STDMETHODIMP raw_ResetCountersForAppDomain(/*[in]*/long appDomainId);
virtual STDMETHODIMP raw_UnloadDomain(/*[in]*/long appDomainId);
virtual STDMETHODIMP raw_GetLastMessage(/*[in]*/ long dwMilliseconds, /*[out]*/ HostEvent* hostEvent, /*[out,retval]*/ VARIANT_BOOL* eventPresent);
void PostHostMessage(long eventType, long appDomainId, long managedThreadId);
void OnDomainUnload(DWORD domainId);
void OnDomainRudeUnload();
void OnDomainCreate(DWORD domainId, DWORD dwCurrentThreadId, ISimpleHostDomainManager* domainManager);
ISimpleHostDomainManager* GetDomainManagerForDefaultDomain();
// Notifies that the managed code "got hold" (created, got from a pool) of a new thread
bool OnThreadAcquiring(DWORD dwParentThreadId);
bool OnThreadAcquire(DWORD dwParentThreadId, DWORD dwNewThreadId);
bool OnThreadRelease(DWORD dwThreadId);
bool OnMemoryAcquiring(DWORD dwThreadId, LONG bytes);
void OnMemoryAcquire(DWORD dwThreadId, LONG bytes, PVOID address);
int OnMemoryRelease(PVOID address);
bool IsSnippetThread(DWORD nativeThreadId);
static HRESULT HostWait(HANDLE hWait, DWORD dwMilliseconds, DWORD dwOption);
static HRESULT Sleep(DWORD dwMilliseconds, DWORD dwOption);
static HRESULT HRESULTFromWaitResult(DWORD dwWaitResult);
// Check the "status" of a Snippet-AppDomain
// TODO: consider using ICLRAppDomainResourceMonitor
// http://msdn.microsoft.com/en-us/library/vstudio/dd627196%28v=vs.100%29.aspx
};
#endif //CONTEXT_H_INCLUDED