Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
DynamicResolver.cs
Go to the documentation of this file.
2
3internal sealed class DynamicResolver : Resolver
4{
5 private sealed class DestroyScout
6 {
8
10 {
12 {
14 {
16 }
17 else
18 {
20 }
21 }
22 }
23 }
24
25 [Flags]
34
36
37 private byte[] m_exceptionHeader;
38
40
41 private byte[] m_code;
42
43 private byte[] m_localSignature;
44
45 private int m_stackSize;
46
48
49 internal DynamicResolver(DynamicILGenerator ilGenerator)
50 {
51 m_stackSize = ilGenerator.GetMaxStackSize();
52 m_exceptions = ilGenerator.GetExceptions();
53 m_code = ilGenerator.BakeByteArray();
55 m_scope = ilGenerator.m_scope;
57 m_method.m_resolver = this;
58 }
59
60 internal DynamicResolver(DynamicILInfo dynamicILInfo)
61 {
62 m_stackSize = dynamicILInfo.MaxStackSize;
63 m_code = dynamicILInfo.Code;
64 m_localSignature = dynamicILInfo.LocalSignature;
65 m_exceptionHeader = dynamicILInfo.Exceptions;
66 m_scope = dynamicILInfo.DynamicScope;
67 m_method = dynamicILInfo.DynamicMethod;
68 m_method.m_resolver = this;
69 }
70
72 {
73 DynamicMethod method = m_method;
74 if (!(method == null) && method.m_methodHandle != null)
75 {
76 DestroyScout destroyScout;
77 try
78 {
79 destroyScout = new DestroyScout();
80 }
81 catch
82 {
84 return;
85 }
86 destroyScout.m_methodHandle = method.m_methodHandle.Value;
87 }
88 }
89
90 internal override RuntimeType GetJitContext(out int securityControlFlags)
91 {
92 SecurityControlFlags securityControlFlags2 = SecurityControlFlags.Default;
94 {
95 securityControlFlags2 |= SecurityControlFlags.RestrictedSkipVisibilityChecks;
96 }
98 {
99 securityControlFlags2 |= SecurityControlFlags.SkipVisibilityChecks;
100 }
101 RuntimeType typeOwner = m_method.m_typeOwner;
102 securityControlFlags = (int)securityControlFlags2;
103 return typeOwner;
104 }
105
107 {
108 int num = 0;
109 if (excp == null)
110 {
111 return 0;
112 }
113 for (int i = 0; i < excp.Length; i++)
114 {
115 num += excp[i].GetNumberOfCatches();
116 }
117 return num;
118 }
119
120 internal override byte[] GetCodeInfo(out int stackSize, out int initLocals, out int EHCount)
121 {
122 stackSize = m_stackSize;
123 if (m_exceptionHeader != null && m_exceptionHeader.Length != 0)
124 {
125 if (m_exceptionHeader.Length < 4)
126 {
127 throw new FormatException();
128 }
129 byte b = m_exceptionHeader[0];
130 if ((b & 0x40u) != 0)
131 {
132 int num = m_exceptionHeader[3] << 16;
133 num |= m_exceptionHeader[2] << 8;
134 num |= m_exceptionHeader[1];
135 EHCount = (num - 4) / 24;
136 }
137 else
138 {
139 EHCount = (m_exceptionHeader[1] - 2) / 12;
140 }
141 }
142 else
143 {
145 }
146 initLocals = (m_method.InitLocals ? 1 : 0);
147 return m_code;
148 }
149
150 internal override byte[] GetLocalsSignature()
151 {
152 return m_localSignature;
153 }
154
155 internal override byte[] GetRawEHInfo()
156 {
157 return m_exceptionHeader;
158 }
159
160 internal unsafe override void GetEHInfo(int excNumber, void* exc)
161 {
162 for (int i = 0; i < m_exceptions.Length; i++)
163 {
164 int numberOfCatches = m_exceptions[i].GetNumberOfCatches();
165 if (excNumber < numberOfCatches)
166 {
167 ((CORINFO_EH_CLAUSE*)exc)->Flags = m_exceptions[i].GetExceptionTypes()[excNumber];
168 ((CORINFO_EH_CLAUSE*)exc)->TryOffset = m_exceptions[i].GetStartAddress();
169 if ((((CORINFO_EH_CLAUSE*)exc)->Flags & 2) != 2)
170 {
171 ((CORINFO_EH_CLAUSE*)exc)->TryLength = m_exceptions[i].GetEndAddress() - ((CORINFO_EH_CLAUSE*)exc)->TryOffset;
172 }
173 else
174 {
175 ((CORINFO_EH_CLAUSE*)exc)->TryLength = m_exceptions[i].GetFinallyEndAddress() - ((CORINFO_EH_CLAUSE*)exc)->TryOffset;
176 }
177 ((CORINFO_EH_CLAUSE*)exc)->HandlerOffset = m_exceptions[i].GetCatchAddresses()[excNumber];
178 ((CORINFO_EH_CLAUSE*)exc)->HandlerLength = m_exceptions[i].GetCatchEndAddresses()[excNumber] - ((CORINFO_EH_CLAUSE*)exc)->HandlerOffset;
179 ((CORINFO_EH_CLAUSE*)exc)->ClassTokenOrFilterOffset = m_exceptions[i].GetFilterAddresses()[excNumber];
180 break;
181 }
182 excNumber -= numberOfCatches;
183 }
184 }
185
186 internal override string GetStringLiteral(int token)
187 {
188 return m_scope.GetString(token);
189 }
190
191 internal override void ResolveToken(int token, out IntPtr typeHandle, out IntPtr methodHandle, out IntPtr fieldHandle)
192 {
193 typeHandle = default(IntPtr);
194 methodHandle = default(IntPtr);
195 fieldHandle = default(IntPtr);
196 object obj = m_scope[token];
197 if (obj == null)
198 {
199 throw new InvalidProgramException();
200 }
201 if (obj is RuntimeTypeHandle)
202 {
203 typeHandle = ((RuntimeTypeHandle)obj).Value;
204 return;
205 }
207 {
208 methodHandle = ((RuntimeMethodHandle)obj).Value;
209 return;
210 }
211 if (obj is RuntimeFieldHandle)
212 {
213 fieldHandle = ((RuntimeFieldHandle)obj).Value;
214 return;
215 }
216 DynamicMethod dynamicMethod = obj as DynamicMethod;
217 if (dynamicMethod != null)
218 {
219 methodHandle = dynamicMethod.GetMethodDescriptor().Value;
220 }
221 else if (obj is GenericMethodInfo genericMethodInfo)
222 {
223 methodHandle = genericMethodInfo.m_methodHandle.Value;
224 typeHandle = genericMethodInfo.m_context.Value;
225 }
226 else if (obj is GenericFieldInfo genericFieldInfo)
227 {
228 fieldHandle = genericFieldInfo.m_fieldHandle.Value;
229 typeHandle = genericFieldInfo.m_context.Value;
230 }
231 else if (obj is VarArgMethod varArgMethod)
232 {
233 if (varArgMethod.m_dynamicMethod == null)
234 {
235 methodHandle = varArgMethod.m_method.MethodHandle.Value;
236 typeHandle = varArgMethod.m_method.GetDeclaringTypeInternal().GetTypeHandleInternal().Value;
237 }
238 else
239 {
240 methodHandle = varArgMethod.m_dynamicMethod.GetMethodDescriptor().Value;
241 }
242 }
243 }
244
245 internal override byte[] ResolveSignature(int token, int fromMethod)
246 {
247 return m_scope.ResolveSignature(token, fromMethod);
248 }
249
250 internal override MethodInfo GetDynamicMethod()
251 {
252 return m_method.GetMethodInfo();
253 }
254}
static void ReRegisterForFinalize(object obj)
Definition GC.cs:214
Definition GC.cs:8
RuntimeMethodHandle GetMethodDescriptor()
DynamicResolver(DynamicILGenerator ilGenerator)
override string GetStringLiteral(int token)
override void ResolveToken(int token, out IntPtr typeHandle, out IntPtr methodHandle, out IntPtr fieldHandle)
override byte[] GetCodeInfo(out int stackSize, out int initLocals, out int EHCount)
static int CalculateNumberOfExceptions(__ExceptionInfo[] excp)
DynamicResolver(DynamicILInfo dynamicILInfo)
override RuntimeType GetJitContext(out int securityControlFlags)
override byte[] ResolveSignature(int token, int fromMethod)
unsafe override void GetEHInfo(int excNumber, void *exc)
byte[] ResolveSignature(int token, int fromMethod)
__ExceptionInfo[] GetExceptions()
RuntimeMethodHandleInternal Value
static Resolver GetResolver(RuntimeMethodHandleInternal method)
static void Destroy(RuntimeMethodHandleInternal method)