summaryrefslogtreecommitdiff
path: root/src/vm/clrtocomcall.h
blob: 6c25948ab42770e5153a5607e1c142b5e4105ca5 (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
// 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.
// 
// File: CLRtoCOMCall.h 
//

// 
// Used to handle stub creation for managed to unmanaged transitions.
// 


#ifndef __COMPLUSCALL_H__
#define __COMPLUSCALL_H__

#ifndef FEATURE_COMINTEROP
#error FEATURE_COMINTEROP is required for this file
#endif // FEATURE_COMINTEROP

#include "util.hpp"

class ComPlusCall
{
    public:
        //---------------------------------------------------------
        // Debugger helper function
        //---------------------------------------------------------
        static TADDR GetFrameCallIP(FramedMethodFrame *frame);

        static MethodDesc* GetILStubMethodDesc(MethodDesc* pMD, DWORD dwStubFlags);
        static PCODE       GetStubForILStub(MethodDesc* pMD, MethodDesc** ppStubMD);

        static ComPlusCallInfo *PopulateComPlusCallMethodDesc(MethodDesc* pMD, DWORD* pdwStubFlags);
        static MethodDesc *GetWinRTFactoryMethodForCtor(MethodDesc *pMDCtor, BOOL *pComposition);
        static MethodDesc *GetWinRTFactoryMethodForStatic(MethodDesc *pMDStatic);

#ifdef _TARGET_X86_
        static void Init();
        static LPVOID GetRetThunk(UINT numStackBytes);
#endif // _TARGET_X86_
    private:
        ComPlusCall();     // prevent "new"'s on this class

#ifdef _TARGET_X86_
    struct RetThunkCacheElement
    {
        RetThunkCacheElement()
        {
            LIMITED_METHOD_CONTRACT;
            m_cbStack = 0;
            m_pRetThunk = NULL;
        }

        UINT m_cbStack;
        LPVOID m_pRetThunk;
    };

    class RetThunkSHashTraits : public NoRemoveSHashTraits< DefaultSHashTraits<RetThunkCacheElement> >
    {
    public:
        typedef UINT key_t;
        static key_t GetKey(element_t e)       { LIMITED_METHOD_CONTRACT; return e.m_cbStack; }
        static BOOL Equals(key_t k1, key_t k2) { LIMITED_METHOD_CONTRACT; return (k1 == k2); }
        static count_t Hash(key_t k)           { LIMITED_METHOD_CONTRACT; return (count_t)(size_t)k; }
        static const element_t Null()          { LIMITED_METHOD_CONTRACT; return RetThunkCacheElement(); }
        static bool IsNull(const element_t &e) { LIMITED_METHOD_CONTRACT; return (e.m_pRetThunk == NULL); }
    };

    static SHash<RetThunkSHashTraits> *s_pRetThunkCache;
    static CrstStatic s_RetThunkCacheCrst;
#endif // _TARGET_X86_
};

#endif // __COMPLUSCALL_H__