summaryrefslogtreecommitdiff
path: root/src/vm/clsload.inl
blob: f2ba34bddb2fde953be1f69098a5a45af9719590 (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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
//
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//
//
// File: clsload.inl
//

//

//
// ============================================================================


#ifndef _CLSLOAD_INL_
#define _CLSLOAD_INL_

inline PTR_Assembly ClassLoader::GetAssembly()
{
    LIMITED_METHOD_CONTRACT;
    SUPPORTS_DAC;
    return m_pAssembly;
}

inline PTR_Module ClassLoader::ComputeLoaderModuleForFunctionPointer(TypeHandle* pRetAndArgTypes, DWORD NumArgsPlusRetType) 
{
    CONTRACTL
    {
        NOTHROW;
        GC_NOTRIGGER;
        MODE_ANY;
        SUPPORTS_DAC;
    }
    CONTRACTL_END;
    return ComputeLoaderModuleWorker(NULL,
                               0,
                               Instantiation(pRetAndArgTypes, NumArgsPlusRetType),
                               Instantiation());
}

inline PTR_Module ClassLoader::ComputeLoaderModuleForParamType(TypeHandle paramType)
{
    CONTRACTL
    {
        NOTHROW;
        GC_NOTRIGGER;
        MODE_ANY;
        SUPPORTS_DAC;
    }
    CONTRACTL_END;

    //
    // Call GetLoaderModule directly instead of ComputeLoaderModuleWorker to avoid exponential recursion for collectible types
    //
    // It is safe to do it even during NGen because of we do not create duplicate copies of arrays and other param types 
    // (see code:CEEPreloader::TriageTypeForZap).
    //
    return paramType.GetLoaderModule();
}

//******************************************************************************

inline void AccessCheckOptions::Initialize(
    AccessCheckType      accessCheckType,
    BOOL                 throwIfTargetIsInaccessible,
    MethodTable *        pTargetMT,
    MethodDesc *         pTargetMethod, 
    FieldDesc *          pTargetField,
    BOOL                 skipCheckForCriticalCode /*=FALSE*/)
{
    CONTRACTL 
    {
        SO_TOLERANT;
        THROWS;
        GC_TRIGGERS;
        MODE_ANY;
        // At most one of these can be non-NULL. They can all be NULL if:
        //   1. we are doing a normal accessibility check, or
        //   2. we are not going to throw an exception if the accessibility check fails
        PRECONDITION(accessCheckType == kNormalAccessibilityChecks || 
                     !throwIfTargetIsInaccessible ||
                     ((pTargetMT ? 1 : 0) + (pTargetMethod ? 1 : 0) + (pTargetField ? 1 : 0)) == 1);
        // m_pAccessContext can only be set for kRestrictedMemberAccess
#ifdef FEATURE_CORECLR
        PRECONDITION(m_pAccessContext == NULL || 
                     accessCheckType == AccessCheckOptions::kRestrictedMemberAccess);
#else
        PRECONDITION(m_pAccessContext == NULL || 
                     accessCheckType == AccessCheckOptions::kUserCodeOnlyRestrictedMemberAccess ||
                     accessCheckType == AccessCheckOptions::kRestrictedMemberAccess);
#endif
    }
    CONTRACTL_END;

    m_accessCheckType = accessCheckType;
    m_fThrowIfTargetIsInaccessible = throwIfTargetIsInaccessible;
    m_pTargetMT = pTargetMT;
    m_pTargetMethod = pTargetMethod; 
    m_pTargetField = pTargetField;
    m_fSkipCheckForCriticalCode = skipCheckForCriticalCode;
}

//******************************************************************************

inline AccessCheckOptions::AccessCheckOptions(
    AccessCheckType      accessCheckType,
    DynamicResolver *    pAccessContext,
    BOOL                 throwIfTargetIsInaccessible,
    MethodTable *        pTargetMT) : 
    m_pAccessContext(pAccessContext)
{
    WRAPPER_NO_CONTRACT;

    Initialize(
        accessCheckType,
        throwIfTargetIsInaccessible,
        pTargetMT,
        NULL, 
        NULL);
}

inline AccessCheckOptions::AccessCheckOptions(
    AccessCheckType      accessCheckType,
    DynamicResolver *    pAccessContext,
    BOOL                 throwIfTargetIsInaccessible,
    MethodDesc *         pTargetMethod) :
    m_pAccessContext(pAccessContext)
{
    WRAPPER_NO_CONTRACT;

    Initialize(
        accessCheckType,
        throwIfTargetIsInaccessible,
        NULL,
        pTargetMethod, 
        NULL);
}

inline AccessCheckOptions::AccessCheckOptions(
    AccessCheckType      accessCheckType,
    DynamicResolver *    pAccessContext,
    BOOL                 throwIfTargetIsInaccessible,
    FieldDesc *          pTargetField) :
    m_pAccessContext(pAccessContext)
{
    WRAPPER_NO_CONTRACT;

    Initialize(
        accessCheckType,
        throwIfTargetIsInaccessible,
        NULL,
        NULL, 
        pTargetField);
}

#endif  // _CLSLOAD_INL_