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
6
7#ifndef _RUNTIMEHANDLES_H_
8#define _RUNTIMEHANDLES_H_
9
10#include "object.h"
11#include "typehandle.h"
12#include "fcall.h"
13#include "field.h"
14#include "typectxt.h"
15
16typedef void* EnregisteredTypeHandle;
17class SignatureNative;
18
19// NOTE: These are defined in CallingConventions.cs.
20typedef enum ReflectionCallConv {
21 CALLCONV_Standard = 0x0001,
22 CALLCONV_VarArgs = 0x0002,
23 CALLCONV_Any = CALLCONV_Standard | CALLCONV_VarArgs,
24 CALLCONV_HasThis = 0x0020,
25 CALLCONV_ExplicitThis = 0x0040,
26 CALLCONV_ArgIteratorFlags = 0xFFFFFF00, // PRIVATE member -- cached ArgIterator flags -- Not exposed in CallingConventions.cs
27 CALLCONV_ArgIteratorFlags_Shift = 8,
28} ReflectionCallConv;
29
30
31// Types used to expose method bodies via reflection.
32
33class RuntimeExceptionHandlingClause;
34class RuntimeMethodBody;
35class RuntimeLocalVariableInfo;
36
37#ifdef USE_CHECKED_OBJECTREFS
38typedef REF<RuntimeExceptionHandlingClause> RUNTIMEEXCEPTIONHANDLINGCLAUSEREF;
39typedef REF<RuntimeMethodBody> RUNTIMEMETHODBODYREF;
40typedef REF<RuntimeLocalVariableInfo> RUNTIMELOCALVARIABLEINFOREF;
41#else
42typedef DPTR(RuntimeExceptionHandlingClause) RUNTIMEEXCEPTIONHANDLINGCLAUSEREF;
43typedef DPTR(RuntimeMethodBody) RUNTIMEMETHODBODYREF;
44typedef DPTR(RuntimeLocalVariableInfo) RUNTIMELOCALVARIABLEINFOREF;
45#endif
46
47class RuntimeExceptionHandlingClause : Object
48{
49private:
50 // Disallow creation and copy construction of these.
51 RuntimeExceptionHandlingClause() { }
52 RuntimeExceptionHandlingClause(RuntimeExceptionHandlingClause &r) { }
53
54public:
55 RUNTIMEMETHODBODYREF _methodBody;
56 CorExceptionFlag _flags;
57 INT32 _tryOffset;
58 INT32 _tryLength;
59 INT32 _handlerOffset;
60 INT32 _handlerLength;
61 mdTypeDef _catchToken;
62 INT32 _filterOffset;
63};
64
65class RuntimeMethodBody : Object
66{
67private:
68 // Disallow creation and copy construction of these.
69 RuntimeMethodBody() { }
70 RuntimeMethodBody(RuntimeMethodBody &r) { }
71
72public:
73 U1ARRAYREF _IL;
74 PTRARRAYREF _exceptionClauses;
75 PTRARRAYREF _localVariables;
76 OBJECTREF _methodBase;
77
78 INT32 _localVarSigToken;
79 INT32 _maxStackSize;
80 CLR_BOOL _initLocals;
81};
82
83class RuntimeLocalVariableInfo : Object
84{
85private:
86 // Disallow creation and copy construction of these.
87 RuntimeLocalVariableInfo() { }
88 RuntimeLocalVariableInfo(RuntimeLocalVariableInfo &r) { }
89
90public:
91
92 REFLECTCLASSBASEREF GetType()
93 {
94 return (REFLECTCLASSBASEREF)_type;
95 }
96
97 void SetType(OBJECTREF type)
98 {
99 SetObjectReference(&_type, type, GetAppDomain());
100 }
101
102 OBJECTREF _type;
103 INT32 _localIndex;
104 CLR_BOOL _isPinned;
105};
106
107class MdUtf8String {
108public:
109 static
110 BOOL QCALLTYPE EqualsCaseInsensitive(LPCUTF8 szLhs, LPCUTF8 szRhs, INT32 stringNumBytes);
111
112 static
113 ULONG QCALLTYPE HashCaseInsensitive(LPCUTF8 sz, INT32 stringNumBytes);
114};
115
116class RuntimeTypeHandle;
117
118typedef RuntimeTypeHandle FCALLRuntimeTypeHandle;
119#define FCALL_RTH_TO_REFLECTCLASS(x) (x).pRuntimeTypeDONOTUSEDIRECTLY
120
121class RuntimeTypeHandle {
122 ReflectClassBaseObject *pRuntimeTypeDONOTUSEDIRECTLY;
123public:
124
125 // Static method on RuntimeTypeHandle
126 static FCDECL1(Object*, Allocate, ReflectClassBaseObject *refType) ; //A.CI work
127 static FCDECL6(Object*, CreateInstance, ReflectClassBaseObject* refThisUNSAFE,
128 CLR_BOOL publicOnly,
129 CLR_BOOL wrapExceptions,
130 CLR_BOOL *pbCanBeCached,
131 MethodDesc** pConstructor,
132 CLR_BOOL *pbHasNoDefaultCtor);
133
134 static FCDECL2(Object*, CreateCaInstance, ReflectClassBaseObject* refCaType, ReflectMethodObject* pCtorUNSAFE);
135
136 static
137 void QCALLTYPE MakeByRef(EnregisteredTypeHandle pTypeHandle, QCall::ObjectHandleOnStack retType);
138
139 static
140 void QCALLTYPE MakePointer(EnregisteredTypeHandle pTypeHandle, QCall::ObjectHandleOnStack retType);
141
142 static
143 void QCALLTYPE MakeSZArray(EnregisteredTypeHandle pTypeHandle, QCall::ObjectHandleOnStack retType);
144
145 static
146 void QCALLTYPE MakeArray(EnregisteredTypeHandle pTypeHandle, INT32 rank, QCall::ObjectHandleOnStack retType);
147
148 static BOOL QCALLTYPE IsCollectible(EnregisteredTypeHandle pTypeHandle);
149
150 static FCDECL1(ReflectClassBaseObject*, GetRuntimeType, void *th);
151
152 static FCDECL1_V(ReflectClassBaseObject*, GetTypeFromHandle, FCALLRuntimeTypeHandle th);
153 static FCDECL1_V(EnregisteredTypeHandle, GetValueInternal, FCALLRuntimeTypeHandle RTH);
154
155 static FCDECL2(FC_BOOL_RET, TypeEQ, Object* left, Object* right);
156 static FCDECL2(FC_BOOL_RET, TypeNEQ, Object* left, Object* right);
157
158
159#ifdef FEATURE_COMINTEROP
160 static FCDECL1(FC_BOOL_RET, IsWindowsRuntimeObjectType, ReflectClassBaseObject *rtTypeUNSAFE);
161 static FCDECL1(FC_BOOL_RET, IsTypeExportedToWindowsRuntime, ReflectClassBaseObject *rtTypeUNSAFE);
162#endif // FEATURE_COMINTEROP
163
164 static
165 void QCALLTYPE PrepareMemberInfoCache(EnregisteredTypeHandle pMemberInfoCache);
166
167 static
168 void QCALLTYPE ConstructName(EnregisteredTypeHandle pTypeHandle, DWORD format, QCall::StringHandleOnStack retString);
169
170 static
171 void QCALLTYPE GetTypeByNameUsingCARules(LPCWSTR pwzClassName, QCall::ModuleHandle pModule, QCall::ObjectHandleOnStack retType);
172
173 static
174 void QCALLTYPE GetTypeByName(LPCWSTR pwzClassName, BOOL bThrowOnError, BOOL bIgnoreCase,
175 QCall::StackCrawlMarkHandle pStackMark,
176 ICLRPrivBinder * pPrivHostBinder,
177 BOOL bLoadTypeFromPartialNameHack, QCall::ObjectHandleOnStack retType,
178 QCall::ObjectHandleOnStack keepAlive);
179
180 static FCDECL1(AssemblyBaseObject*, GetAssembly, ReflectClassBaseObject *pType);
181 static FCDECL1(ReflectClassBaseObject*, GetBaseType, ReflectClassBaseObject* pType);
182 static FCDECL1(ReflectModuleBaseObject*, GetModule, ReflectClassBaseObject* pType);
183 static FCDECL1(INT32, GetAttributes, ReflectClassBaseObject* pType);
184 static FCDECL1(INT32, GetToken, ReflectClassBaseObject* pType);
185 static FCDECL1(LPCUTF8, GetUtf8Name, ReflectClassBaseObject* pType);
186 static FCDECL1(INT32, GetArrayRank, ReflectClassBaseObject* pType);
187
188 static FCDECL1(ReflectMethodObject*, GetDeclaringMethod, ReflectClassBaseObject *pType);
189
190 static
191 void QCALLTYPE GetDefaultConstructor(EnregisteredTypeHandle pTypeHandle, QCall::ObjectHandleOnStack retMethod);
192
193 static FCDECL1(ReflectClassBaseObject*, GetDeclaringType, ReflectClassBaseObject* pType);
194 static FCDECL1(FC_BOOL_RET, IsValueType, ReflectClassBaseObject* pType);
195 static FCDECL1(FC_BOOL_RET, IsInterface, ReflectClassBaseObject* pType);
196 static FCDECL1(FC_BOOL_RET, IsByRefLike, ReflectClassBaseObject* pType);
197
198 static
199 BOOL QCALLTYPE IsVisible(EnregisteredTypeHandle pTypeHandle);
200
201 static FCDECL2(FC_BOOL_RET, IsComObject, ReflectClassBaseObject *pType, CLR_BOOL isGenericCOM);
202 static FCDECL2(FC_BOOL_RET, CanCastTo, ReflectClassBaseObject *pType, ReflectClassBaseObject *pTarget);
203 static FCDECL2(FC_BOOL_RET, IsInstanceOfType, ReflectClassBaseObject *pType, Object *object);
204
205 static FCDECL6(FC_BOOL_RET, SatisfiesConstraints, PTR_ReflectClassBaseObject pGenericParameter, TypeHandle *typeContextArgs, INT32 typeContextCount, TypeHandle *methodContextArgs, INT32 methodContextCount, PTR_ReflectClassBaseObject pGenericArgument);
206 static
207 FCDECL1(FC_BOOL_RET, HasInstantiation, PTR_ReflectClassBaseObject pType);
208
209 static
210 FCDECL1(FC_BOOL_RET, IsGenericTypeDefinition, PTR_ReflectClassBaseObject pType);
211
212 static
213 FCDECL1(FC_BOOL_RET, IsGenericVariable, PTR_ReflectClassBaseObject pType);
214
215 static
216 FCDECL1(INT32, GetGenericVariableIndex, PTR_ReflectClassBaseObject pType);
217
218 static
219 FCDECL1(FC_BOOL_RET, ContainsGenericVariables, PTR_ReflectClassBaseObject pType);
220
221 static
222 void QCALLTYPE GetInstantiation(EnregisteredTypeHandle pTypeHandle, QCall::ObjectHandleOnStack retType, BOOL fAsRuntimeTypeArray);
223
224 static
225 void QCALLTYPE Instantiate(EnregisteredTypeHandle pTypeHandle, TypeHandle * pInstArray, INT32 cInstArray, QCall::ObjectHandleOnStack retType);
226
227 static
228 void QCALLTYPE GetGenericTypeDefinition(EnregisteredTypeHandle pTypeHandle, QCall::ObjectHandleOnStack retType);
229
230 static FCDECL2(FC_BOOL_RET, CompareCanonicalHandles, PTR_ReflectClassBaseObject pLeft, PTR_ReflectClassBaseObject pRight);
231
232 static FCDECL1(PtrArray*, GetInterfaces, ReflectClassBaseObject *pType);
233
234 static
235 void QCALLTYPE GetConstraints(EnregisteredTypeHandle pTypeHandle, QCall::ObjectHandleOnStack retTypes);
236
237 static
238 PVOID QCALLTYPE GetGCHandle(EnregisteredTypeHandle pTypeHandle, INT32 handleType);
239
240 static FCDECL1(INT32, GetCorElementType, PTR_ReflectClassBaseObject pType);
241 static FCDECL1(ReflectClassBaseObject*, GetElementType, ReflectClassBaseObject* pType);
242
243 static FCDECL2(MethodDesc*, GetMethodAt, PTR_ReflectClassBaseObject pType, INT32 slot);
244 static FCDECL1(INT32, GetNumVirtuals, ReflectClassBaseObject *pType);
245
246 static
247 void QCALLTYPE VerifyInterfaceIsImplemented(EnregisteredTypeHandle pTypeHandle, EnregisteredTypeHandle pIFaceHandle);
248
249 static
250 MethodDesc* QCALLTYPE GetInterfaceMethodImplementation(EnregisteredTypeHandle pTypeHandle, EnregisteredTypeHandle pOwner, MethodDesc * pMD);
251
252 static FCDECL3(FC_BOOL_RET, GetFields, ReflectClassBaseObject *pType, INT32 **result, INT32 *pCount);
253
254 static FCDECL1(MethodDesc *, GetFirstIntroducedMethod, ReflectClassBaseObject* pType);
255 static FCDECL1(void, GetNextIntroducedMethod, MethodDesc **ppMethod);
256
257 static FCDECL2(Object*, CreateInstanceForGenericType, ReflectClassBaseObject* pType
258 , ReflectClassBaseObject* parameterType );
259
260 static
261 FCDECL1(IMDInternalImport*, GetMetadataImport, ReflectClassBaseObject * pModuleUNSAFE);
262};
263
264class RuntimeMethodHandle {
265
266public:
267 static FCDECL1(ReflectMethodObject*, GetCurrentMethod, StackCrawlMark* stackMark);
268
269 static FCDECL5(Object*, InvokeMethod, Object *target, PTRArray *objs, SignatureNative* pSig, CLR_BOOL fConstructor, CLR_BOOL fWrapExceptions);
270
271 struct StreamingContextData {
272 Object * additionalContext; // additionalContex was changed from OBJECTREF to Object to avoid having a
273 INT32 contextStates; // constructor in this struct. GCC doesn't allow structs with constructors to be
274 };
275
276 // *******************************************************************************************
277 // Keep these in sync with the version in bcl\system\runtime\serialization\streamingcontext.cs
278 // *******************************************************************************************
279 enum StreamingContextStates
280 {
281 CONTEXTSTATE_CrossProcess = 0x01,
282 CONTEXTSTATE_CrossMachine = 0x02,
283 CONTEXTSTATE_File = 0x04,
284 CONTEXTSTATE_Persistence = 0x08,
285 CONTEXTSTATE_Remoting = 0x10,
286 CONTEXTSTATE_Other = 0x20,
287 CONTEXTSTATE_Clone = 0x40,
288 CONTEXTSTATE_CrossAppDomain = 0x80,
289 CONTEXTSTATE_All = 0xFF
290 };
291
292 // passed by value
293 // STATIC IMPLEMENTATION
294 static OBJECTREF InvokeMethod_Internal(
295 MethodDesc *pMethod, OBJECTREF targetUNSAFE, INT32 attrs, OBJECTREF binderUNSAFE, PTRARRAYREF objsUNSAFE, OBJECTREF localeUNSAFE,
296 BOOL isBinderDefault, Assembly *caller, Assembly *reflectedClassAssembly, TypeHandle declaringType, SignatureNative* pSig, BOOL verifyAccess);
297
298 static
299 BOOL QCALLTYPE IsCAVisibleFromDecoratedType(
300 EnregisteredTypeHandle targetTypeHandle,
301 MethodDesc * pTargetCtor,
302 EnregisteredTypeHandle sourceTypeHandle,
303 QCall::ModuleHandle sourceModuleHandle);
304
305 static FCDECL4(void, SerializationInvoke, ReflectMethodObject *pMethodUNSAFE, Object* targetUNSAFE,
306 Object* serializationInfoUNSAFE, struct StreamingContextData * pContext);
307
308 static
309 void QCALLTYPE ConstructInstantiation(MethodDesc * pMethod, DWORD format, QCall::StringHandleOnStack retString);
310
311 static
312 void * QCALLTYPE GetFunctionPointer(MethodDesc * pMethod);
313
314 static BOOL QCALLTYPE GetIsCollectible(MethodDesc * pMethod);
315
316 static FCDECL1(INT32, GetAttributes, MethodDesc *pMethod);
317 static FCDECL1(INT32, GetImplAttributes, ReflectMethodObject *pMethodUNSAFE);
318 static FCDECL1(ReflectClassBaseObject*, GetDeclaringType, MethodDesc *pMethod);
319 static FCDECL1(INT32, GetSlot, MethodDesc *pMethod);
320 static FCDECL1(INT32, GetMethodDef, ReflectMethodObject *pMethodUNSAFE);
321 static FCDECL1(StringObject*, GetName, MethodDesc *pMethod);
322 static FCDECL1(LPCUTF8, GetUtf8Name, MethodDesc *pMethod);
323 static FCDECL2(FC_BOOL_RET, MatchesNameHash, MethodDesc * pMethod, ULONG hash);
324
325 static
326 void QCALLTYPE GetMethodInstantiation(MethodDesc * pMethod, QCall::ObjectHandleOnStack retTypes, BOOL fAsRuntimeTypeArray);
327
328 static
329 FCDECL1(FC_BOOL_RET, HasMethodInstantiation, MethodDesc *pMethod);
330
331 static
332 FCDECL1(FC_BOOL_RET, IsGenericMethodDefinition, MethodDesc *pMethod);
333
334 static
335 FCDECL1(FC_BOOL_RET, IsTypicalMethodDefinition, ReflectMethodObject *pMethodUNSAFE);
336
337 static
338 void QCALLTYPE GetTypicalMethodDefinition(MethodDesc * pMethod, QCall::ObjectHandleOnStack refMethod);
339
340 static
341 void QCALLTYPE StripMethodInstantiation(MethodDesc * pMethod, QCall::ObjectHandleOnStack refMethod);
342
343 static
344 FCDECL1(INT32, GetGenericParameterCount, MethodDesc * pMethod);
345
346 // see comment in the cpp file
347 static FCDECL3(MethodDesc*, GetStubIfNeeded, MethodDesc *pMethod, ReflectClassBaseObject *pType, PtrArray* instArray);
348 static FCDECL2(MethodDesc*, GetMethodFromCanonical, MethodDesc *pMethod, PTR_ReflectClassBaseObject pType);
349
350 static
351 FCDECL1(FC_BOOL_RET, IsDynamicMethod, MethodDesc * pMethod);
352
353 static
354 FCDECL1(Object*, GetResolver, MethodDesc * pMethod);
355
356 static
357 void QCALLTYPE Destroy(MethodDesc * pMethod);
358
359 static
360 void QCALLTYPE GetCallerType(QCall::StackCrawlMarkHandle pStackMark, QCall::ObjectHandleOnStack retType);
361
362 static FCDECL2(RuntimeMethodBody*, GetMethodBody, ReflectMethodObject *pMethodUNSAFE, PTR_ReflectClassBaseObject pDeclaringType);
363
364 static FCDECL1(FC_BOOL_RET, IsConstructor, MethodDesc *pMethod);
365
366 static FCDECL1(Object*, GetLoaderAllocator, MethodDesc *pMethod);
367};
368
369class RuntimeFieldHandle {
370
371public:
372 static FCDECL5(Object*, GetValue, ReflectFieldObject *pFieldUNSAFE, Object *instanceUNSAFE, ReflectClassBaseObject *pFieldType, ReflectClassBaseObject *pDeclaringType, CLR_BOOL *pDomainInitialized);
373 static FCDECL7(void, SetValue, ReflectFieldObject *pFieldUNSAFE, Object *targetUNSAFE, Object *valueUNSAFE, ReflectClassBaseObject *pFieldType, DWORD attr, ReflectClassBaseObject *pDeclaringType, CLR_BOOL *pDomainInitialized);
374 static FCDECL4(Object*, GetValueDirect, ReflectFieldObject *pFieldUNSAFE, ReflectClassBaseObject *pFieldType, TypedByRef *pTarget, ReflectClassBaseObject *pDeclaringType);
375 static FCDECL5(void, SetValueDirect, ReflectFieldObject *pFieldUNSAFE, ReflectClassBaseObject *pFieldType, TypedByRef *pTarget, Object *valueUNSAFE, ReflectClassBaseObject *pContextType);
376 static FCDECL1(StringObject*, GetName, ReflectFieldObject *pFieldUNSAFE);
377 static FCDECL1(LPCUTF8, GetUtf8Name, FieldDesc *pField);
378 static FCDECL2(FC_BOOL_RET, MatchesNameHash, FieldDesc * pField, ULONG hash);
379
380 static FCDECL1(INT32, GetAttributes, FieldDesc *pField);
381 static FCDECL1(ReflectClassBaseObject*, GetApproxDeclaringType, FieldDesc *pField);
382 static FCDECL1(INT32, GetToken, ReflectFieldObject *pFieldUNSAFE);
383 static FCDECL2(FieldDesc*, GetStaticFieldForGenericType, FieldDesc *pField, ReflectClassBaseObject *pDeclaringType);
384 static FCDECL1(FC_BOOL_RET, AcquiresContextFromThis, FieldDesc *pField);
385};
386
387class ModuleHandle {
388
389public:
390 static FCDECL5(ReflectMethodObject*, GetDynamicMethod, ReflectMethodObject *pMethodUNSAFE, ReflectModuleBaseObject *pModuleUNSAFE, StringObject *name, U1Array *sig, Object *resolver);
391 static FCDECL1(INT32, GetToken, ReflectModuleBaseObject *pModuleUNSAFE);
392
393 static
394 void QCALLTYPE GetModuleType(QCall::ModuleHandle pModule, QCall::ObjectHandleOnStack retType);
395
396 static
397 FCDECL1(IMDInternalImport*, GetMetadataImport, ReflectModuleBaseObject * pModuleUNSAFE);
398
399 static
400 BOOL QCALLTYPE ContainsPropertyMatchingHash(QCall::ModuleHandle pModule, INT32 tkProperty, ULONG hash);
401
402 static
403 void QCALLTYPE ResolveType(QCall::ModuleHandle pModule, INT32 tkType, TypeHandle *typeArgs, INT32 typeArgsCount, TypeHandle *methodArgs, INT32 methodArgsCount, QCall::ObjectHandleOnStack retType);
404
405 static
406 MethodDesc * QCALLTYPE ResolveMethod(QCall::ModuleHandle pModule, INT32 tkMemberRef, TypeHandle *typeArgs, INT32 typeArgsCount, TypeHandle *methodArgs, INT32 methodArgsCount);
407
408 static
409 void QCALLTYPE ResolveField(QCall::ModuleHandle pModule, INT32 tkMemberRef, TypeHandle *typeArgs, INT32 typeArgsCount, TypeHandle *methodArgs, INT32 methodArgsCount, QCall::ObjectHandleOnStack retField);
410
411 static
412 void QCALLTYPE GetAssembly(QCall::ModuleHandle pModule, QCall::ObjectHandleOnStack retAssembly);
413
414 static
415 void QCALLTYPE GetPEKind(QCall::ModuleHandle pModule, DWORD* pdwPEKind, DWORD* pdwMachine);
416
417 static
418 FCDECL1(INT32, GetMDStreamVersion, ReflectModuleBaseObject * pModuleUNSAFE);
419};
420
421class AssemblyHandle {
422
423public:
424 static FCDECL1(ReflectModuleBaseObject*, GetManifestModule, AssemblyBaseObject *pAssemblyUNSAFE);
425
426 static FCDECL1(INT32, GetToken, AssemblyBaseObject *pAssemblyUNSAFE);
427};
428
429class SignatureNative;
430
431typedef DPTR(SignatureNative) PTR_SignatureNative;
432
433#ifdef USE_CHECKED_OBJECTREFS
434typedef REF<SignatureNative> SIGNATURENATIVEREF;
435#else
436typedef PTR_SignatureNative SIGNATURENATIVEREF;
437#endif
438
439class SignatureNative : public Object
440{
441 friend class RuntimeMethodHandle;
442 friend class ArgIteratorForMethodInvoke;
443
444public:
445 static FCDECL6(void, GetSignature,
446 SignatureNative* pSignatureNative,
447 PCCOR_SIGNATURE pCorSig, DWORD cCorSig,
448 FieldDesc *pFieldDesc, ReflectMethodObject *pMethodUNSAFE,
449 ReflectClassBaseObject *pDeclaringType);
450 static FCDECL3(Object *, GetCustomModifiers, SignatureNative* pSig, INT32 parameter, CLR_BOOL fRequired);
451 static FCDECL2(FC_BOOL_RET, CompareSig, SignatureNative* pLhs, SignatureNative* pRhs);
452 static FCDECL4(FC_BOOL_RET, CompareSigForAppCompat, SignatureNative* pLhs, ReflectClassBaseObject * pTypeLhs, SignatureNative* pRhs, ReflectClassBaseObject * pTypeRhs);
453
454
455 BOOL HasThis() { LIMITED_METHOD_CONTRACT; return (m_managedCallingConvention & CALLCONV_HasThis); }
456 INT32 NumFixedArgs() { WRAPPER_NO_CONTRACT; return m_PtrArrayarguments->GetNumComponents(); }
457 TypeHandle GetReturnTypeHandle()
458 {
459 CONTRACTL {
460 NOTHROW;
461 GC_NOTRIGGER;
462 MODE_COOPERATIVE;
463 }
464 CONTRACTL_END;
465
466 return ((REFLECTCLASSBASEREF)m_returnType)->GetType();
467 }
468
469 PCCOR_SIGNATURE GetCorSig() { LIMITED_METHOD_CONTRACT; return m_sig; }
470 DWORD GetCorSigSize() { LIMITED_METHOD_CONTRACT; return m_cSig; }
471 Module* GetModule() { WRAPPER_NO_CONTRACT; return GetDeclaringType().GetModule(); }
472
473 TypeHandle GetArgumentAt(INT32 position)
474 {
475 CONTRACTL {
476 NOTHROW;
477 GC_NOTRIGGER;
478 MODE_COOPERATIVE;
479 }
480 CONTRACTL_END;
481
482 REFLECTCLASSBASEREF refArgument = (REFLECTCLASSBASEREF)m_PtrArrayarguments->GetAt(position);
483 return refArgument->GetType();
484 }
485
486 DWORD GetArgIteratorFlags()
487 {
488 LIMITED_METHOD_CONTRACT;
489 return VolatileLoad(&m_managedCallingConvention) >> CALLCONV_ArgIteratorFlags_Shift;
490 }
491
492 INT32 GetSizeOfArgStack()
493 {
494 LIMITED_METHOD_CONTRACT;
495 return m_nSizeOfArgStack;
496 }
497
498 TypeHandle GetDeclaringType()
499 {
500 LIMITED_METHOD_CONTRACT;
501 return m_declaringType->GetType();
502 }
503 MethodDesc* GetMethod()
504 {
505 LIMITED_METHOD_CONTRACT;
506 return m_pMethod;
507 }
508
509 const SigTypeContext * GetTypeContext(SigTypeContext *pTypeContext)
510 {
511 CONTRACTL
512 {
513 NOTHROW;
514 GC_NOTRIGGER;
515 MODE_COOPERATIVE;
516 }
517 CONTRACTL_END;
518
519 _ASSERTE(m_pMethod || !GetDeclaringType().IsNull());
520 if (m_pMethod)
521 return SigTypeContext::GetOptionalTypeContext(m_pMethod, GetDeclaringType(), pTypeContext);
522 else
523 return SigTypeContext::GetOptionalTypeContext(GetDeclaringType(), pTypeContext);
524 }
525
526private:
527 void SetReturnType(OBJECTREF returnType)
528 {
529 CONTRACTL {
530 THROWS;
531 GC_TRIGGERS;
532 MODE_COOPERATIVE;
533 }
534 CONTRACTL_END;
535 SetObjectReference(&m_returnType, returnType, GetAppDomain());
536 }
537
538 void SetKeepAlive(OBJECTREF keepAlive)
539 {
540 CONTRACTL {
541 THROWS;
542 GC_TRIGGERS;
543 MODE_COOPERATIVE;
544 }
545 CONTRACTL_END;
546 SetObjectReference(&m_keepalive, keepAlive, GetAppDomain());
547 }
548
549 void SetDeclaringType(REFLECTCLASSBASEREF declaringType)
550 {
551 CONTRACTL {
552 THROWS;
553 GC_TRIGGERS;
554 MODE_COOPERATIVE;
555 }
556 CONTRACTL_END;
557 SetObjectReference((OBJECTREF*)&m_declaringType, (OBJECTREF)declaringType, GetAppDomain());
558 }
559
560 void SetArgumentArray(PTRARRAYREF ptrArrayarguments)
561 {
562 CONTRACTL {
563 THROWS;
564 GC_TRIGGERS;
565 MODE_COOPERATIVE;
566 }
567 CONTRACTL_END;
568 SetObjectReference((OBJECTREF*)&m_PtrArrayarguments, (OBJECTREF)ptrArrayarguments, GetAppDomain());
569 }
570
571 void SetArgument(INT32 argument, OBJECTREF argumentType)
572 {
573 CONTRACTL {
574 THROWS;
575 GC_TRIGGERS;
576 MODE_COOPERATIVE;
577 }
578 CONTRACTL_END;
579
580 m_PtrArrayarguments->SetAt(argument, argumentType);
581 }
582
583 void SetArgIteratorFlags(DWORD flags)
584 {
585 LIMITED_METHOD_CONTRACT;
586 return VolatileStore(&m_managedCallingConvention, (INT32)(m_managedCallingConvention | (flags << CALLCONV_ArgIteratorFlags_Shift)));
587 }
588
589 void SetSizeOfArgStack(INT32 nSizeOfArgStack)
590 {
591 LIMITED_METHOD_CONTRACT;
592 m_nSizeOfArgStack = nSizeOfArgStack;
593 }
594
595 void SetCallingConvention(INT32 mdCallingConvention)
596 {
597 LIMITED_METHOD_CONTRACT;
598
599 if ((mdCallingConvention & IMAGE_CEE_CS_CALLCONV_MASK) == IMAGE_CEE_CS_CALLCONV_VARARG)
600 m_managedCallingConvention = CALLCONV_VarArgs;
601 else
602 m_managedCallingConvention = CALLCONV_Standard;
603
604 if ((mdCallingConvention & IMAGE_CEE_CS_CALLCONV_HASTHIS) != 0)
605 m_managedCallingConvention |= CALLCONV_HasThis;
606
607 if ((mdCallingConvention & IMAGE_CEE_CS_CALLCONV_EXPLICITTHIS) != 0)
608 m_managedCallingConvention |= CALLCONV_ExplicitThis;
609 }
610
611 // Mirrored in the managed world (System.Signature)
612 //
613 // this is the layout the classloader chooses by default for the managed struct.
614 //
615 PTRARRAYREF m_PtrArrayarguments;
616 REFLECTCLASSBASEREF m_declaringType;
617 OBJECTREF m_returnType;
618 OBJECTREF m_keepalive;
619 PCCOR_SIGNATURE m_sig;
620 INT32 m_managedCallingConvention;
621 INT32 m_nSizeOfArgStack;
622 DWORD m_cSig;
623 MethodDesc* m_pMethod;
624};
625
626class ReflectionPointer : public Object
627{
628public:
629 OBJECTREF _ptrType;
630 void * _ptr;
631};
632
633#endif
634
635