forked from maraf/runtime
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapplicationcontext.cpp
More file actions
222 lines (186 loc) · 6.64 KB
/
applicationcontext.cpp
File metadata and controls
222 lines (186 loc) · 6.64 KB
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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// ============================================================
//
// ApplicationContext.cpp
//
//
// Implements the ApplicationContext class
//
// ============================================================
#include "applicationcontext.hpp"
#include "assemblyhashtraits.hpp"
#include "stringarraylist.h"
#include "failurecache.hpp"
#include "utils.hpp"
#include "ex.h"
#include "clr/fs/path.h"
using namespace clr::fs;
namespace BINDER_SPACE
{
ApplicationContext::ApplicationContext()
{
m_pExecutionContext = NULL;
m_pFailureCache = NULL;
m_contextCS = NULL;
m_pTrustedPlatformAssemblyMap = nullptr;
}
ApplicationContext::~ApplicationContext()
{
SAFE_DELETE(m_pExecutionContext);
SAFE_DELETE(m_pFailureCache);
if (m_contextCS != NULL)
{
ClrDeleteCriticalSection(m_contextCS);
}
if (m_pTrustedPlatformAssemblyMap != nullptr)
{
delete m_pTrustedPlatformAssemblyMap;
}
}
HRESULT ApplicationContext::Init()
{
HRESULT hr = S_OK;
NewHolder<ExecutionContext> pExecutionContext;
FailureCache *pFailureCache = NULL;
// Allocate context objects
SAFE_NEW(pExecutionContext, ExecutionContext);
SAFE_NEW(pFailureCache, FailureCache);
m_contextCS = ClrCreateCriticalSection(
CrstFusionAppCtx,
CRST_REENTRANCY);
if (!m_contextCS)
{
SAFE_DELETE(pFailureCache);
hr = E_OUTOFMEMORY;
}
else
{
m_pExecutionContext = pExecutionContext.Extract();
m_pFailureCache = pFailureCache;
}
Exit:
return hr;
}
HRESULT ApplicationContext::SetupBindingPaths(SString &sTrustedPlatformAssemblies,
SString &sPlatformResourceRoots,
SString &sAppPaths,
BOOL fAcquireLock)
{
HRESULT hr = S_OK;
CRITSEC_Holder contextLock(fAcquireLock ? GetCriticalSectionCookie() : NULL);
if (m_pTrustedPlatformAssemblyMap != nullptr)
{
GO_WITH_HRESULT(S_OK);
}
//
// Parse TrustedPlatformAssemblies
//
m_pTrustedPlatformAssemblyMap = new SimpleNameToFileNameMap();
sTrustedPlatformAssemblies.Normalize();
for (SString::Iterator i = sTrustedPlatformAssemblies.Begin(); i != sTrustedPlatformAssemblies.End(); )
{
SString fileName;
SString simpleName;
bool isNativeImage = false;
HRESULT pathResult = S_OK;
IF_FAIL_GO(pathResult = GetNextTPAPath(sTrustedPlatformAssemblies, i, /*dllOnly*/ false, fileName, simpleName, isNativeImage));
if (pathResult == S_FALSE)
{
break;
}
const SimpleNameToFileNameMapEntry *pExistingEntry = m_pTrustedPlatformAssemblyMap->LookupPtr(simpleName.GetUnicode());
if (pExistingEntry != nullptr)
{
//
// We want to store only the first entry matching a simple name we encounter.
// The exception is if we first store an IL reference and later in the string
// we encounter a native image. Since we don't touch IL in the presence of
// native images, we replace the IL entry with the NI.
//
if ((pExistingEntry->m_wszILFileName != nullptr && !isNativeImage) ||
(pExistingEntry->m_wszNIFileName != nullptr && isNativeImage))
{
continue;
}
}
LPWSTR wszSimpleName = nullptr;
if (pExistingEntry == nullptr)
{
wszSimpleName = new WCHAR[simpleName.GetCount() + 1];
if (wszSimpleName == nullptr)
{
GO_WITH_HRESULT(E_OUTOFMEMORY);
}
wcscpy_s(wszSimpleName, simpleName.GetCount() + 1, simpleName.GetUnicode());
}
else
{
wszSimpleName = pExistingEntry->m_wszSimpleName;
}
LPWSTR wszFileName = new WCHAR[fileName.GetCount() + 1];
if (wszFileName == nullptr)
{
GO_WITH_HRESULT(E_OUTOFMEMORY);
}
wcscpy_s(wszFileName, fileName.GetCount() + 1, fileName.GetUnicode());
SimpleNameToFileNameMapEntry mapEntry;
mapEntry.m_wszSimpleName = wszSimpleName;
if (isNativeImage)
{
mapEntry.m_wszNIFileName = wszFileName;
mapEntry.m_wszILFileName = pExistingEntry == nullptr ? nullptr : pExistingEntry->m_wszILFileName;
}
else
{
mapEntry.m_wszILFileName = wszFileName;
mapEntry.m_wszNIFileName = pExistingEntry == nullptr ? nullptr : pExistingEntry->m_wszNIFileName;
}
m_pTrustedPlatformAssemblyMap->AddOrReplace(mapEntry);
}
//
// Parse PlatformResourceRoots
//
sPlatformResourceRoots.Normalize();
for (SString::Iterator i = sPlatformResourceRoots.Begin(); i != sPlatformResourceRoots.End(); )
{
SString pathName;
HRESULT pathResult = S_OK;
IF_FAIL_GO(pathResult = GetNextPath(sPlatformResourceRoots, i, pathName));
if (pathResult == S_FALSE)
{
break;
}
if (Path::IsRelative(pathName))
{
GO_WITH_HRESULT(E_INVALIDARG);
}
m_platformResourceRoots.Append(pathName);
}
//
// Parse AppPaths
//
sAppPaths.Normalize();
for (SString::Iterator i = sAppPaths.Begin(); i != sAppPaths.End(); )
{
SString pathName;
HRESULT pathResult = S_OK;
IF_FAIL_GO(pathResult = GetNextPath(sAppPaths, i, pathName));
if (pathResult == S_FALSE)
{
break;
}
if (Path::IsRelative(pathName))
{
GO_WITH_HRESULT(E_INVALIDARG);
}
m_appPaths.Append(pathName);
}
Exit:
return hr;
}
bool ApplicationContext::IsTpaListProvided()
{
return m_pTrustedPlatformAssemblyMap != nullptr;
}
};