diff options
author | Rob Mensching <rob@firegiant.com> | 2024-01-11 18:26:20 -0800 |
---|---|---|
committer | Rob Mensching <rob@firegiant.com> | 2024-03-06 18:03:38 -0800 |
commit | 0d3d54992104288e9ee0c834d0b96e8502fd2d42 (patch) | |
tree | 9efa49c4983cd2ba1becab64bd1f2faccac88acf /src/ext/Bal/dnchost | |
parent | 2824298d9dd817a47527c920363556b54ead5d5d (diff) | |
download | wix-0d3d54992104288e9ee0c834d0b96e8502fd2d42.tar.gz wix-0d3d54992104288e9ee0c834d0b96e8502fd2d42.tar.bz2 wix-0d3d54992104288e9ee0c834d0b96e8502fd2d42.zip |
Move the BootstrapperApplication out of proc
Diffstat (limited to 'src/ext/Bal/dnchost')
-rw-r--r-- | src/ext/Bal/dnchost/dnchost.cpp | 328 | ||||
-rw-r--r-- | src/ext/Bal/dnchost/dnchost.def | 6 | ||||
-rw-r--r-- | src/ext/Bal/dnchost/dnchost.h | 28 | ||||
-rw-r--r-- | src/ext/Bal/dnchost/dnchost.vcxproj | 89 | ||||
-rw-r--r-- | src/ext/Bal/dnchost/dncutil.cpp | 216 | ||||
-rw-r--r-- | src/ext/Bal/dnchost/dncutil.h | 29 | ||||
-rw-r--r-- | src/ext/Bal/dnchost/packages.config | 6 | ||||
-rw-r--r-- | src/ext/Bal/dnchost/precomp.cpp | 3 | ||||
-rw-r--r-- | src/ext/Bal/dnchost/precomp.h | 31 |
9 files changed, 0 insertions, 736 deletions
diff --git a/src/ext/Bal/dnchost/dnchost.cpp b/src/ext/Bal/dnchost/dnchost.cpp deleted file mode 100644 index 1868e3f8..00000000 --- a/src/ext/Bal/dnchost/dnchost.cpp +++ /dev/null | |||
@@ -1,328 +0,0 @@ | |||
1 | // Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information. | ||
2 | |||
3 | #include "precomp.h" | ||
4 | |||
5 | static DNCSTATE vstate = { }; | ||
6 | |||
7 | |||
8 | // internal function declarations | ||
9 | |||
10 | static HRESULT LoadModulePaths( | ||
11 | __in DNCSTATE* pState | ||
12 | ); | ||
13 | static HRESULT LoadDncConfiguration( | ||
14 | __in DNCSTATE* pState, | ||
15 | __in const BOOTSTRAPPER_CREATE_ARGS* pArgs | ||
16 | ); | ||
17 | static HRESULT LoadRuntime( | ||
18 | __in DNCSTATE* pState | ||
19 | ); | ||
20 | static HRESULT LoadManagedBootstrapperApplicationFactory( | ||
21 | __in DNCSTATE* pState | ||
22 | ); | ||
23 | static HRESULT CreatePrerequisiteBA( | ||
24 | __in DNCSTATE* pState, | ||
25 | __in IBootstrapperEngine* pEngine, | ||
26 | __in const BOOTSTRAPPER_CREATE_ARGS* pArgs, | ||
27 | __inout BOOTSTRAPPER_CREATE_RESULTS* pResults | ||
28 | ); | ||
29 | |||
30 | |||
31 | // function definitions | ||
32 | |||
33 | extern "C" BOOL WINAPI DllMain( | ||
34 | IN HINSTANCE hInstance, | ||
35 | IN DWORD dwReason, | ||
36 | IN LPVOID /* pvReserved */ | ||
37 | ) | ||
38 | { | ||
39 | switch (dwReason) | ||
40 | { | ||
41 | case DLL_PROCESS_ATTACH: | ||
42 | ::DisableThreadLibraryCalls(hInstance); | ||
43 | vstate.hInstance = hInstance; | ||
44 | break; | ||
45 | |||
46 | case DLL_PROCESS_DETACH: | ||
47 | vstate.hInstance = NULL; | ||
48 | break; | ||
49 | } | ||
50 | |||
51 | return TRUE; | ||
52 | } | ||
53 | |||
54 | extern "C" HRESULT WINAPI BootstrapperApplicationCreate( | ||
55 | __in const BOOTSTRAPPER_CREATE_ARGS* pArgs, | ||
56 | __inout BOOTSTRAPPER_CREATE_RESULTS* pResults | ||
57 | ) | ||
58 | { | ||
59 | HRESULT hr = S_OK; | ||
60 | IBootstrapperEngine* pEngine = NULL; | ||
61 | |||
62 | hr = BalInitializeFromCreateArgs(pArgs, &pEngine); | ||
63 | ExitOnFailure(hr, "Failed to initialize Bal."); | ||
64 | |||
65 | if (!vstate.fInitialized) | ||
66 | { | ||
67 | hr = XmlInitialize(); | ||
68 | BalExitOnFailure(hr, "Failed to initialize XML."); | ||
69 | |||
70 | hr = LoadModulePaths(&vstate); | ||
71 | BalExitOnFailure(hr, "Failed to get the host base path."); | ||
72 | |||
73 | hr = LoadDncConfiguration(&vstate, pArgs); | ||
74 | BalExitOnFailure(hr, "Failed to get the dnc configuration."); | ||
75 | |||
76 | vstate.fInitialized = TRUE; | ||
77 | } | ||
78 | |||
79 | if (vstate.prereqData.fAlwaysInstallPrereqs && !vstate.prereqData.fCompleted) | ||
80 | { | ||
81 | BalLog(BOOTSTRAPPER_LOG_LEVEL_STANDARD, "Loading prerequisite bootstrapper application since it's configured to always run before loading the runtime."); | ||
82 | |||
83 | hr = CreatePrerequisiteBA(&vstate, pEngine, pArgs, pResults); | ||
84 | BalExitOnFailure(hr, "Failed to create the pre-requisite bootstrapper application."); | ||
85 | |||
86 | ExitFunction(); | ||
87 | } | ||
88 | |||
89 | if (!vstate.fInitializedRuntime) | ||
90 | { | ||
91 | hr = LoadRuntime(&vstate); | ||
92 | |||
93 | vstate.fInitializedRuntime = SUCCEEDED(hr); | ||
94 | } | ||
95 | |||
96 | if (vstate.fInitializedRuntime) | ||
97 | { | ||
98 | if (!vstate.pAppFactory) | ||
99 | { | ||
100 | hr = LoadManagedBootstrapperApplicationFactory(&vstate); | ||
101 | BalExitOnFailure(hr, "Failed to create the .NET Core bootstrapper application factory."); | ||
102 | } | ||
103 | |||
104 | BalLog(BOOTSTRAPPER_LOG_LEVEL_STANDARD, "Loading .NET Core %ls bootstrapper application.", DNCHOSTTYPE_FDD == vstate.type ? L"FDD" : L"SCD"); | ||
105 | |||
106 | hr = vstate.pAppFactory->Create(pArgs, pResults); | ||
107 | BalExitOnFailure(hr, "Failed to create the .NET Core bootstrapper application."); | ||
108 | } | ||
109 | else // fallback to the prerequisite BA. | ||
110 | { | ||
111 | if (DNCHOSTTYPE_SCD == vstate.type) | ||
112 | { | ||
113 | vstate.prereqData.hrFatalError = E_DNCHOST_SCD_RUNTIME_FAILURE; | ||
114 | BalLogError(hr, "The self-contained .NET Core runtime failed to load. This is an unrecoverable error."); | ||
115 | } | ||
116 | else if (vstate.prereqData.fCompleted) | ||
117 | { | ||
118 | hr = E_PREREQBA_INFINITE_LOOP; | ||
119 | BalLogError(hr, "The prerequisites were already installed. The bootstrapper application will not be reloaded to prevent an infinite loop."); | ||
120 | vstate.prereqData.hrFatalError = hr; | ||
121 | } | ||
122 | else | ||
123 | { | ||
124 | vstate.prereqData.hrFatalError = S_OK; | ||
125 | } | ||
126 | BalLog(BOOTSTRAPPER_LOG_LEVEL_STANDARD, "Loading prerequisite bootstrapper application because .NET Core host could not be loaded, error: 0x%08x.", hr); | ||
127 | |||
128 | hr = CreatePrerequisiteBA(&vstate, pEngine, pArgs, pResults); | ||
129 | BalExitOnFailure(hr, "Failed to create the pre-requisite bootstrapper application."); | ||
130 | } | ||
131 | |||
132 | LExit: | ||
133 | ReleaseNullObject(pEngine); | ||
134 | |||
135 | return hr; | ||
136 | } | ||
137 | |||
138 | extern "C" void WINAPI BootstrapperApplicationDestroy( | ||
139 | __in const BOOTSTRAPPER_DESTROY_ARGS* pArgs, | ||
140 | __in BOOTSTRAPPER_DESTROY_RESULTS* pResults | ||
141 | ) | ||
142 | { | ||
143 | BOOTSTRAPPER_DESTROY_RESULTS childResults = { }; | ||
144 | |||
145 | childResults.cbSize = sizeof(BOOTSTRAPPER_DESTROY_RESULTS); | ||
146 | |||
147 | if (vstate.hMbapreqModule) | ||
148 | { | ||
149 | PFN_BOOTSTRAPPER_APPLICATION_DESTROY pfnDestroy = reinterpret_cast<PFN_BOOTSTRAPPER_APPLICATION_DESTROY>(::GetProcAddress(vstate.hMbapreqModule, "PrereqBootstrapperApplicationDestroy")); | ||
150 | if (pfnDestroy) | ||
151 | { | ||
152 | (*pfnDestroy)(pArgs, &childResults); | ||
153 | } | ||
154 | |||
155 | ::FreeLibrary(vstate.hMbapreqModule); | ||
156 | vstate.hMbapreqModule = NULL; | ||
157 | } | ||
158 | |||
159 | BalUninitialize(); | ||
160 | |||
161 | // Need to keep track of state between reloads. | ||
162 | pResults->fDisableUnloading = TRUE; | ||
163 | } | ||
164 | |||
165 | static HRESULT LoadModulePaths( | ||
166 | __in DNCSTATE* pState | ||
167 | ) | ||
168 | { | ||
169 | HRESULT hr = S_OK; | ||
170 | |||
171 | hr = PathForCurrentProcess(&pState->sczModuleFullPath, pState->hInstance); | ||
172 | BalExitOnFailure(hr, "Failed to get the full host path."); | ||
173 | |||
174 | hr = PathGetDirectory(pState->sczModuleFullPath, &pState->sczAppBase); | ||
175 | BalExitOnFailure(hr, "Failed to get the directory of the full process path."); | ||
176 | |||
177 | LExit: | ||
178 | return hr; | ||
179 | } | ||
180 | |||
181 | static HRESULT LoadDncConfiguration( | ||
182 | __in DNCSTATE* pState, | ||
183 | __in const BOOTSTRAPPER_CREATE_ARGS* pArgs | ||
184 | ) | ||
185 | { | ||
186 | HRESULT hr = S_OK; | ||
187 | IXMLDOMDocument* pixdManifest = NULL; | ||
188 | IXMLDOMNode* pixnHost = NULL; | ||
189 | LPWSTR sczPayloadName = NULL; | ||
190 | DWORD dwBool = 0; | ||
191 | BOOL fXmlFound = FALSE; | ||
192 | |||
193 | hr = XmlLoadDocumentFromFile(pArgs->pCommand->wzBootstrapperApplicationDataPath, &pixdManifest); | ||
194 | BalExitOnFailure(hr, "Failed to load BalManifest '%ls'", pArgs->pCommand->wzBootstrapperApplicationDataPath); | ||
195 | |||
196 | hr = XmlSelectSingleNode(pixdManifest, L"/BootstrapperApplicationData/WixBalBAFactoryAssembly", &pixnHost); | ||
197 | BalExitOnRequiredXmlQueryFailure(hr, "Failed to get WixBalBAFactoryAssembly element."); | ||
198 | |||
199 | hr = XmlGetAttributeEx(pixnHost, L"FilePath", &sczPayloadName); | ||
200 | BalExitOnRequiredXmlQueryFailure(hr, "Failed to get WixBalBAFactoryAssembly/@FilePath."); | ||
201 | |||
202 | hr = PathConcatRelativeToBase(pArgs->pCommand->wzBootstrapperWorkingFolder, sczPayloadName, &pState->sczBaFactoryAssemblyPath); | ||
203 | BalExitOnFailure(hr, "Failed to create BaFactoryAssemblyPath."); | ||
204 | |||
205 | LPCWSTR wzFileName = PathFile(pState->sczBaFactoryAssemblyPath); | ||
206 | LPCWSTR wzExtension = PathExtension(pState->sczBaFactoryAssemblyPath); | ||
207 | if (!wzExtension) | ||
208 | { | ||
209 | BalExitOnFailure(hr = E_FAIL, "BaFactoryAssemblyPath has no extension."); | ||
210 | } | ||
211 | |||
212 | hr = StrAllocString(&pState->sczBaFactoryAssemblyName, wzFileName, wzExtension - wzFileName); | ||
213 | BalExitOnFailure(hr, "Failed to copy BAFactoryAssembly payload Name."); | ||
214 | |||
215 | hr = StrAllocString(&pState->sczBaFactoryDepsJsonPath, pState->sczBaFactoryAssemblyPath, wzExtension - pState->sczBaFactoryAssemblyPath); | ||
216 | BalExitOnFailure(hr, "Failed to initialize deps json path."); | ||
217 | |||
218 | hr = StrAllocString(&pState->sczBaFactoryRuntimeConfigPath, pState->sczBaFactoryDepsJsonPath, 0); | ||
219 | BalExitOnFailure(hr, "Failed to initialize runtime config path."); | ||
220 | |||
221 | hr = StrAllocConcat(&pState->sczBaFactoryDepsJsonPath, L".deps.json", 0); | ||
222 | BalExitOnFailure(hr, "Failed to concat extension to deps json path."); | ||
223 | |||
224 | hr = StrAllocConcat(&pState->sczBaFactoryRuntimeConfigPath, L".runtimeconfig.json", 0); | ||
225 | BalExitOnFailure(hr, "Failed to concat extension to runtime config path."); | ||
226 | |||
227 | hr = XmlSelectSingleNode(pixdManifest, L"/BootstrapperApplicationData/WixMbaPrereqOptions", &pixnHost); | ||
228 | BalExitOnOptionalXmlQueryFailure(hr, fXmlFound, "Failed to find WixMbaPrereqOptions element in bootstrapper application config."); | ||
229 | |||
230 | if (fXmlFound) | ||
231 | { | ||
232 | hr = XmlGetAttributeNumber(pixnHost, L"AlwaysInstallPrereqs", reinterpret_cast<DWORD*>(&pState->prereqData.fAlwaysInstallPrereqs)); | ||
233 | BalExitOnOptionalXmlQueryFailure(hr, fXmlFound, "Failed to get AlwaysInstallPrereqs value."); | ||
234 | } | ||
235 | |||
236 | pState->prereqData.fPerformHelp = !pState->prereqData.fAlwaysInstallPrereqs; | ||
237 | |||
238 | pState->type = DNCHOSTTYPE_FDD; | ||
239 | |||
240 | hr = XmlSelectSingleNode(pixdManifest, L"/BootstrapperApplicationData/WixDncOptions", &pixnHost); | ||
241 | BalExitOnOptionalXmlQueryFailure(hr, fXmlFound, "Failed to find WixDncOptions element in bootstrapper application config."); | ||
242 | |||
243 | if (!fXmlFound) | ||
244 | { | ||
245 | ExitFunction(); | ||
246 | } | ||
247 | |||
248 | hr = XmlGetAttributeNumber(pixnHost, L"SelfContainedDeployment", &dwBool); | ||
249 | BalExitOnOptionalXmlQueryFailure(hr, fXmlFound, "Failed to get SelfContainedDeployment value."); | ||
250 | |||
251 | if (fXmlFound && dwBool) | ||
252 | { | ||
253 | pState->type = DNCHOSTTYPE_SCD; | ||
254 | } | ||
255 | |||
256 | LExit: | ||
257 | ReleaseStr(sczPayloadName); | ||
258 | ReleaseObject(pixnHost); | ||
259 | ReleaseObject(pixdManifest); | ||
260 | |||
261 | return hr; | ||
262 | } | ||
263 | |||
264 | static HRESULT LoadRuntime( | ||
265 | __in DNCSTATE* pState | ||
266 | ) | ||
267 | { | ||
268 | HRESULT hr = S_OK; | ||
269 | |||
270 | hr = DnchostLoadRuntime( | ||
271 | &pState->hostfxrState, | ||
272 | pState->sczModuleFullPath, | ||
273 | pState->sczBaFactoryAssemblyPath, | ||
274 | pState->sczBaFactoryDepsJsonPath, | ||
275 | pState->sczBaFactoryRuntimeConfigPath); | ||
276 | |||
277 | return hr; | ||
278 | } | ||
279 | |||
280 | static HRESULT LoadManagedBootstrapperApplicationFactory( | ||
281 | __in DNCSTATE* pState | ||
282 | ) | ||
283 | { | ||
284 | HRESULT hr = S_OK; | ||
285 | |||
286 | hr = DnchostCreateFactory( | ||
287 | &pState->hostfxrState, | ||
288 | pState->sczBaFactoryAssemblyName, | ||
289 | &pState->pAppFactory); | ||
290 | |||
291 | return hr; | ||
292 | } | ||
293 | |||
294 | static HRESULT CreatePrerequisiteBA( | ||
295 | __in DNCSTATE* pState, | ||
296 | __in IBootstrapperEngine* pEngine, | ||
297 | __in const BOOTSTRAPPER_CREATE_ARGS* pArgs, | ||
298 | __inout BOOTSTRAPPER_CREATE_RESULTS* pResults | ||
299 | ) | ||
300 | { | ||
301 | HRESULT hr = S_OK; | ||
302 | LPWSTR sczDncpreqPath = NULL; | ||
303 | HMODULE hModule = NULL; | ||
304 | |||
305 | hr = PathConcat(pState->sczAppBase, L"dncpreq.dll", &sczDncpreqPath); | ||
306 | BalExitOnFailure(hr, "Failed to get path to pre-requisite BA."); | ||
307 | |||
308 | hModule = ::LoadLibraryExW(sczDncpreqPath, NULL, LOAD_WITH_ALTERED_SEARCH_PATH); | ||
309 | BalExitOnNullWithLastError(hModule, hr, "Failed to load pre-requisite BA DLL."); | ||
310 | |||
311 | PFN_PREQ_BOOTSTRAPPER_APPLICATION_CREATE pfnCreate = reinterpret_cast<PFN_PREQ_BOOTSTRAPPER_APPLICATION_CREATE>(::GetProcAddress(hModule, "PrereqBootstrapperApplicationCreate")); | ||
312 | BalExitOnNullWithLastError(pfnCreate, hr, "Failed to get PrereqBootstrapperApplicationCreate entry-point from: %ls", sczDncpreqPath); | ||
313 | |||
314 | hr = pfnCreate(&pState->prereqData, pEngine, pArgs, pResults); | ||
315 | BalExitOnFailure(hr, "Failed to create prequisite bootstrapper app."); | ||
316 | |||
317 | pState->hMbapreqModule = hModule; | ||
318 | hModule = NULL; | ||
319 | |||
320 | LExit: | ||
321 | if (hModule) | ||
322 | { | ||
323 | ::FreeLibrary(hModule); | ||
324 | } | ||
325 | ReleaseStr(sczDncpreqPath); | ||
326 | |||
327 | return hr; | ||
328 | } | ||
diff --git a/src/ext/Bal/dnchost/dnchost.def b/src/ext/Bal/dnchost/dnchost.def deleted file mode 100644 index 4488df94..00000000 --- a/src/ext/Bal/dnchost/dnchost.def +++ /dev/null | |||
@@ -1,6 +0,0 @@ | |||
1 | ; Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information. | ||
2 | |||
3 | |||
4 | EXPORTS | ||
5 | BootstrapperApplicationCreate | ||
6 | BootstrapperApplicationDestroy | ||
diff --git a/src/ext/Bal/dnchost/dnchost.h b/src/ext/Bal/dnchost/dnchost.h deleted file mode 100644 index 000cf43d..00000000 --- a/src/ext/Bal/dnchost/dnchost.h +++ /dev/null | |||
@@ -1,28 +0,0 @@ | |||
1 | #pragma once | ||
2 | // Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information. | ||
3 | |||
4 | |||
5 | enum DNCHOSTTYPE | ||
6 | { | ||
7 | DNCHOSTTYPE_UNKNOWN, | ||
8 | DNCHOSTTYPE_FDD, | ||
9 | DNCHOSTTYPE_SCD, | ||
10 | }; | ||
11 | |||
12 | struct DNCSTATE | ||
13 | { | ||
14 | BOOL fInitialized; | ||
15 | BOOL fInitializedRuntime; | ||
16 | HINSTANCE hInstance; | ||
17 | LPWSTR sczModuleFullPath; | ||
18 | LPWSTR sczAppBase; | ||
19 | LPWSTR sczBaFactoryAssemblyName; | ||
20 | LPWSTR sczBaFactoryAssemblyPath; | ||
21 | LPWSTR sczBaFactoryDepsJsonPath; | ||
22 | LPWSTR sczBaFactoryRuntimeConfigPath; | ||
23 | DNCHOSTTYPE type; | ||
24 | HOSTFXR_STATE hostfxrState; | ||
25 | IBootstrapperApplicationFactory* pAppFactory; | ||
26 | HMODULE hMbapreqModule; | ||
27 | PREQBA_DATA prereqData; | ||
28 | }; | ||
diff --git a/src/ext/Bal/dnchost/dnchost.vcxproj b/src/ext/Bal/dnchost/dnchost.vcxproj deleted file mode 100644 index 5860e968..00000000 --- a/src/ext/Bal/dnchost/dnchost.vcxproj +++ /dev/null | |||
@@ -1,89 +0,0 @@ | |||
1 | <?xml version="1.0" encoding="utf-8"?> | ||
2 | <!-- Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information. --> | ||
3 | <Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
4 | <ItemGroup Label="ProjectConfigurations"> | ||
5 | <ProjectConfiguration Include="Debug|ARM64"> | ||
6 | <Configuration>Debug</Configuration> | ||
7 | <Platform>ARM64</Platform> | ||
8 | </ProjectConfiguration> | ||
9 | <ProjectConfiguration Include="Release|ARM64"> | ||
10 | <Configuration>Release</Configuration> | ||
11 | <Platform>ARM64</Platform> | ||
12 | </ProjectConfiguration> | ||
13 | <ProjectConfiguration Include="Debug|Win32"> | ||
14 | <Configuration>Debug</Configuration> | ||
15 | <Platform>Win32</Platform> | ||
16 | </ProjectConfiguration> | ||
17 | <ProjectConfiguration Include="Release|Win32"> | ||
18 | <Configuration>Release</Configuration> | ||
19 | <Platform>Win32</Platform> | ||
20 | </ProjectConfiguration> | ||
21 | <ProjectConfiguration Include="Debug|x64"> | ||
22 | <Configuration>Debug</Configuration> | ||
23 | <Platform>x64</Platform> | ||
24 | </ProjectConfiguration> | ||
25 | <ProjectConfiguration Include="Release|x64"> | ||
26 | <Configuration>Release</Configuration> | ||
27 | <Platform>x64</Platform> | ||
28 | </ProjectConfiguration> | ||
29 | </ItemGroup> | ||
30 | |||
31 | <PropertyGroup Label="Globals"> | ||
32 | <ProjectGuid>{B6F70281-6583-4138-BB7F-AABFEBBB3CA2}</ProjectGuid> | ||
33 | <ConfigurationType>DynamicLibrary</ConfigurationType> | ||
34 | <CharacterSet>Unicode</CharacterSet> | ||
35 | <TargetName>dnchost</TargetName> | ||
36 | <ProjectModuleDefinitionFile>dnchost.def</ProjectModuleDefinitionFile> | ||
37 | </PropertyGroup> | ||
38 | |||
39 | <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> | ||
40 | <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> | ||
41 | |||
42 | <ItemDefinitionGroup Condition=" '$(Configuration)'=='Debug' "> | ||
43 | <ClCompile> | ||
44 | <!-- libnethost.lib is currently only available in Release mode, so can't use debug runtime --> | ||
45 | <RuntimeLibrary>MultiThreaded</RuntimeLibrary> | ||
46 | </ClCompile> | ||
47 | </ItemDefinitionGroup> | ||
48 | |||
49 | <PropertyGroup> | ||
50 | <NetHostPlatform>$(Platform)</NetHostPlatform> | ||
51 | <NetHostPlatform Condition=" '$(NetHostPlatform)'=='Win32' ">x86</NetHostPlatform> | ||
52 | <NetHostPath>..\..\..\..\packages\runtime.win-$(NetHostPlatform).Microsoft.NETCore.DotNetAppHost.6.0.4\runtimes\win-$(NetHostPlatform)\native\</NetHostPath> | ||
53 | <ProjectAdditionalIncludeDirectories>$(BaseOutputPath)obj;$(NetHostPath);..\wixstdba\inc</ProjectAdditionalIncludeDirectories> | ||
54 | <ProjectAdditionalLinkLibraries>shlwapi.lib;$(NetHostPath)libnethost.lib</ProjectAdditionalLinkLibraries> | ||
55 | </PropertyGroup> | ||
56 | |||
57 | <ItemGroup> | ||
58 | <ClCompile Include="dnchost.cpp" /> | ||
59 | <ClCompile Include="dncutil.cpp" /> | ||
60 | <ClCompile Include="precomp.cpp"> | ||
61 | <PrecompiledHeader>Create</PrecompiledHeader> | ||
62 | </ClCompile> | ||
63 | </ItemGroup> | ||
64 | |||
65 | <ItemGroup> | ||
66 | <ClInclude Include="dnchost.h" /> | ||
67 | <ClInclude Include="dncutil.h" /> | ||
68 | <ClInclude Include="precomp.h" /> | ||
69 | </ItemGroup> | ||
70 | |||
71 | <ItemGroup> | ||
72 | <None Include="dnchost.def" /> | ||
73 | </ItemGroup> | ||
74 | |||
75 | <ItemDefinitionGroup> | ||
76 | <Link> | ||
77 | <!-- libnethost.lib is currently compiled with /GL, so must use linker option /LTCG --> | ||
78 | <AdditionalOptions>/LTCG %(AdditionalOptions)</AdditionalOptions> | ||
79 | </Link> | ||
80 | </ItemDefinitionGroup> | ||
81 | |||
82 | <ItemGroup> | ||
83 | <PackageReference Include="WixToolset.BalUtil" /> | ||
84 | |||
85 | <PackageReference Include="Microsoft.SourceLink.GitHub" PrivateAssets="All" /> | ||
86 | </ItemGroup> | ||
87 | |||
88 | <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> | ||
89 | </Project> | ||
diff --git a/src/ext/Bal/dnchost/dncutil.cpp b/src/ext/Bal/dnchost/dncutil.cpp deleted file mode 100644 index d00b0ce6..00000000 --- a/src/ext/Bal/dnchost/dncutil.cpp +++ /dev/null | |||
@@ -1,216 +0,0 @@ | |||
1 | // Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information. | ||
2 | |||
3 | #include "precomp.h" | ||
4 | |||
5 | #define DNC_ENTRY_TYPEW L"WixToolset.Dnc.Host.BootstrapperApplicationFactory" | ||
6 | #define DNC_STATIC_ENTRY_METHODW L"CreateBAFactory" | ||
7 | #define DNC_STATIC_ENTRY_DELEGATEW L"WixToolset.Dnc.Host.StaticEntryDelegate" | ||
8 | |||
9 | // https://github.com/dotnet/runtime/blob/master/src/installer/corehost/error_codes.h | ||
10 | #define InvalidArgFailure 0x80008081 | ||
11 | #define HostApiBufferTooSmall 0x80008098 | ||
12 | #define HostApiUnsupportedVersion 0x800080a2 | ||
13 | |||
14 | // internal function declarations | ||
15 | |||
16 | static HRESULT GetHostfxrPath( | ||
17 | __in HOSTFXR_STATE* pState, | ||
18 | __in LPCWSTR wzNativeHostPath | ||
19 | ); | ||
20 | static HRESULT LoadHostfxr( | ||
21 | __in HOSTFXR_STATE* pState | ||
22 | ); | ||
23 | static HRESULT InitializeHostfxr( | ||
24 | __in HOSTFXR_STATE* pState, | ||
25 | __in LPCWSTR wzManagedHostPath, | ||
26 | __in LPCWSTR wzDepsJsonPath, | ||
27 | __in LPCWSTR wzRuntimeConfigPath | ||
28 | ); | ||
29 | static HRESULT InitializeCoreClr( | ||
30 | __in HOSTFXR_STATE* pState | ||
31 | ); | ||
32 | |||
33 | |||
34 | // function definitions | ||
35 | |||
36 | HRESULT DnchostLoadRuntime( | ||
37 | __in HOSTFXR_STATE* pState, | ||
38 | __in LPCWSTR wzNativeHostPath, | ||
39 | __in LPCWSTR wzManagedHostPath, | ||
40 | __in LPCWSTR wzDepsJsonPath, | ||
41 | __in LPCWSTR wzRuntimeConfigPath | ||
42 | ) | ||
43 | { | ||
44 | HRESULT hr = S_OK; | ||
45 | |||
46 | hr = GetHostfxrPath(pState, wzNativeHostPath); | ||
47 | BalExitOnFailure(hr, "Failed to find hostfxr."); | ||
48 | |||
49 | hr = LoadHostfxr(pState); | ||
50 | BalExitOnFailure(hr, "Failed to load hostfxr."); | ||
51 | |||
52 | hr = InitializeHostfxr(pState, wzManagedHostPath, wzDepsJsonPath, wzRuntimeConfigPath); | ||
53 | BalExitOnFailure(hr, "Failed to initialize hostfxr."); | ||
54 | |||
55 | hr = InitializeCoreClr(pState); | ||
56 | BalExitOnFailure(hr, "Failed to initialize coreclr."); | ||
57 | |||
58 | LExit: | ||
59 | return hr; | ||
60 | } | ||
61 | |||
62 | HRESULT DnchostCreateFactory( | ||
63 | __in HOSTFXR_STATE* pState, | ||
64 | __in LPCWSTR wzBaFactoryAssemblyName, | ||
65 | __out IBootstrapperApplicationFactory** ppAppFactory | ||
66 | ) | ||
67 | { | ||
68 | HRESULT hr = S_OK; | ||
69 | PFNCREATEBAFACTORY pfnCreateBAFactory = NULL; | ||
70 | LPWSTR sczEntryType = NULL; | ||
71 | LPWSTR sczEntryDelegate = NULL; | ||
72 | LPSTR sczBaFactoryAssemblyName = NULL; | ||
73 | |||
74 | hr = StrAllocFormatted(&sczEntryType, L"%ls,%ls", DNC_ENTRY_TYPEW, wzBaFactoryAssemblyName); | ||
75 | BalExitOnFailure(hr, "Failed to format entry type."); | ||
76 | |||
77 | hr = StrAllocFormatted(&sczEntryDelegate, L"%ls,%ls", DNC_STATIC_ENTRY_DELEGATEW, wzBaFactoryAssemblyName); | ||
78 | BalExitOnFailure(hr, "Failed to format entry delegate."); | ||
79 | |||
80 | hr = pState->pfnGetFunctionPointer( | ||
81 | sczEntryType, | ||
82 | DNC_STATIC_ENTRY_METHODW, | ||
83 | sczEntryDelegate, | ||
84 | NULL, | ||
85 | NULL, | ||
86 | reinterpret_cast<void**>(&pfnCreateBAFactory)); | ||
87 | BalExitOnFailure(hr, "Failed to create delegate through GetFunctionPointer."); | ||
88 | |||
89 | *ppAppFactory = pfnCreateBAFactory(); | ||
90 | |||
91 | LExit: | ||
92 | ReleaseStr(sczEntryType); | ||
93 | ReleaseStr(sczEntryDelegate); | ||
94 | ReleaseStr(sczBaFactoryAssemblyName); | ||
95 | |||
96 | return hr; | ||
97 | } | ||
98 | |||
99 | static HRESULT GetHostfxrPath( | ||
100 | __in HOSTFXR_STATE* pState, | ||
101 | __in LPCWSTR wzNativeHostPath | ||
102 | ) | ||
103 | { | ||
104 | HRESULT hr = S_OK; | ||
105 | get_hostfxr_parameters getHostfxrParameters = { }; | ||
106 | int nrc = 0; | ||
107 | size_t cchHostFxrPath = MAX_PATH; | ||
108 | |||
109 | getHostfxrParameters.size = sizeof(get_hostfxr_parameters); | ||
110 | getHostfxrParameters.assembly_path = wzNativeHostPath; | ||
111 | |||
112 | // get_hostfxr_path does a full search on every call, so | ||
113 | // minimize the number of calls | ||
114 | // need to loop | ||
115 | for (;;) | ||
116 | { | ||
117 | cchHostFxrPath *= 2; | ||
118 | hr = StrAlloc(&pState->sczHostfxrPath, cchHostFxrPath); | ||
119 | BalExitOnFailure(hr, "Failed to allocate hostFxrPath."); | ||
120 | |||
121 | nrc = get_hostfxr_path(pState->sczHostfxrPath, &cchHostFxrPath, &getHostfxrParameters); | ||
122 | if (HostApiBufferTooSmall != nrc) | ||
123 | { | ||
124 | break; | ||
125 | } | ||
126 | } | ||
127 | if (0 != nrc) | ||
128 | { | ||
129 | BalExitOnFailure(hr = nrc, "GetHostfxrPath failed"); | ||
130 | } | ||
131 | |||
132 | LExit: | ||
133 | return hr; | ||
134 | } | ||
135 | |||
136 | static HRESULT LoadHostfxr( | ||
137 | __in HOSTFXR_STATE* pState | ||
138 | ) | ||
139 | { | ||
140 | HRESULT hr = S_OK; | ||
141 | HMODULE hHostfxr; | ||
142 | |||
143 | hHostfxr = ::LoadLibraryExW(pState->sczHostfxrPath, NULL, LOAD_WITH_ALTERED_SEARCH_PATH); | ||
144 | BalExitOnNullWithLastError(hHostfxr, hr, "Failed to load hostfxr from '%ls'.", pState->sczHostfxrPath); | ||
145 | |||
146 | pState->pfnHostfxrInitializeForApp = reinterpret_cast<hostfxr_initialize_for_dotnet_command_line_fn>(::GetProcAddress(hHostfxr, "hostfxr_initialize_for_dotnet_command_line")); | ||
147 | BalExitOnNullWithLastError(pState->pfnHostfxrInitializeForApp, hr, "Failed to get procedure address for hostfxr_initialize_for_dotnet_command_line."); | ||
148 | |||
149 | pState->pfnHostfxrSetErrorWriter = reinterpret_cast<hostfxr_set_error_writer_fn>(::GetProcAddress(hHostfxr, "hostfxr_set_error_writer")); | ||
150 | BalExitOnNullWithLastError(pState->pfnHostfxrSetErrorWriter, hr, "Failed to get procedure address for hostfxr_set_error_writer."); | ||
151 | |||
152 | pState->pfnHostfxrClose = reinterpret_cast<hostfxr_close_fn>(::GetProcAddress(hHostfxr, "hostfxr_close")); | ||
153 | BalExitOnNullWithLastError(pState->pfnHostfxrClose, hr, "Failed to get procedure address for hostfxr_close."); | ||
154 | |||
155 | pState->pfnHostfxrGetRuntimeDelegate = reinterpret_cast<hostfxr_get_runtime_delegate_fn>(::GetProcAddress(hHostfxr, "hostfxr_get_runtime_delegate")); | ||
156 | BalExitOnNullWithLastError(pState->pfnHostfxrGetRuntimeDelegate, hr, "Failed to get procedure address for hostfxr_get_runtime_delegate."); | ||
157 | |||
158 | LExit: | ||
159 | // Never unload the module since it isn't meant to be unloaded. | ||
160 | |||
161 | return hr; | ||
162 | } | ||
163 | |||
164 | static void HOSTFXR_CALLTYPE DnchostErrorWriter( | ||
165 | __in LPCWSTR wzMessage | ||
166 | ) | ||
167 | { | ||
168 | BalLog(BOOTSTRAPPER_LOG_LEVEL_ERROR, "error from hostfxr: %ls", wzMessage); | ||
169 | } | ||
170 | |||
171 | static HRESULT InitializeHostfxr( | ||
172 | __in HOSTFXR_STATE* pState, | ||
173 | __in LPCWSTR wzManagedHostPath, | ||
174 | __in LPCWSTR wzDepsJsonPath, | ||
175 | __in LPCWSTR wzRuntimeConfigPath | ||
176 | ) | ||
177 | { | ||
178 | HRESULT hr = S_OK; | ||
179 | |||
180 | pState->pfnHostfxrSetErrorWriter(static_cast<hostfxr_error_writer_fn>(&DnchostErrorWriter)); | ||
181 | |||
182 | LPCWSTR argv[] = { | ||
183 | L"exec", | ||
184 | L"--depsfile", | ||
185 | wzDepsJsonPath, | ||
186 | L"--runtimeconfig", | ||
187 | wzRuntimeConfigPath, | ||
188 | wzManagedHostPath, | ||
189 | }; | ||
190 | hr = pState->pfnHostfxrInitializeForApp(sizeof(argv)/sizeof(LPWSTR), argv, NULL, &pState->hostContextHandle); | ||
191 | BalExitOnFailure(hr, "HostfxrInitializeForApp failed"); | ||
192 | |||
193 | LExit: | ||
194 | return hr; | ||
195 | } | ||
196 | |||
197 | static HRESULT InitializeCoreClr( | ||
198 | __in HOSTFXR_STATE* pState | ||
199 | ) | ||
200 | { | ||
201 | HRESULT hr = S_OK; | ||
202 | |||
203 | hr = pState->pfnHostfxrGetRuntimeDelegate(pState->hostContextHandle, hdt_get_function_pointer, reinterpret_cast<void**>(&pState->pfnGetFunctionPointer)); | ||
204 | if (InvalidArgFailure == hr || // old versions of hostfxr don't allow calling GetRuntimeDelegate from InitializeForApp. | ||
205 | HostApiUnsupportedVersion == hr) // hdt_get_function_pointer was added in .NET 5. | ||
206 | { | ||
207 | BalExitOnFailure(hr, "HostfxrGetRuntimeDelegate failed, most likely because the target framework is older than .NET 5."); | ||
208 | } | ||
209 | else | ||
210 | { | ||
211 | BalExitOnFailure(hr, "HostfxrGetRuntimeDelegate failed"); | ||
212 | } | ||
213 | |||
214 | LExit: | ||
215 | return hr; | ||
216 | } | ||
diff --git a/src/ext/Bal/dnchost/dncutil.h b/src/ext/Bal/dnchost/dncutil.h deleted file mode 100644 index 3fa81364..00000000 --- a/src/ext/Bal/dnchost/dncutil.h +++ /dev/null | |||
@@ -1,29 +0,0 @@ | |||
1 | #pragma once | ||
2 | // Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information. | ||
3 | |||
4 | typedef IBootstrapperApplicationFactory* (STDMETHODCALLTYPE* PFNCREATEBAFACTORY)(); | ||
5 | |||
6 | struct HOSTFXR_STATE | ||
7 | { | ||
8 | LPWSTR sczHostfxrPath; | ||
9 | hostfxr_handle hostContextHandle; | ||
10 | hostfxr_initialize_for_dotnet_command_line_fn pfnHostfxrInitializeForApp; | ||
11 | hostfxr_set_error_writer_fn pfnHostfxrSetErrorWriter; | ||
12 | hostfxr_close_fn pfnHostfxrClose; | ||
13 | hostfxr_get_runtime_delegate_fn pfnHostfxrGetRuntimeDelegate; | ||
14 | get_function_pointer_fn pfnGetFunctionPointer; | ||
15 | }; | ||
16 | |||
17 | HRESULT DnchostLoadRuntime( | ||
18 | __in HOSTFXR_STATE* pState, | ||
19 | __in LPCWSTR wzNativeHostPath, | ||
20 | __in LPCWSTR wzManagedHostPath, | ||
21 | __in LPCWSTR wzDepsJsonPath, | ||
22 | __in LPCWSTR wzRuntimeConfigPath | ||
23 | ); | ||
24 | |||
25 | HRESULT DnchostCreateFactory( | ||
26 | __in HOSTFXR_STATE* pState, | ||
27 | __in LPCWSTR wzBaFactoryAssemblyName, | ||
28 | __out IBootstrapperApplicationFactory** ppAppFactory | ||
29 | ); | ||
diff --git a/src/ext/Bal/dnchost/packages.config b/src/ext/Bal/dnchost/packages.config deleted file mode 100644 index 1c7505e7..00000000 --- a/src/ext/Bal/dnchost/packages.config +++ /dev/null | |||
@@ -1,6 +0,0 @@ | |||
1 | <?xml version="1.0" encoding="utf-8"?> | ||
2 | <packages> | ||
3 | <package id="runtime.win-arm64.Microsoft.NETCore.DotNetAppHost" version="6.0.4" targetFramework="native" /> | ||
4 | <package id="runtime.win-x64.Microsoft.NETCore.DotNetAppHost" version="6.0.4" targetFramework="native" /> | ||
5 | <package id="runtime.win-x86.Microsoft.NETCore.DotNetAppHost" version="6.0.4" targetFramework="native" /> | ||
6 | </packages> \ No newline at end of file | ||
diff --git a/src/ext/Bal/dnchost/precomp.cpp b/src/ext/Bal/dnchost/precomp.cpp deleted file mode 100644 index 37664a1c..00000000 --- a/src/ext/Bal/dnchost/precomp.cpp +++ /dev/null | |||
@@ -1,3 +0,0 @@ | |||
1 | // Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information. | ||
2 | |||
3 | #include "precomp.h" | ||
diff --git a/src/ext/Bal/dnchost/precomp.h b/src/ext/Bal/dnchost/precomp.h deleted file mode 100644 index 2166a23d..00000000 --- a/src/ext/Bal/dnchost/precomp.h +++ /dev/null | |||
@@ -1,31 +0,0 @@ | |||
1 | #pragma once | ||
2 | // Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information. | ||
3 | |||
4 | #include <windows.h> | ||
5 | #include <msiquery.h> | ||
6 | #include <corerror.h> | ||
7 | #include <Shlwapi.h> | ||
8 | |||
9 | #include <dutil.h> | ||
10 | #include <memutil.h> | ||
11 | #include <pathutil.h> | ||
12 | #include <strutil.h> | ||
13 | #include <xmlutil.h> | ||
14 | |||
15 | #include <BootstrapperEngine.h> | ||
16 | #include <BootstrapperApplication.h> | ||
17 | |||
18 | #include <IBootstrapperEngine.h> | ||
19 | #include <IBootstrapperApplication.h> | ||
20 | #include <IBootstrapperApplicationFactory.h> | ||
21 | #include <balutil.h> | ||
22 | |||
23 | #define NETHOST_USE_AS_STATIC | ||
24 | #include <nethost.h> | ||
25 | #include <hostfxr.h> | ||
26 | #include <coreclr_delegates.h> | ||
27 | |||
28 | #include <preqba.h> | ||
29 | |||
30 | #include "dncutil.h" | ||
31 | #include "dnchost.h" | ||