summaryrefslogtreecommitdiff
path: root/src/jit/eeinterface.cpp
blob: 658123097841b464db4020591928930f5347a2d5 (plain)
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
// 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.
*/

struct FilterSuperPMIExceptionsParam_eeinterface
{
    Compiler*               pThis;
    Compiler::Info*         pJitInfo;
    bool                    hasThis;
    size_t                  siglength;
    CORINFO_SIG_INFO        sig;
    CORINFO_ARG_LIST_HANDLE argLst;
    CORINFO_METHOD_HANDLE   hnd;
    const char*             returnType;
    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;
}

const char* Compiler::eeGetMethodFullName(CORINFO_METHOD_HANDLE hnd)
{
    const char* className;
    const char* 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 */

    PAL_TRY(FilterSuperPMIExceptionsParam_eeinterface*, pParam, &param)
    {
        unsigned i;
        pParam->pThis->eeGetMethodSig(pParam->hnd, &pParam->sig);
        pParam->argLst = pParam->sig.args;

        for (i = 0; i < pParam->sig.numArgs; i++)
        {
            var_types type = pParam->pThis->eeGetArgType(pParam->argLst, &pParam->sig);

            pParam->siglength += strlen(varTypeName(type));
            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);
        }

        if (JITtype2varType(pParam->sig.retType) != TYP_VOID)
        {
            pParam->returnType = varTypeName(JITtype2varType(pParam->sig.retType));
            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 = (char*)compGetMem(length, CMK_DebugOnly);

    /* 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, &param.sig);
            strcat_s(retName, length, varTypeName(type));

            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)

/*****************************************************************************/