-
Notifications
You must be signed in to change notification settings - Fork 359
/
Copy pathclrma.cpp
143 lines (122 loc) · 3.75 KB
/
clrma.cpp
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
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
#include "exts.h"
#include "managedanalysis.h"
HRESULT CLRMACreateInstance(ICLRManagedAnalysis** ppCLRMA);
HRESULT CLRMAReleaseInstance();
ICLRManagedAnalysis* g_managedAnalysis = nullptr;
int g_clrmaGlobalFlags = ClrmaGlobalFlags::LoggingEnabled | ClrmaGlobalFlags::DacClrmaEnabled | ClrmaGlobalFlags::ManagedClrmaEnabled;
//
// Exports
//
HRESULT
CLRMACreateInstance(ICLRManagedAnalysis** ppCLRMA)
{
HRESULT hr = E_UNEXPECTED;
if (ppCLRMA == nullptr)
{
return E_INVALIDARG;
}
*ppCLRMA = nullptr;
if (g_managedAnalysis == nullptr)
{
g_managedAnalysis = new (std::nothrow) ClrmaManagedAnalysis();
if (g_managedAnalysis == nullptr)
{
return E_OUTOFMEMORY;
}
OnUnloadTask::Register(([]() { CLRMAReleaseInstance(); }));
}
g_managedAnalysis->AddRef();
*ppCLRMA = g_managedAnalysis;
return S_OK;
}
HRESULT
CLRMAReleaseInstance()
{
TraceInformation("CLRMAReleaseInstance\n");
if (g_managedAnalysis != nullptr)
{
g_managedAnalysis->Release();
g_managedAnalysis = nullptr;
}
return S_OK;
}
DECLARE_API(clrmaconfig)
{
INIT_API_EXT();
BOOL bEnable = FALSE;
BOOL bDisable = FALSE;
BOOL bDacClrma = FALSE;
BOOL bManagedClrma = FALSE;
BOOL bLogging = FALSE;
CMDOption option[] =
{ // name, vptr, type, hasValue
{"-enable", &bEnable, COBOOL, FALSE},
{"-disable", &bDisable, COBOOL, FALSE},
{"-dac", &bDacClrma, COBOOL, FALSE},
{"-managed", &bManagedClrma, COBOOL, FALSE},
{"-logging", &bLogging, COBOOL, FALSE},
};
if (!GetCMDOption(args, option, ARRAY_SIZE(option), NULL, 0, NULL))
{
return E_INVALIDARG;
}
if (bEnable)
{
if (bDacClrma)
{
g_clrmaGlobalFlags |= ClrmaGlobalFlags::DacClrmaEnabled;
}
if (bManagedClrma)
{
g_clrmaGlobalFlags |= ClrmaGlobalFlags::ManagedClrmaEnabled;
}
if (bLogging)
{
g_clrmaGlobalFlags |= ClrmaGlobalFlags::LoggingEnabled;
}
}
else if (bDisable)
{
if (bDacClrma)
{
g_clrmaGlobalFlags &= ~ClrmaGlobalFlags::DacClrmaEnabled;
}
if (bManagedClrma)
{
g_clrmaGlobalFlags &= ~ClrmaGlobalFlags::ManagedClrmaEnabled;
}
if (bLogging)
{
g_clrmaGlobalFlags &= ~ClrmaGlobalFlags::LoggingEnabled;
}
}
ExtOut("CLRMA logging: %s\n", (g_clrmaGlobalFlags & ClrmaGlobalFlags::LoggingEnabled) ? "enabled (disable with '-disable -logging')" : "disabled (enable with '-enable -logging')");
ExtOut("CLRMA direct DAC support: %s\n", (g_clrmaGlobalFlags & ClrmaGlobalFlags::DacClrmaEnabled) ? "enabled (disable with '-disable -dac')" : "disabled (enable with '-enable -dac')");
ExtOut("CLRMA managed support: %s\n", (g_clrmaGlobalFlags & ClrmaGlobalFlags::ManagedClrmaEnabled) ? "enabled (disable with '-disable -managed')" : "disabled (enable with '-enable -managed')");
return Status;
}
extern void InternalOutputVaList(ULONG mask, PCSTR format, va_list args);
void
TraceInformation(PCSTR format, ...)
{
if (g_clrmaGlobalFlags & ClrmaGlobalFlags::LoggingEnabled)
{
va_list args;
va_start(args, format);
InternalOutputVaList(DEBUG_OUTPUT_NORMAL, format, args);
va_end(args);
}
}
void
TraceError(PCSTR format, ...)
{
if (g_clrmaGlobalFlags & ClrmaGlobalFlags::LoggingEnabled)
{
va_list args;
va_start(args, format);
InternalOutputVaList(DEBUG_OUTPUT_ERROR, format, args);
va_end(args);
}
}