-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathil_rewriter.h
145 lines (104 loc) · 3.51 KB
/
il_rewriter.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
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
#ifndef OTEL_CLR_PROFILER_IL_REWRITER_H_
#define OTEL_CLR_PROFILER_IL_REWRITER_H_
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full
// license information.
#include <corhlpr.h>
#include <corprof.h>
typedef enum
{
#define OPDEF(c, s, pop, push, args, type, l, s1, s2, ctrl) c,
#include "opcode.def"
#undef OPDEF
CEE_COUNT,
CEE_SWITCH_ARG,
// special internal instructions
} OPCODE;
struct ILInstr
{
ILInstr* m_pNext;
ILInstr* m_pPrev;
unsigned m_opcode;
unsigned m_offset;
union
{
ILInstr* m_pTarget;
INT8 m_Arg8;
INT16 m_Arg16;
INT32 m_Arg32;
INT64 m_Arg64;
};
};
struct EHClause
{
CorExceptionFlag m_Flags;
ILInstr* m_pTryBegin;
ILInstr* m_pTryEnd;
ILInstr* m_pHandlerBegin; // First instruction inside the handler
ILInstr* m_pHandlerEnd; // Last instruction inside the handler
union
{
DWORD m_ClassToken; // use for type-based exception handlers
ILInstr* m_pFilter; // use for filter-based exception handlers
// (COR_ILEXCEPTION_CLAUSE_FILTER is set)
};
};
class ILRewriter
{
private:
ICorProfilerInfo* m_pICorProfilerInfo;
ICorProfilerFunctionControl* m_pICorProfilerFunctionControl;
ModuleID m_moduleId;
mdToken m_tkMethod;
mdToken m_tkLocalVarSig;
unsigned m_maxStack;
unsigned m_flags;
bool m_fGenerateTinyHeader;
ILInstr m_IL; // Double linked list of all il instructions
unsigned m_nEH;
EHClause* m_pEH;
// Helper table for importing. Sparse array that maps BYTE offset of
// beginning of an instruction to that instruction's ILInstr*. BYTE offsets
// that don't correspond to the beginning of an instruction are mapped to
// NULL.
ILInstr** m_pOffsetToInstr;
unsigned m_CodeSize;
unsigned m_nInstrs;
BYTE* m_pOutputBuffer;
IMethodMalloc* m_pIMethodMalloc;
public:
ILRewriter(ICorProfilerInfo* pICorProfilerInfo, ICorProfilerFunctionControl* pICorProfilerFunctionControl,
ModuleID moduleID, mdToken tkMethod);
~ILRewriter();
void InitializeTiny();
mdToken GetTkLocalVarSig();
void SetTkLocalVarSig(mdToken tkLocalVarSig);
unsigned GetEHCount();
EHClause* GetEHPointer();
void SetEHClause(EHClause* ehPointer, unsigned ehLength);
/////////////////////////////////////////////////////////////////////////////////////////////////
//
// I M P O R T
//
////////////////////////////////////////////////////////////////////////////////////////////////
HRESULT Import();
HRESULT ImportIL(LPCBYTE pIL);
HRESULT ImportEH(const COR_ILMETHOD_SECT_EH* pILEH, unsigned nEH);
ILInstr* NewILInstr();
HRESULT GetInstrFromOffset(unsigned offset, ILInstr** ppInstr);
void InsertBefore(ILInstr* pWhere, ILInstr* pWhat);
void InsertAfter(ILInstr* pWhere, ILInstr* pWhat);
void AdjustState(ILInstr* pNewInstr);
ILInstr* GetILList();
/////////////////////////////////////////////////////////////////////////////////////////////////
//
// E X P O R T
//
////////////////////////////////////////////////////////////////////////////////////////////////
HRESULT Export();
HRESULT SetILFunctionBody(unsigned size, LPBYTE pBody);
LPBYTE AllocateILMemory(unsigned size);
void DeallocateILMemory(LPBYTE pBody);
unsigned GetMaxStackValue();
};
#endif // OTEL_CLR_PROFILER_IL_REWRITER_H_