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 // ============================================================
6 // ApplicationContext.hpp
11 // Defines the ApplicationContext class
13 // ============================================================
15 #ifndef __BINDER__APPLICATION_CONTEXT_HPP__
16 #define __BINDER__APPLICATION_CONTEXT_HPP__
18 #include "bindertypes.hpp"
19 #include "failurecache.hpp"
20 #include "assemblyidentitycache.hpp"
21 #ifdef FEATURE_VERSIONING_LOG
22 #include "bindinglog.hpp"
23 #endif // FEATURE_VERSIONING_LOG
24 #include "stringarraylist.h"
26 namespace BINDER_SPACE
28 //=============================================================================================
29 // Data structures for Simple Name -> File Name hash
30 struct FileNameMapEntry
35 class FileNameHashTraits : public NoRemoveSHashTraits< DefaultSHashTraits< FileNameMapEntry > >
39 static const FileNameMapEntry Null() { FileNameMapEntry e; e.m_wszFileName = nullptr; return e; }
40 static bool IsNull(const FileNameMapEntry & e) { return e.m_wszFileName == nullptr; }
41 static const key_t GetKey(const FileNameMapEntry & e)
44 key = e.m_wszFileName;
47 static count_t Hash(const key_t &str) { return HashiString(str); }
48 static BOOL Equals(const key_t &lhs, const key_t &rhs) { LIMITED_METHOD_CONTRACT; return (_wcsicmp(lhs, rhs) == 0); }
51 typedef SHash<FileNameHashTraits> TpaFileNameHash;
53 // Entry in SHash table that maps namespace to list of files
54 struct SimpleNameToFileNameMapEntry
56 LPWSTR m_wszSimpleName;
57 LPWSTR m_wszILFileName;
58 LPWSTR m_wszNIFileName;
61 // SHash traits for Namespace -> FileNameList hash
62 class SimpleNameToFileNameMapTraits : public NoRemoveSHashTraits< DefaultSHashTraits< SimpleNameToFileNameMapEntry > >
66 static const SimpleNameToFileNameMapEntry Null() { SimpleNameToFileNameMapEntry e; e.m_wszSimpleName = nullptr; return e; }
67 static bool IsNull(const SimpleNameToFileNameMapEntry & e) { return e.m_wszSimpleName == nullptr; }
68 static const key_t GetKey(const SimpleNameToFileNameMapEntry & e)
71 key = e.m_wszSimpleName;
74 static count_t Hash(const key_t &str) { return HashiString(str); }
75 static BOOL Equals(const key_t &lhs, const key_t &rhs) { LIMITED_METHOD_CONTRACT; return (_wcsicmp(lhs, rhs) == 0); }
77 void OnDestructPerEntryCleanupAction(const SimpleNameToFileNameMapEntry & e)
79 if (e.m_wszILFileName == nullptr && e.m_wszNIFileName == nullptr)
81 // Don't delete simple name here since it's a filename only entry and will be cleaned up
82 // by the SimpleName -> FileName entry which reuses the same filename pointer.
86 if (e.m_wszSimpleName != nullptr)
88 delete [] e.m_wszSimpleName;
90 if (e.m_wszILFileName != nullptr)
92 delete [] e.m_wszILFileName;
94 if (e.m_wszNIFileName != nullptr)
96 delete [] e.m_wszNIFileName;
99 static const bool s_DestructPerEntryCleanupAction = true;
102 typedef SHash<SimpleNameToFileNameMapTraits> SimpleNameToFileNameMap;
104 class ApplicationContext
109 STDMETHOD(QueryInterface)(REFIID riid,
111 STDMETHOD_(ULONG, AddRef)();
112 STDMETHOD_(ULONG, Release)();
114 // ApplicationContext methods
115 ApplicationContext();
116 virtual ~ApplicationContext();
119 inline SString &GetApplicationName();
120 inline DWORD GetAppDomainId();
121 inline void SetAppDomainId(DWORD dwAppDomainId);
123 HRESULT SetupBindingPaths(/* in */ SString &sTrustedPlatformAssemblies,
124 /* in */ SString &sPlatformResourceRoots,
125 /* in */ SString &sAppPaths,
126 /* in */ SString &sAppNiPaths,
127 /* in */ BOOL fAcquireLock);
129 HRESULT GetAssemblyIdentity(/* in */ LPCSTR szTextualIdentity,
130 /* in */ AssemblyIdentityUTF8 **ppAssemblyIdentity);
133 inline ExecutionContext *GetExecutionContext();
134 inline InspectionContext *GetInspectionContext();
135 inline FailureCache *GetFailureCache();
136 inline HRESULT AddToFailureCache(SString &assemblyNameOrPath,
137 HRESULT hrBindResult);
138 inline StringArrayList *GetAppPaths();
139 inline SimpleNameToFileNameMap *GetTpaList();
140 inline TpaFileNameHash *GetTpaFileNameList();
141 inline StringArrayList *GetPlatformResourceRoots();
142 inline StringArrayList *GetAppNiPaths();
144 // Using a host-configured Trusted Platform Assembly list
145 bool IsTpaListProvided();
146 inline CRITSEC_COOKIE GetCriticalSectionCookie();
147 inline LONG GetVersion();
148 inline void IncrementVersion();
150 #ifdef FEATURE_VERSIONING_LOG
151 inline BindingLog *GetBindingLog();
152 inline void ClearBindingLog();
153 #endif // FEATURE_VERSIONING_LOG
157 Volatile<LONG> m_cVersion;
158 SString m_applicationName;
159 DWORD m_dwAppDomainId;
160 ExecutionContext *m_pExecutionContext;
161 InspectionContext *m_pInspectionContext;
162 FailureCache *m_pFailureCache;
163 CRITSEC_COOKIE m_contextCS;
164 #ifdef FEATURE_VERSIONING_LOG
165 BindingLog m_bindingLog;
166 #endif // FEATURE_VERSIONING_LOG
168 AssemblyIdentityCache m_assemblyIdentityCache;
170 StringArrayList m_platformResourceRoots;
171 StringArrayList m_appPaths;
172 StringArrayList m_appNiPaths;
174 SimpleNameToFileNameMap * m_pTrustedPlatformAssemblyMap;
175 TpaFileNameHash * m_pFileNameHash;
177 bool m_fCanExplicitlyBindToNativeImages;
179 inline void SetExplicitBindToNativeImages(bool fCanExplicitlyBindToNativeImages)
181 m_fCanExplicitlyBindToNativeImages = fCanExplicitlyBindToNativeImages;
184 inline bool CanExplicitlyBindToNativeImages()
186 return m_fCanExplicitlyBindToNativeImages;
191 #include "applicationcontext.inl"