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
8#ifndef _REFLECTIONINVOCATION_H_
9#define _REFLECTIONINVOCATION_H_
10
11#include "object.h"
12#include "fcall.h"
13#include "field.h"
14#include "stackwalktypes.h"
15#include "runtimehandles.h"
16#include "invokeutil.h"
17
18// NOTE: The following constants are defined in BindingFlags.cs
19#define BINDER_IgnoreCase 0x01
20#define BINDER_DeclaredOnly 0x02
21#define BINDER_Instance 0x04
22#define BINDER_Static 0x08
23#define BINDER_Public 0x10
24#define BINDER_NonPublic 0x20
25#define BINDER_FlattenHierarchy 0x40
26
27#define BINDER_InvokeMethod 0x00100
28#define BINDER_CreateInstance 0x00200
29#define BINDER_GetField 0x00400
30#define BINDER_SetField 0x00800
31#define BINDER_GetProperty 0x01000
32#define BINDER_SetProperty 0x02000
33#define BINDER_PutDispProperty 0x04000
34#define BINDER_PutRefDispProperty 0x08000
35
36#define BINDER_ExactBinding 0x010000
37#define BINDER_SuppressChangeType 0x020000
38#define BINDER_OptionalParamBinding 0x040000
39
40#define BINDER_IgnoreReturn 0x1000000
41#define BINDER_DoNotWrapExceptions 0x2000000
42
43#define BINDER_DefaultLookup (BINDER_Instance | BINDER_Static | BINDER_Public)
44#define BINDER_AllLookup (BINDER_Instance | BINDER_Static | BINDER_Public | BINDER_Instance)
45
46class ReflectionInvocation {
47
48public:
49 static
50 void QCALLTYPE CompileMethod(MethodDesc * pMD);
51
52 static FCDECL1(void, RunClassConstructor, ReflectClassBaseObject *pTypeUNSAFE);
53 static FCDECL1(void, RunModuleConstructor, ReflectModuleBaseObject *pModuleUNSAFE);
54 static FCDECL3(void, PrepareMethod, ReflectMethodObject* pMethodUNSAFE, TypeHandle *pInstantiation, UINT32 cInstantiation);
55 static FCDECL1(void, PrepareDelegate, Object* delegateUNSAFE);
56 static FCDECL1(void, PrepareContractedDelegate, Object* delegateUNSAFE);
57 static FCDECL0(void, ProbeForSufficientStack);
58 static FCDECL0(void, EnsureSufficientExecutionStack);
59 static FCDECL0(FC_BOOL_RET, TryEnsureSufficientExecutionStack);
60 static FCDECL3(void, ExecuteCodeWithGuaranteedCleanup, Object* pCodeDelegateUNSAFE, Object* pBackoutDelegateUNSAFE, Object* pUserDataUNSAFE);
61
62 // TypedReference functions, should go somewhere else
63 static FCDECL4(void, MakeTypedReference, TypedByRef * value, Object* targetUNSAFE, ArrayBase* fldsUNSAFE, ReflectClassBaseObject *pFieldType);
64 static FCDECL2(void, SetTypedReference, TypedByRef * target, Object* objUNSAFE);
65 static FCDECL1(Object*, TypedReferenceToObject, TypedByRef * value);
66
67#ifdef FEATURE_COMINTEROP
68 static FCDECL3(Object*, GetClassFromProgID, StringObject* classNameUNSAFE, StringObject* serverUNSAFE, CLR_BOOL bThrowOnError);
69 static FCDECL3(Object*, GetClassFromCLSID, GUID clsid, StringObject* serverUNSAFE, CLR_BOOL bThrowOnError);
70 static FCDECL8(Object*, InvokeDispMethod, ReflectClassBaseObject* refThisUNSAFE, StringObject* nameUNSAFE, INT32 invokeAttr, Object* targetUNSAFE, PTRArray* argsUNSAFE, PTRArray* byrefModifiersUNSAFE, LCID lcid, PTRArray* namedParametersUNSAFE);
71#endif // FEATURE_COMINTEROP
72 static FCDECL2(void, GetGUID, ReflectClassBaseObject* refThisUNSAFE, GUID * result);
73 static FCDECL2_IV(Object*, CreateEnum, ReflectClassBaseObject *pTypeUNSAFE, INT64 value);
74
75 // helper fcalls for invocation
76 static FCDECL2(FC_BOOL_RET, CanValueSpecialCast, ReflectClassBaseObject *valueType, ReflectClassBaseObject *targetType);
77 static FCDECL3(Object*, AllocateValueType, ReflectClassBaseObject *targetType, Object *valueUNSAFE, CLR_BOOL fForceTypeChange);
78
79 static FCDECL4(void, PerformSecurityCheck, Object *target, MethodDesc *pMeth, ReflectClassBaseObject *pParent, DWORD dwFlags);
80 static FCDECL2(void, CheckArgs, PTRArray *objs, SignatureNative sig);
81
82 static void PrepareDelegateHelper(OBJECTREF* pDelegate, BOOL onlyContractedMethod);
83 static void CanCacheTargetAndCrackedSig(MethodDesc* pMD);
84};
85
86class ReflectionSerialization {
87public:
88 static FCDECL1(Object*, GetUninitializedObject, ReflectClassBaseObject* objTypeUNSAFE);
89};
90
91class ReflectionEnum {
92public:
93 static FCDECL1(Object *, InternalGetEnumUnderlyingType, ReflectClassBaseObject *target);
94 static FCDECL1(INT32, InternalGetCorElementType, Object *pRefThis);
95
96 static
97 void QCALLTYPE GetEnumValuesAndNames(EnregisteredTypeHandle pEnumType, QCall::ObjectHandleOnStack pReturnValues, QCall::ObjectHandleOnStack pReturnNames, BOOL fGetNames);
98
99 static FCDECL2_IV(Object*, InternalBoxEnum, ReflectClassBaseObject* pEnumType, INT64 value);
100 static FCDECL2(FC_BOOL_RET, InternalEquals, Object *pRefThis, Object* pRefTarget);
101 static FCDECL2(FC_BOOL_RET, InternalHasFlag, Object *pRefThis, Object* pRefFlags);
102 static FCDECL2(int, InternalCompareTo, Object *pRefThis, Object* pRefTarget);
103};
104
105class ReflectionBinder {
106public:
107 static FCDECL2(FC_BOOL_RET, DBCanConvertPrimitive, ReflectClassBaseObject* vSource, ReflectClassBaseObject* vTarget);
108 static FCDECL2(FC_BOOL_RET, DBCanConvertObjectPrimitive, Object* vSourceObj, ReflectClassBaseObject* vTarget);
109
110
111};
112
113#endif // _REFLECTIONINVOCATION_H_
114