1// Licensed to the .NET Foundation under one or more agreements.
2// The .NET Foundation licenses this file to you under the MIT license.
3// See the LICENSE file in the project root for more information.
4//
5// File: ILStubResolver.h
6//
7
8//
9
10
11#ifndef __ILSTUBRESOLVER_H__
12#define __ILSTUBRESOLVER_H__
13
14#include "stubgen.h"
15class ILStubResolver : DynamicResolver
16{
17 friend class ILStubCache;
18 friend class ILStubLinker;
19
20public:
21
22 // -----------------------------------
23 // DynamicResolver interface methods
24 // -----------------------------------
25
26 void FreeCompileTimeState();
27 void GetJitContext(SecurityControlFlags* pSecurityControlFlags,
28 TypeHandle* pTypeOwner);
29 ChunkAllocator* GetJitMetaHeap();
30
31 BYTE* GetCodeInfo(unsigned* pCodeSize, unsigned* pStackSize, CorInfoOptions* pOptions, unsigned* pEHSize);
32 SigPointer GetLocalSig();
33
34 OBJECTHANDLE ConstructStringLiteral(mdToken metaTok);
35 BOOL IsValidStringRef(mdToken metaTok);
36 void ResolveToken(mdToken token, TypeHandle * pTH, MethodDesc ** ppMD, FieldDesc ** ppFD);
37 SigPointer ResolveSignature(mdToken token);
38 SigPointer ResolveSignatureForVarArg(mdToken token);
39 void GetEHInfo(unsigned EHnumber, CORINFO_EH_CLAUSE* clause);
40
41 static LPCUTF8 GetStubClassName(MethodDesc* pMD);
42 LPCUTF8 GetStubMethodName();
43
44 MethodDesc* GetDynamicMethod() { LIMITED_METHOD_CONTRACT; return m_pStubMD; }
45
46 // -----------------------------------
47 // ILStubResolver-specific methods
48 // -----------------------------------
49 bool IsNativeToCLRInteropStub();
50 MethodDesc* GetStubMethodDesc();
51 MethodDesc* GetStubTargetMethodDesc();
52 void SetStubTargetMethodDesc(MethodDesc* pStubTargetMD);
53 void SetStubTargetMethodSig(PCCOR_SIGNATURE pStubTargetMethodSig, DWORD cbStubTargetSigLength);
54 void SetStubMethodDesc(MethodDesc* pStubMD);
55
56 COR_ILMETHOD_DECODER * AllocGeneratedIL(size_t cbCode, DWORD cbLocalSig, UINT maxStack);
57 COR_ILMETHOD_DECODER * GetILHeader();
58 COR_ILMETHOD_SECT_EH* AllocEHSect(size_t nClauses);
59
60 bool IsCompiled();
61 bool IsILGenerated();
62
63 ILStubResolver();
64
65 void SetTokenLookupMap(TokenLookupMap* pMap);
66
67 void SetJitFlags(CORJIT_FLAGS jitFlags);
68 CORJIT_FLAGS GetJitFlags();
69
70 static void StubGenFailed(ILStubResolver* pResolver);
71
72protected:
73 enum ILStubType
74 {
75 Unassigned = 0,
76 CLRToNativeInteropStub,
77 CLRToCOMInteropStub,
78 CLRToWinRTInteropStub,
79 NativeToCLRInteropStub,
80 COMToCLRInteropStub,
81 WinRTToCLRInteropStub,
82#ifdef FEATURE_ARRAYSTUB_AS_IL
83 ArrayOpStub,
84#endif
85#ifdef FEATURE_MULTICASTSTUB_AS_IL
86 MulticastDelegateStub,
87#endif
88#ifdef FEATURE_STUBS_AS_IL
89 SecureDelegateStub,
90 UnboxingILStub,
91 InstantiatingStub,
92#endif
93 };
94
95 enum CompileTimeStatePtrSpecialValues
96 {
97 ILNotYetGenerated = NULL,
98 ILGeneratedAndFreed = 1,
99 };
100
101 void ClearCompileTimeState(CompileTimeStatePtrSpecialValues newState);
102 void SetStubType(ILStubType stubType);
103
104 //
105 // This stuff is only needed during JIT
106 //
107 struct CompileTimeState
108 {
109 COR_ILMETHOD_DECODER m_ILHeader;
110 COR_ILMETHOD_SECT_EH * m_pEHSect;
111 SigPointer m_StubTargetMethodSig;
112 TokenLookupMap m_tokenLookupMap;
113 };
114 typedef DPTR(struct CompileTimeState) PTR_CompileTimeState;
115
116 PTR_CompileTimeState m_pCompileTimeState;
117
118 PTR_MethodDesc m_pStubMD;
119 PTR_MethodDesc m_pStubTargetMD;
120 ILStubType m_type;
121 CORJIT_FLAGS m_jitFlags;
122};
123
124typedef Holder<ILStubResolver*, DoNothing<ILStubResolver*>, ILStubResolver::StubGenFailed, NULL> ILStubGenHolder;
125
126
127#endif // __ILSTUBRESOLVER_H__
128