summaryrefslogtreecommitdiff
path: root/src/binder/inc/assemblybinder.hpp
blob: fa2f8b409a08851ee05eecb1595cc44c5fb484ae (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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
// ============================================================
//
// AssemblyBinder.hpp
//


//
// Defines the AssemblyBinder class
//
// ============================================================

#ifndef __BINDER__ASSEMBLY_BINDER_HPP__
#define __BINDER__ASSEMBLY_BINDER_HPP__

#include "bindertypes.hpp"
#include "bindresult.hpp"
#include "coreclrbindercommon.h"

class CLRPrivBinderAssemblyLoadContext;
class CLRPrivBinderCoreCLR;

namespace BINDER_SPACE
{
    typedef enum
    {
        kBindingStoreGAC      = 0x01,
        kBindingStoreManifest = 0x02,
        kBindingStoreHost     = 0x04,
        kBindingStoreContext  = 0x08
    } BindingStore;

    class AssemblyBinder
    {
    public:
        static HRESULT Startup();

        // See code:BINDER_SPACE::AssemblyBinder::GetAssembly for info on fNgenExplicitBind
        // and fExplicitBindToNativeImage, and see code:CEECompileInfo::LoadAssemblyByPath
        // for an example of how they're used.
        static HRESULT BindAssembly(/* in */  ApplicationContext  *pApplicationContext,
                                    /* in */  AssemblyName        *pAssemblyName,
                                    /* in */  LPCWSTR              szCodeBase,
                                    /* in */  PEAssembly          *pParentAssembly,
                                    /* in */  BOOL                 fNgenExplicitBind,
                                    /* in */  BOOL                 fExplicitBindToNativeImage,
                                    /* in */  bool                 excludeAppPaths,
                                    /* out */ Assembly           **ppAssembly);

        static HRESULT BindToSystem(/* in */ SString    &systemDirectory,
                                    /* out */ Assembly **ppSystemAssembly,
                                    /* in */ bool fBindToNativeImage);

        static HRESULT BindToSystemSatellite(/* in */ SString   &systemDirectory,
                                             /* in */ SString   &simpleName,
                                             /* in */ SString   &cultureName,
                                             /* out */ Assembly **ppSystemAssembly);

        static HRESULT GetAssemblyFromImage(/* in */ PEImage    *pPEImage,
                                            /* in */ PEImage    *pNativePEImage,
                                            /* out */ Assembly **ppAssembly);

        // Special assembly binder entry point for byte arrays
        static HRESULT PreBindByteArray(/* in */  ApplicationContext *pApplicationContext,
                                        /* in */  PEImage            *pPEImage,
                                        /* in */  BOOL                fInspectionOnly);

        static HRESULT GetAssembly(/* in */  SString     &assemblyPath,
                                   /* in */  BOOL         fInspectionOnly,
                                   /* in */  BOOL         fIsInGAC,
                                   /* in */  BOOL         fExplicitBindToNativeImage,
                                   /* out */ Assembly   **ppAssembly,
                                   /* in */  LPCTSTR      szMDAssemblyPath = NULL);

#if !defined(DACCESS_COMPILE) && !defined(CROSSGEN_COMPILE)
        static HRESULT BindUsingHostAssemblyResolver (/* in */ INT_PTR pManagedAssemblyLoadContextToBindWithin,
                                                      /* in */ AssemblyName       *pAssemblyName,
                                                      /* in */ IAssemblyName      *pIAssemblyName,
                                                      /* in */ CLRPrivBinderCoreCLR *pTPABinder,
                                                      /* out */ Assembly           **ppAssembly);
                                                      
        static HRESULT BindUsingPEImage(/* in */  ApplicationContext *pApplicationContext,
                                        /* in */  BINDER_SPACE::AssemblyName *pAssemblyName,
                                        /* in */  PEImage            *pPEImage,
                                        /* in */  PEKIND              peKind,
                                        /* in */  IMDInternalImport  *pIMetaDataAssemblyImport, 
                                        /* [retval] [out] */  Assembly **ppAssembly);          
#endif // !defined(DACCESS_COMPILE) && !defined(CROSSGEN_COMPILE)
                                 
        static HRESULT TranslatePEToArchitectureType(DWORD  *pdwPAFlags, PEKIND *PeKind);
        
    protected:
        enum
        {
            BIND_NONE = 0x00,
            BIND_CACHE_FAILURES = 0x01,
            BIND_CACHE_RERUN_BIND = 0x02,
            BIND_IGNORE_DYNAMIC_BINDS = 0x04
#if !defined(DACCESS_COMPILE) && !defined(CROSSGEN_COMPILE)
            ,
            BIND_IGNORE_REFDEF_MATCH = 0x8
#endif // !defined(DACCESS_COMPILE) && !defined(CROSSGEN_COMPILE)
        };

        static BOOL IgnoreDynamicBinds(DWORD dwBindFlags)
        {
            return ((dwBindFlags & BIND_IGNORE_DYNAMIC_BINDS) != 0);
        }

        static BOOL CacheBindFailures(DWORD dwBindFlags)
        {
            return ((dwBindFlags & BIND_CACHE_FAILURES) != 0);
        }

        static BOOL RerunBind(DWORD dwBindFlags)
        {
            return ((dwBindFlags & BIND_CACHE_RERUN_BIND) != 0);
        }
        
#if !defined(DACCESS_COMPILE) && !defined(CROSSGEN_COMPILE)
        static BOOL IgnoreRefDefMatch(DWORD dwBindFlags)
        {
            return ((dwBindFlags & BIND_IGNORE_REFDEF_MATCH) != 0);
        }
#endif // !defined(DACCESS_COMPILE) && !defined(CROSSGEN_COMPILE)
        
        static HRESULT BindByName(/* in */  ApplicationContext *pApplicationContext,
                                  /* in */  AssemblyName       *pAssemblyName,
                                  /* in */  DWORD               dwBindFlags,
                                  /* in */  bool                excludeAppPaths,
                                  /* out */ BindResult         *pBindResult);

        // See code:BINDER_SPACE::AssemblyBinder::GetAssembly for info on fNgenExplicitBind
        // and fExplicitBindToNativeImage, and see code:CEECompileInfo::LoadAssemblyByPath
        // for an example of how they're used.
        static HRESULT BindWhereRef(/* in */  ApplicationContext *pApplicationContext,
                                    /* in */  PathString         &assemblyPath,
                                    /* in */  BOOL                fNgenExplicitBind,
                                    /* in */  BOOL                fExplicitBindToNativeImage,
                                    /* in */  bool                excludeAppPaths,
                                    /* out */ BindResult         *pBindResult);

        static HRESULT BindLocked(/* in */  ApplicationContext *pApplicationContext,
                                  /* in */  AssemblyName       *pAssemblyName,
                                  /* in */  DWORD               dwBindFlags,
                                  /* in */  bool                excludeAppPaths,
                                  /* out */ BindResult         *pBindResult);
        static HRESULT BindLockedOrService(/* in */  ApplicationContext *pApplicationContext,
                                           /* in */  AssemblyName       *pAssemblyName,
                                           /* in */  bool                excludeAppPaths,
                                           /* out */ BindResult         *pBindResult);

        static HRESULT FindInExecutionContext(/* in */  ApplicationContext  *pApplicationContext,
                                              /* in */  AssemblyName        *pAssemblyName,
                                              /* out */ ContextEntry       **ppContextEntry);

        static HRESULT BindByTpaList(/* in */  ApplicationContext  *pApplicationContext,
                                     /* in */  AssemblyName        *pRequestedAssemblyName,
                                     /* in */  BOOL                 fInspectionOnly,
                                     /* in */  bool                 excludeAppPaths,
                                     /* out */ BindResult          *pBindResult);
        
        static HRESULT Register(/* in */  ApplicationContext *pApplicationContext,
                                /* in */  BOOL                fInspectionOnly,
                                /* in */  BindResult         *pBindResult);
        static HRESULT RegisterAndGetHostChosen(/* in */  ApplicationContext *pApplicationContext,
                                                /* in */  LONG                kContextVersion,
                                                /* in */  BindResult         *pBindResult,
                                                /* out */ BindResult         *pHostBindResult);

        static HRESULT OtherBindInterfered(/* in */ ApplicationContext *pApplicationContext,
                                           /* in */ BindResult         *pBindResult);
    };
};

#endif