This repository was archived by the owner on Jan 23, 2023. It is now read-only.
- Notifications
You must be signed in to change notification settings - Fork 2.6k
/
Copy patheeinterface.cpp
264 lines (217 loc) · 8.16 KB
/
eeinterface.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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
// 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.
/*XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XX XX
XX EEInterface XX
XX XX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
*/
// ONLY FUNCTIONS common to all variants of the JIT (EXE, DLL) should go here)
// otherwise they belong in the corresponding directory.
#include"jitpch.h"
#ifdef _MSC_VER
#pragma hdrstop
#endif
#if defined(DEBUG) || defined(FEATURE_JIT_METHOD_PERF) || defined(FEATURE_SIMD)
#pragma warning(push)
#pragma warning(disable : 4701) // difficult to get rid of C4701 with 'sig' below
/*****************************************************************************/
/*****************************************************************************
*
* Filter wrapper to handle exception filtering.
* On Unix compilers don't support SEH.
*/
structFilterSuperPMIExceptionsParam_eeinterface
{
Compiler* pThis;
Compiler::Info* pJitInfo;
bool hasThis;
size_t siglength;
CORINFO_SIG_INFO sig;
CORINFO_ARG_LIST_HANDLE argLst;
CORINFO_METHOD_HANDLE hnd;
constchar* returnType;
constchar** pArgNames;
EXCEPTION_POINTERS exceptionPointers;
};
static LONG FilterSuperPMIExceptions_eeinterface(PEXCEPTION_POINTERS pExceptionPointers, LPVOID lpvParam)
{
FilterSuperPMIExceptionsParam_eeinterface* pSPMIEParam = (FilterSuperPMIExceptionsParam_eeinterface*)lpvParam;
pSPMIEParam->exceptionPointers = *pExceptionPointers;
if (pSPMIEParam->pThis->IsSuperPMIException(pExceptionPointers->ExceptionRecord->ExceptionCode))
{
return EXCEPTION_EXECUTE_HANDLER;
}
return EXCEPTION_CONTINUE_SEARCH;
}
constchar* Compiler::eeGetMethodFullName(CORINFO_METHOD_HANDLE hnd)
{
constchar* className;
constchar* methodName = eeGetMethodName(hnd, &className);
if ((eeGetHelperNum(hnd) != CORINFO_HELP_UNDEF) || eeIsNativeMethod(hnd))
{
return methodName;
}
FilterSuperPMIExceptionsParam_eeinterface param;
param.returnType = nullptr;
param.pThis = this;
param.hasThis = false;
param.siglength = 0;
param.hnd = hnd;
param.pJitInfo = &info;
size_t length = 0;
unsigned i;
/* Generating the full signature is a two-pass process. First we have to walk
the components in order to assess the total size, then we allocate the buffer
and copy the elements into it.
*/
/* Right now there is a race-condition in the EE, className can be nullptr */
/* initialize length with length of className and '.' */
if (className)
{
length = strlen(className) + 1;
}
else
{
assert(strlen("<NULL>.") == 7);
length = 7;
}
/* add length of methodName and opening bracket */
length += strlen(methodName) + 1;
/* figure out the signature */
param.pThis->eeGetMethodSig(param.hnd, ¶m.sig);
// allocate space to hold the class names for each of the parameters
if (param.sig.numArgs > 0)
{
param.pArgNames = getAllocator(CMK_DebugOnly).allocate<constchar*>(param.sig.numArgs);
}
else
{
param.pArgNames = nullptr;
}
PAL_TRY(FilterSuperPMIExceptionsParam_eeinterface*, pParam, ¶m)
{
unsigned i;
pParam->argLst = pParam->sig.args;
for (i = 0; i < pParam->sig.numArgs; i++)
{
var_types type = pParam->pThis->eeGetArgType(pParam->argLst, &pParam->sig);
switch (type)
{
case TYP_REF:
case TYP_STRUCT:
{
CORINFO_CLASS_HANDLE clsHnd = pParam->pThis->eeGetArgClass(&pParam->sig, pParam->argLst);
// For some SIMD struct types we can get a nullptr back from eeGetArgClass on Linux/X64
if (clsHnd != NO_CLASS_HANDLE)
{
constchar* clsName = pParam->pThis->eeGetClassName(clsHnd);
if (clsName != nullptr)
{
pParam->pArgNames[i] = clsName;
break;
}
}
}
__fallthrough;
default:
pParam->pArgNames[i] = varTypeName(type);
break;
}
pParam->siglength += strlen(pParam->pArgNames[i]);
pParam->argLst = pParam->pJitInfo->compCompHnd->getArgNext(pParam->argLst);
}
/* add ',' if there is more than one argument */
if (pParam->sig.numArgs > 1)
{
pParam->siglength += (pParam->sig.numArgs - 1);
}
var_types retType = JITtype2varType(pParam->sig.retType);
if (retType != TYP_VOID)
{
switch (retType)
{
case TYP_REF:
case TYP_STRUCT:
{
CORINFO_CLASS_HANDLE clsHnd = pParam->sig.retTypeClass;
if (clsHnd != NO_CLASS_HANDLE)
{
constchar* clsName = pParam->pThis->eeGetClassName(clsHnd);
if (clsName != nullptr)
{
pParam->returnType = clsName;
break;
}
}
}
__fallthrough;
default:
pParam->returnType = varTypeName(retType);
break;
}
pParam->siglength += strlen(pParam->returnType) + 1; // don't forget the delimiter ':'
}
// Does it have a 'this' pointer? Don't count explicit this, which has the this pointer type as the first
// element of the arg type list
if (pParam->sig.hasThis() && !pParam->sig.hasExplicitThis())
{
assert(strlen(":this") == 5);
pParam->siglength += 5;
pParam->hasThis = true;
}
}
PAL_EXCEPT_FILTER(FilterSuperPMIExceptions_eeinterface)
{
param.siglength = 0;
}
PAL_ENDTRY
/* add closing bracket and null terminator */
length += param.siglength + 2;
char* retName = getAllocator(CMK_DebugOnly).allocate<char>(length);
/* Now generate the full signature string in the allocated buffer */
if (className)
{
strcpy_s(retName, length, className);
strcat_s(retName, length, ":");
}
else
{
strcpy_s(retName, length, "<NULL>.");
}
strcat_s(retName, length, methodName);
// append the signature
strcat_s(retName, length, "(");
if (param.siglength > 0)
{
param.argLst = param.sig.args;
for (i = 0; i < param.sig.numArgs; i++)
{
var_types type = eeGetArgType(param.argLst, ¶m.sig);
strcat_s(retName, length, param.pArgNames[i]);
param.argLst = info.compCompHnd->getArgNext(param.argLst);
if (i + 1 < param.sig.numArgs)
{
strcat_s(retName, length, ",");
}
}
}
strcat_s(retName, length, ")");
if (param.returnType != nullptr)
{
strcat_s(retName, length, ":");
strcat_s(retName, length, param.returnType);
}
if (param.hasThis)
{
strcat_s(retName, length, ":this");
}
assert(strlen(retName) == (length - 1));
return (retName);
}
#pragma warning(pop)
#endif// defined(DEBUG) || defined(FEATURE_JIT_METHOD_PERF) || defined(FEATURE_SIMD)
/*****************************************************************************/