diff options
author | Sean Hall <r.sean.hall@gmail.com> | 2022-10-25 15:12:01 -0500 |
---|---|---|
committer | Sean Hall <r.sean.hall@gmail.com> | 2022-10-25 16:19:18 -0500 |
commit | d9ab1c3ce2cdebb865c2283eb3e764d3b2caaa98 (patch) | |
tree | 332335fbcd676be4fc991858897fbb35dcd3c9f3 /src/ext | |
parent | 321c30138c82390ea5ad6b0a612dff294203a877 (diff) | |
download | wix-d9ab1c3ce2cdebb865c2283eb3e764d3b2caaa98.tar.gz wix-d9ab1c3ce2cdebb865c2283eb3e764d3b2caaa98.tar.bz2 wix-d9ab1c3ce2cdebb865c2283eb3e764d3b2caaa98.zip |
Remove support for .NET Core 3.x from dnchost.
Related to 6942
Diffstat (limited to 'src/ext')
-rw-r--r-- | src/ext/Bal/dnchost/coreclrhost.h | 137 | ||||
-rw-r--r-- | src/ext/Bal/dnchost/dnchost.cpp | 1 | ||||
-rw-r--r-- | src/ext/Bal/dnchost/dnchost.vcxproj | 1 | ||||
-rw-r--r-- | src/ext/Bal/dnchost/dncutil.cpp | 257 | ||||
-rw-r--r-- | src/ext/Bal/dnchost/dncutil.h | 6 | ||||
-rw-r--r-- | src/ext/Bal/dnchost/precomp.h | 1 |
6 files changed, 19 insertions, 384 deletions
diff --git a/src/ext/Bal/dnchost/coreclrhost.h b/src/ext/Bal/dnchost/coreclrhost.h deleted file mode 100644 index 07f28735..00000000 --- a/src/ext/Bal/dnchost/coreclrhost.h +++ /dev/null | |||
@@ -1,137 +0,0 @@ | |||
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 | |||
5 | |||
6 | |||
7 | // ***** ABOUT THIS HEADER ***** | ||
8 | // ************************************************************************************** | ||
9 | // | ||
10 | // This is the version on 2019-12-22 from | ||
11 | // https://github.com/dotnet/runtime/blob/master/src/coreclr/src/coreclr/hosts/inc/coreclrhost.h | ||
12 | // | ||
13 | // ************************************************************************************** | ||
14 | // **************************** | ||
15 | |||
16 | |||
17 | // | ||
18 | // APIs for hosting CoreCLR | ||
19 | // | ||
20 | |||
21 | #ifndef __CORECLR_HOST_H__ | ||
22 | #define __CORECLR_HOST_H__ | ||
23 | |||
24 | #if defined(_WIN32) && defined(_M_IX86) | ||
25 | #define CORECLR_CALLING_CONVENTION __stdcall | ||
26 | #else | ||
27 | #define CORECLR_CALLING_CONVENTION | ||
28 | #endif | ||
29 | |||
30 | // For each hosting API, we define a function prototype and a function pointer | ||
31 | // The prototype is useful for implicit linking against the dynamic coreclr | ||
32 | // library and the pointer for explicit dynamic loading (dlopen, LoadLibrary) | ||
33 | #define CORECLR_HOSTING_API(function, ...) \ | ||
34 | extern "C" int CORECLR_CALLING_CONVENTION function(__VA_ARGS__); \ | ||
35 | typedef int (CORECLR_CALLING_CONVENTION *function##_ptr)(__VA_ARGS__) | ||
36 | |||
37 | // | ||
38 | // Initialize the CoreCLR. Creates and starts CoreCLR host and creates an app domain | ||
39 | // | ||
40 | // Parameters: | ||
41 | // exePath - Absolute path of the executable that invoked the ExecuteAssembly (the native host application) | ||
42 | // appDomainFriendlyName - Friendly name of the app domain that will be created to execute the assembly | ||
43 | // propertyCount - Number of properties (elements of the following two arguments) | ||
44 | // propertyKeys - Keys of properties of the app domain | ||
45 | // propertyValues - Values of properties of the app domain | ||
46 | // hostHandle - Output parameter, handle of the created host | ||
47 | // domainId - Output parameter, id of the created app domain | ||
48 | // | ||
49 | // Returns: | ||
50 | // HRESULT indicating status of the operation. S_OK if the assembly was successfully executed | ||
51 | // | ||
52 | CORECLR_HOSTING_API(coreclr_initialize, | ||
53 | const char* exePath, | ||
54 | const char* appDomainFriendlyName, | ||
55 | int propertyCount, | ||
56 | const char** propertyKeys, | ||
57 | const char** propertyValues, | ||
58 | void** hostHandle, | ||
59 | unsigned int* domainId); | ||
60 | |||
61 | // | ||
62 | // Shutdown CoreCLR. It unloads the app domain and stops the CoreCLR host. | ||
63 | // | ||
64 | // Parameters: | ||
65 | // hostHandle - Handle of the host | ||
66 | // domainId - Id of the domain | ||
67 | // | ||
68 | // Returns: | ||
69 | // HRESULT indicating status of the operation. S_OK if the assembly was successfully executed | ||
70 | // | ||
71 | CORECLR_HOSTING_API(coreclr_shutdown, | ||
72 | void* hostHandle, | ||
73 | unsigned int domainId); | ||
74 | |||
75 | // | ||
76 | // Shutdown CoreCLR. It unloads the app domain and stops the CoreCLR host. | ||
77 | // | ||
78 | // Parameters: | ||
79 | // hostHandle - Handle of the host | ||
80 | // domainId - Id of the domain | ||
81 | // latchedExitCode - Latched exit code after domain unloaded | ||
82 | // | ||
83 | // Returns: | ||
84 | // HRESULT indicating status of the operation. S_OK if the assembly was successfully executed | ||
85 | // | ||
86 | CORECLR_HOSTING_API(coreclr_shutdown_2, | ||
87 | void* hostHandle, | ||
88 | unsigned int domainId, | ||
89 | int* latchedExitCode); | ||
90 | |||
91 | // | ||
92 | // Create a native callable function pointer for a managed method. | ||
93 | // | ||
94 | // Parameters: | ||
95 | // hostHandle - Handle of the host | ||
96 | // domainId - Id of the domain | ||
97 | // entryPointAssemblyName - Name of the assembly which holds the custom entry point | ||
98 | // entryPointTypeName - Name of the type which holds the custom entry point | ||
99 | // entryPointMethodName - Name of the method which is the custom entry point | ||
100 | // delegate - Output parameter, the function stores a native callable function pointer to the delegate at the specified address | ||
101 | // | ||
102 | // Returns: | ||
103 | // HRESULT indicating status of the operation. S_OK if the assembly was successfully executed | ||
104 | // | ||
105 | CORECLR_HOSTING_API(coreclr_create_delegate, | ||
106 | void* hostHandle, | ||
107 | unsigned int domainId, | ||
108 | const char* entryPointAssemblyName, | ||
109 | const char* entryPointTypeName, | ||
110 | const char* entryPointMethodName, | ||
111 | void** delegate); | ||
112 | |||
113 | // | ||
114 | // Execute a managed assembly with given arguments | ||
115 | // | ||
116 | // Parameters: | ||
117 | // hostHandle - Handle of the host | ||
118 | // domainId - Id of the domain | ||
119 | // argc - Number of arguments passed to the executed assembly | ||
120 | // argv - Array of arguments passed to the executed assembly | ||
121 | // managedAssemblyPath - Path of the managed assembly to execute (or NULL if using a custom entrypoint). | ||
122 | // exitCode - Exit code returned by the executed assembly | ||
123 | // | ||
124 | // Returns: | ||
125 | // HRESULT indicating status of the operation. S_OK if the assembly was successfully executed | ||
126 | // | ||
127 | CORECLR_HOSTING_API(coreclr_execute_assembly, | ||
128 | void* hostHandle, | ||
129 | unsigned int domainId, | ||
130 | int argc, | ||
131 | const char** argv, | ||
132 | const char* managedAssemblyPath, | ||
133 | unsigned int* exitCode); | ||
134 | |||
135 | #undef CORECLR_HOSTING_API | ||
136 | |||
137 | #endif // __CORECLR_HOST_H__ \ No newline at end of file | ||
diff --git a/src/ext/Bal/dnchost/dnchost.cpp b/src/ext/Bal/dnchost/dnchost.cpp index 8faf292c..1868e3f8 100644 --- a/src/ext/Bal/dnchost/dnchost.cpp +++ b/src/ext/Bal/dnchost/dnchost.cpp | |||
@@ -286,7 +286,6 @@ static HRESULT LoadManagedBootstrapperApplicationFactory( | |||
286 | hr = DnchostCreateFactory( | 286 | hr = DnchostCreateFactory( |
287 | &pState->hostfxrState, | 287 | &pState->hostfxrState, |
288 | pState->sczBaFactoryAssemblyName, | 288 | pState->sczBaFactoryAssemblyName, |
289 | pState->sczBaFactoryAssemblyPath, | ||
290 | &pState->pAppFactory); | 289 | &pState->pAppFactory); |
291 | 290 | ||
292 | return hr; | 291 | return hr; |
diff --git a/src/ext/Bal/dnchost/dnchost.vcxproj b/src/ext/Bal/dnchost/dnchost.vcxproj index b258ccae..fc96580a 100644 --- a/src/ext/Bal/dnchost/dnchost.vcxproj +++ b/src/ext/Bal/dnchost/dnchost.vcxproj | |||
@@ -63,7 +63,6 @@ | |||
63 | </ItemGroup> | 63 | </ItemGroup> |
64 | 64 | ||
65 | <ItemGroup> | 65 | <ItemGroup> |
66 | <ClInclude Include="coreclrhost.h" /> | ||
67 | <ClInclude Include="dnchost.h" /> | 66 | <ClInclude Include="dnchost.h" /> |
68 | <ClInclude Include="dncutil.h" /> | 67 | <ClInclude Include="dncutil.h" /> |
69 | <ClInclude Include="precomp.h" /> | 68 | <ClInclude Include="precomp.h" /> |
diff --git a/src/ext/Bal/dnchost/dncutil.cpp b/src/ext/Bal/dnchost/dncutil.cpp index a8d4f4ff..d00b0ce6 100644 --- a/src/ext/Bal/dnchost/dncutil.cpp +++ b/src/ext/Bal/dnchost/dncutil.cpp | |||
@@ -2,9 +2,7 @@ | |||
2 | 2 | ||
3 | #include "precomp.h" | 3 | #include "precomp.h" |
4 | 4 | ||
5 | #define DNC_ENTRY_TYPE "WixToolset.Dnc.Host.BootstrapperApplicationFactory" | ||
6 | #define DNC_ENTRY_TYPEW L"WixToolset.Dnc.Host.BootstrapperApplicationFactory" | 5 | #define DNC_ENTRY_TYPEW L"WixToolset.Dnc.Host.BootstrapperApplicationFactory" |
7 | #define DNC_STATIC_ENTRY_METHOD "CreateBAFactory" | ||
8 | #define DNC_STATIC_ENTRY_METHODW L"CreateBAFactory" | 6 | #define DNC_STATIC_ENTRY_METHODW L"CreateBAFactory" |
9 | #define DNC_STATIC_ENTRY_DELEGATEW L"WixToolset.Dnc.Host.StaticEntryDelegate" | 7 | #define DNC_STATIC_ENTRY_DELEGATEW L"WixToolset.Dnc.Host.StaticEntryDelegate" |
10 | 8 | ||
@@ -29,23 +27,7 @@ static HRESULT InitializeHostfxr( | |||
29 | __in LPCWSTR wzRuntimeConfigPath | 27 | __in LPCWSTR wzRuntimeConfigPath |
30 | ); | 28 | ); |
31 | static HRESULT InitializeCoreClr( | 29 | static HRESULT InitializeCoreClr( |
32 | __in HOSTFXR_STATE* pState, | 30 | __in HOSTFXR_STATE* pState |
33 | __in LPCWSTR wzNativeHostPath | ||
34 | ); | ||
35 | static HRESULT InitializeCoreClrPre5( | ||
36 | __in HOSTFXR_STATE* pState, | ||
37 | __in LPCWSTR wzNativeHostPath | ||
38 | ); | ||
39 | static HRESULT LoadCoreClr( | ||
40 | __in HOSTFXR_STATE* pState, | ||
41 | __in LPCWSTR wzCoreClrPath | ||
42 | ); | ||
43 | static HRESULT StartCoreClr( | ||
44 | __in HOSTFXR_STATE* pState, | ||
45 | __in LPCWSTR wzNativeHostPath, | ||
46 | __in DWORD cProperties, | ||
47 | __in LPCWSTR* propertyKeys, | ||
48 | __in LPCWSTR* propertyValues | ||
49 | ); | 31 | ); |
50 | 32 | ||
51 | 33 | ||
@@ -70,7 +52,7 @@ HRESULT DnchostLoadRuntime( | |||
70 | hr = InitializeHostfxr(pState, wzManagedHostPath, wzDepsJsonPath, wzRuntimeConfigPath); | 52 | hr = InitializeHostfxr(pState, wzManagedHostPath, wzDepsJsonPath, wzRuntimeConfigPath); |
71 | BalExitOnFailure(hr, "Failed to initialize hostfxr."); | 53 | BalExitOnFailure(hr, "Failed to initialize hostfxr."); |
72 | 54 | ||
73 | hr = InitializeCoreClr(pState, wzNativeHostPath); | 55 | hr = InitializeCoreClr(pState); |
74 | BalExitOnFailure(hr, "Failed to initialize coreclr."); | 56 | BalExitOnFailure(hr, "Failed to initialize coreclr."); |
75 | 57 | ||
76 | LExit: | 58 | LExit: |
@@ -80,7 +62,6 @@ LExit: | |||
80 | HRESULT DnchostCreateFactory( | 62 | HRESULT DnchostCreateFactory( |
81 | __in HOSTFXR_STATE* pState, | 63 | __in HOSTFXR_STATE* pState, |
82 | __in LPCWSTR wzBaFactoryAssemblyName, | 64 | __in LPCWSTR wzBaFactoryAssemblyName, |
83 | __in LPCWSTR /*wzBaFactoryAssemblyPath*/, | ||
84 | __out IBootstrapperApplicationFactory** ppAppFactory | 65 | __out IBootstrapperApplicationFactory** ppAppFactory |
85 | ) | 66 | ) |
86 | { | 67 | { |
@@ -90,37 +71,20 @@ HRESULT DnchostCreateFactory( | |||
90 | LPWSTR sczEntryDelegate = NULL; | 71 | LPWSTR sczEntryDelegate = NULL; |
91 | LPSTR sczBaFactoryAssemblyName = NULL; | 72 | LPSTR sczBaFactoryAssemblyName = NULL; |
92 | 73 | ||
93 | if (pState->pfnGetFunctionPointer) | 74 | hr = StrAllocFormatted(&sczEntryType, L"%ls,%ls", DNC_ENTRY_TYPEW, wzBaFactoryAssemblyName); |
94 | { | 75 | BalExitOnFailure(hr, "Failed to format entry type."); |
95 | hr = StrAllocFormatted(&sczEntryType, L"%ls,%ls", DNC_ENTRY_TYPEW, wzBaFactoryAssemblyName); | 76 | |
96 | BalExitOnFailure(hr, "Failed to format entry type."); | 77 | hr = StrAllocFormatted(&sczEntryDelegate, L"%ls,%ls", DNC_STATIC_ENTRY_DELEGATEW, wzBaFactoryAssemblyName); |
97 | 78 | BalExitOnFailure(hr, "Failed to format entry delegate."); | |
98 | hr = StrAllocFormatted(&sczEntryDelegate, L"%ls,%ls", DNC_STATIC_ENTRY_DELEGATEW, wzBaFactoryAssemblyName); | 79 | |
99 | BalExitOnFailure(hr, "Failed to format entry delegate."); | 80 | hr = pState->pfnGetFunctionPointer( |
100 | 81 | sczEntryType, | |
101 | hr = pState->pfnGetFunctionPointer( | 82 | DNC_STATIC_ENTRY_METHODW, |
102 | sczEntryType, | 83 | sczEntryDelegate, |
103 | DNC_STATIC_ENTRY_METHODW, | 84 | NULL, |
104 | sczEntryDelegate, | 85 | NULL, |
105 | NULL, | 86 | reinterpret_cast<void**>(&pfnCreateBAFactory)); |
106 | NULL, | 87 | BalExitOnFailure(hr, "Failed to create delegate through GetFunctionPointer."); |
107 | reinterpret_cast<void**>(&pfnCreateBAFactory)); | ||
108 | BalExitOnFailure(hr, "Failed to create delegate through GetFunctionPointer."); | ||
109 | } | ||
110 | else | ||
111 | { | ||
112 | hr = StrAnsiAllocString(&sczBaFactoryAssemblyName, wzBaFactoryAssemblyName, 0, CP_UTF8); | ||
113 | BalExitOnFailure(hr, "Failed to convert assembly name to UTF8: %ls", wzBaFactoryAssemblyName); | ||
114 | |||
115 | hr = pState->pfnCoreclrCreateDelegate( | ||
116 | pState->pClrHandle, | ||
117 | pState->dwDomainId, | ||
118 | sczBaFactoryAssemblyName, | ||
119 | DNC_ENTRY_TYPE, | ||
120 | DNC_STATIC_ENTRY_METHOD, | ||
121 | reinterpret_cast<void**>(&pfnCreateBAFactory)); | ||
122 | BalExitOnFailure(hr, "Failed to create delegate in app domain."); | ||
123 | } | ||
124 | 88 | ||
125 | *ppAppFactory = pfnCreateBAFactory(); | 89 | *ppAppFactory = pfnCreateBAFactory(); |
126 | 90 | ||
@@ -182,9 +146,6 @@ static HRESULT LoadHostfxr( | |||
182 | pState->pfnHostfxrInitializeForApp = reinterpret_cast<hostfxr_initialize_for_dotnet_command_line_fn>(::GetProcAddress(hHostfxr, "hostfxr_initialize_for_dotnet_command_line")); | 146 | pState->pfnHostfxrInitializeForApp = reinterpret_cast<hostfxr_initialize_for_dotnet_command_line_fn>(::GetProcAddress(hHostfxr, "hostfxr_initialize_for_dotnet_command_line")); |
183 | BalExitOnNullWithLastError(pState->pfnHostfxrInitializeForApp, hr, "Failed to get procedure address for hostfxr_initialize_for_dotnet_command_line."); | 147 | BalExitOnNullWithLastError(pState->pfnHostfxrInitializeForApp, hr, "Failed to get procedure address for hostfxr_initialize_for_dotnet_command_line."); |
184 | 148 | ||
185 | pState->pfnHostfxrGetRuntimeProperties = reinterpret_cast<hostfxr_get_runtime_properties_fn>(::GetProcAddress(hHostfxr, "hostfxr_get_runtime_properties")); | ||
186 | BalExitOnNullWithLastError(pState->pfnHostfxrGetRuntimeProperties, hr, "Failed to get procedure address for hostfxr_get_runtime_properties."); | ||
187 | |||
188 | pState->pfnHostfxrSetErrorWriter = reinterpret_cast<hostfxr_set_error_writer_fn>(::GetProcAddress(hHostfxr, "hostfxr_set_error_writer")); | 149 | pState->pfnHostfxrSetErrorWriter = reinterpret_cast<hostfxr_set_error_writer_fn>(::GetProcAddress(hHostfxr, "hostfxr_set_error_writer")); |
189 | BalExitOnNullWithLastError(pState->pfnHostfxrSetErrorWriter, hr, "Failed to get procedure address for hostfxr_set_error_writer."); | 150 | BalExitOnNullWithLastError(pState->pfnHostfxrSetErrorWriter, hr, "Failed to get procedure address for hostfxr_set_error_writer."); |
190 | 151 | ||
@@ -204,14 +165,7 @@ static void HOSTFXR_CALLTYPE DnchostErrorWriter( | |||
204 | __in LPCWSTR wzMessage | 165 | __in LPCWSTR wzMessage |
205 | ) | 166 | ) |
206 | { | 167 | { |
207 | BOOTSTRAPPER_LOG_LEVEL level = BOOTSTRAPPER_LOG_LEVEL_ERROR; | 168 | BalLog(BOOTSTRAPPER_LOG_LEVEL_ERROR, "error from hostfxr: %ls", wzMessage); |
208 | |||
209 | if (CSTR_EQUAL == ::CompareString(LOCALE_INVARIANT, 0, wzMessage, -1, L"The requested delegate type is not available in the target framework.", -1)) | ||
210 | { | ||
211 | level = BOOTSTRAPPER_LOG_LEVEL_DEBUG; | ||
212 | } | ||
213 | |||
214 | BalLog(level, "error from hostfxr: %ls", wzMessage); | ||
215 | } | 169 | } |
216 | 170 | ||
217 | static HRESULT InitializeHostfxr( | 171 | static HRESULT InitializeHostfxr( |
@@ -241,8 +195,7 @@ LExit: | |||
241 | } | 195 | } |
242 | 196 | ||
243 | static HRESULT InitializeCoreClr( | 197 | static HRESULT InitializeCoreClr( |
244 | __in HOSTFXR_STATE* pState, | 198 | __in HOSTFXR_STATE* pState |
245 | __in LPCWSTR wzNativeHostPath | ||
246 | ) | 199 | ) |
247 | { | 200 | { |
248 | HRESULT hr = S_OK; | 201 | HRESULT hr = S_OK; |
@@ -251,7 +204,7 @@ static HRESULT InitializeCoreClr( | |||
251 | if (InvalidArgFailure == hr || // old versions of hostfxr don't allow calling GetRuntimeDelegate from InitializeForApp. | 204 | if (InvalidArgFailure == hr || // old versions of hostfxr don't allow calling GetRuntimeDelegate from InitializeForApp. |
252 | HostApiUnsupportedVersion == hr) // hdt_get_function_pointer was added in .NET 5. | 205 | HostApiUnsupportedVersion == hr) // hdt_get_function_pointer was added in .NET 5. |
253 | { | 206 | { |
254 | hr = InitializeCoreClrPre5(pState, wzNativeHostPath); | 207 | BalExitOnFailure(hr, "HostfxrGetRuntimeDelegate failed, most likely because the target framework is older than .NET 5."); |
255 | } | 208 | } |
256 | else | 209 | else |
257 | { | 210 | { |
@@ -261,175 +214,3 @@ static HRESULT InitializeCoreClr( | |||
261 | LExit: | 214 | LExit: |
262 | return hr; | 215 | return hr; |
263 | } | 216 | } |
264 | |||
265 | static HRESULT InitializeCoreClrPre5( | ||
266 | __in HOSTFXR_STATE* pState, | ||
267 | __in LPCWSTR wzNativeHostPath | ||
268 | ) | ||
269 | { | ||
270 | HRESULT hr = S_OK; | ||
271 | int32_t rc = 0; | ||
272 | LPCWSTR* rgPropertyKeys = NULL; | ||
273 | LPCWSTR* rgPropertyValues = NULL; | ||
274 | size_t cProperties = 0; | ||
275 | LPWSTR* rgDirectories = NULL; | ||
276 | UINT cDirectories = 0; | ||
277 | LPWSTR sczCoreClrPath = NULL; | ||
278 | |||
279 | // We are not using hostfxr as it was intended to be used. We need to initialize hostfxr so that it properly initializes hostpolicy - | ||
280 | // there are pieces of the framework such as AssemblyDependencyResolver that won't work without that. We also need hostfxr to find a | ||
281 | // compatible framework for framework-dependent deployed BAs. We had to use hostfxr_initialize_for_dotnet_command_line since | ||
282 | // hostfxr_initialize_for_runtime_config doesn't currently (3.x) support self-contained deployed BAs. That means we're supposed to | ||
283 | // start the runtime through hostfxr_run_app, but that method shuts down the runtime before returning. We actually want to call | ||
284 | // hostfxr_get_runtime_delegate, but that method currently requires hostfxr to be initialized through | ||
285 | // hostfxr_initialize_for_runtime_config. So we're forced to locate coreclr.dll and manually load the runtime ourselves. | ||
286 | |||
287 | // Unfortunately, that's not the only problem. hostfxr has global state that tracks whether it started the runtime. While we keep our | ||
288 | // hostfxr_handle open, everyone that calls the hostfxr_initialize_* methods will block until we have started the runtime through | ||
289 | // hostfxr or closed our handle. If we close the handle, then hostfxr could potentially try to load a second runtime into the | ||
290 | // process, which is not supported. We're going to just keep our handle open since no one else in the process should be trying to | ||
291 | // start the runtime anyway. | ||
292 | |||
293 | rc = pState->pfnHostfxrGetRuntimeProperties(pState->hostContextHandle, &cProperties, rgPropertyKeys, rgPropertyValues); | ||
294 | if (HostApiBufferTooSmall != rc) | ||
295 | { | ||
296 | BalExitOnFailure(hr = rc, "HostfxrGetRuntimeProperties failed to return required size."); | ||
297 | } | ||
298 | |||
299 | rgPropertyKeys = static_cast<LPCWSTR*>(MemAlloc(sizeof(LPWSTR) * cProperties, TRUE)); | ||
300 | rgPropertyValues = static_cast<LPCWSTR*>(MemAlloc(sizeof(LPWSTR) * cProperties, TRUE)); | ||
301 | if (!rgPropertyKeys || !rgPropertyValues) | ||
302 | { | ||
303 | BalExitOnFailure(hr = E_OUTOFMEMORY, "Failed to allocate buffers for runtime properties."); | ||
304 | } | ||
305 | |||
306 | hr = pState->pfnHostfxrGetRuntimeProperties(pState->hostContextHandle, &cProperties, rgPropertyKeys, rgPropertyValues); | ||
307 | BalExitOnFailure(hr, "HostfxrGetRuntimeProperties failed."); | ||
308 | |||
309 | for (DWORD i = 0; i < cProperties; ++i) | ||
310 | { | ||
311 | if (CSTR_EQUAL == ::CompareString(LOCALE_INVARIANT, 0, rgPropertyKeys[i], -1, L"NATIVE_DLL_SEARCH_DIRECTORIES", -1)) | ||
312 | { | ||
313 | hr = StrSplitAllocArray(&rgDirectories, &cDirectories, rgPropertyValues[i], L";"); | ||
314 | BalExitOnFailure(hr, "Failed to split NATIVE_DLL_SEARCH_DIRECTORIES '%ls'", rgPropertyValues[i]); | ||
315 | } | ||
316 | } | ||
317 | |||
318 | for (DWORD i = 0; i < cDirectories; ++i) | ||
319 | { | ||
320 | Assert(rgDirectories); | ||
321 | |||
322 | hr = PathConcat(rgDirectories[i], L"coreclr.dll", &sczCoreClrPath); | ||
323 | BalExitOnFailure(hr, "Failed to allocate path to coreclr."); | ||
324 | |||
325 | if (::PathFileExists(sczCoreClrPath)) | ||
326 | { | ||
327 | break; | ||
328 | } | ||
329 | else | ||
330 | { | ||
331 | ReleaseNullStr(sczCoreClrPath); | ||
332 | } | ||
333 | } | ||
334 | |||
335 | if (!sczCoreClrPath) | ||
336 | { | ||
337 | for (DWORD i = 0; i < cProperties; ++i) | ||
338 | { | ||
339 | BalLog(BOOTSTRAPPER_LOG_LEVEL_ERROR, "%ls: %ls", rgPropertyKeys[i], rgPropertyValues[i]); | ||
340 | } | ||
341 | BalExitWithRootFailure(hr, E_FILENOTFOUND, "Failed to locate coreclr.dll."); | ||
342 | } | ||
343 | |||
344 | hr = LoadCoreClr(pState, sczCoreClrPath); | ||
345 | BalExitOnFailure(hr, "Failed to load coreclr."); | ||
346 | |||
347 | hr = StartCoreClr(pState, wzNativeHostPath, (DWORD)cProperties, rgPropertyKeys, rgPropertyValues); | ||
348 | BalExitOnFailure(hr, "Failed to start coreclr."); | ||
349 | |||
350 | LExit: | ||
351 | ReleaseMem(rgDirectories); | ||
352 | ReleaseMem(rgPropertyValues); | ||
353 | ReleaseMem(rgPropertyKeys); | ||
354 | ReleaseStr(sczCoreClrPath); | ||
355 | |||
356 | return hr; | ||
357 | } | ||
358 | |||
359 | static HRESULT LoadCoreClr( | ||
360 | __in HOSTFXR_STATE* pState, | ||
361 | __in LPCWSTR wzCoreClrPath | ||
362 | ) | ||
363 | { | ||
364 | HRESULT hr = S_OK; | ||
365 | HMODULE hModule = NULL; | ||
366 | |||
367 | hModule = ::LoadLibraryExW(wzCoreClrPath, NULL, LOAD_WITH_ALTERED_SEARCH_PATH); | ||
368 | BalExitOnNullWithLastError(hModule, hr, "Failed to load coreclr.dll from '%ls'.", wzCoreClrPath); | ||
369 | |||
370 | pState->pfnCoreclrInitialize = reinterpret_cast<coreclr_initialize_ptr>(::GetProcAddress(hModule, "coreclr_initialize")); | ||
371 | BalExitOnNullWithLastError(pState->pfnCoreclrInitialize, hr, "Failed to get procedure address for coreclr_initialize."); | ||
372 | |||
373 | pState->pfnCoreclrCreateDelegate = reinterpret_cast<coreclr_create_delegate_ptr>(::GetProcAddress(hModule, "coreclr_create_delegate")); | ||
374 | BalExitOnNullWithLastError(pState->pfnCoreclrCreateDelegate, hr, "Failed to get procedure address for coreclr_create_delegate."); | ||
375 | |||
376 | LExit: | ||
377 | // Never unload the module since coreclr doesn't support it. | ||
378 | |||
379 | return hr; | ||
380 | } | ||
381 | |||
382 | static HRESULT StartCoreClr( | ||
383 | __in HOSTFXR_STATE* pState, | ||
384 | __in LPCWSTR wzNativeHostPath, | ||
385 | __in DWORD cProperties, | ||
386 | __in LPCWSTR* propertyKeys, | ||
387 | __in LPCWSTR* propertyValues | ||
388 | ) | ||
389 | { | ||
390 | HRESULT hr = S_OK; | ||
391 | LPSTR szNativeHostPath = NULL; | ||
392 | LPSTR* rgPropertyKeys = NULL; | ||
393 | LPSTR* rgPropertyValues = NULL; | ||
394 | |||
395 | rgPropertyKeys = static_cast<LPSTR*>(MemAlloc(sizeof(LPSTR) * cProperties, TRUE)); | ||
396 | rgPropertyValues = static_cast<LPSTR*>(MemAlloc(sizeof(LPSTR) * cProperties, TRUE)); | ||
397 | if (!rgPropertyKeys || !rgPropertyValues) | ||
398 | { | ||
399 | BalExitOnFailure(hr = E_OUTOFMEMORY, "Failed to allocate buffers for runtime properties."); | ||
400 | } | ||
401 | |||
402 | hr = StrAnsiAllocString(&szNativeHostPath, wzNativeHostPath, 0, CP_UTF8); | ||
403 | BalExitOnFailure(hr, "Failed to convert module path to UTF8: %ls", wzNativeHostPath); | ||
404 | |||
405 | for (DWORD i = 0; i < cProperties; ++i) | ||
406 | { | ||
407 | hr = StrAnsiAllocString(&rgPropertyKeys[i], propertyKeys[i], 0, CP_UTF8); | ||
408 | BalExitOnFailure(hr, "Failed to convert property key to UTF8: %ls", propertyKeys[i]); | ||
409 | |||
410 | hr = StrAnsiAllocString(&rgPropertyValues[i], propertyValues[i], 0, CP_UTF8); | ||
411 | BalExitOnFailure(hr, "Failed to convert property value to UTF8: %ls", propertyValues[i]); | ||
412 | } | ||
413 | |||
414 | hr = pState->pfnCoreclrInitialize(szNativeHostPath, "MBA", cProperties, (LPCSTR*)rgPropertyKeys, (LPCSTR*)rgPropertyValues, &pState->pClrHandle, &pState->dwDomainId); | ||
415 | BalExitOnFailure(hr, "CoreclrInitialize failed."); | ||
416 | |||
417 | LExit: | ||
418 | for (DWORD i = 0; i < cProperties; ++i) | ||
419 | { | ||
420 | if (rgPropertyKeys) | ||
421 | { | ||
422 | ReleaseStr(rgPropertyKeys[i]); | ||
423 | } | ||
424 | |||
425 | if (rgPropertyValues) | ||
426 | { | ||
427 | ReleaseStr(rgPropertyValues[i]); | ||
428 | } | ||
429 | } | ||
430 | ReleaseMem(rgPropertyValues); | ||
431 | ReleaseMem(rgPropertyKeys); | ||
432 | ReleaseStr(szNativeHostPath); | ||
433 | |||
434 | return hr; | ||
435 | } | ||
diff --git a/src/ext/Bal/dnchost/dncutil.h b/src/ext/Bal/dnchost/dncutil.h index f88e3f77..3fa81364 100644 --- a/src/ext/Bal/dnchost/dncutil.h +++ b/src/ext/Bal/dnchost/dncutil.h | |||
@@ -8,15 +8,10 @@ struct HOSTFXR_STATE | |||
8 | LPWSTR sczHostfxrPath; | 8 | LPWSTR sczHostfxrPath; |
9 | hostfxr_handle hostContextHandle; | 9 | hostfxr_handle hostContextHandle; |
10 | hostfxr_initialize_for_dotnet_command_line_fn pfnHostfxrInitializeForApp; | 10 | hostfxr_initialize_for_dotnet_command_line_fn pfnHostfxrInitializeForApp; |
11 | hostfxr_get_runtime_properties_fn pfnHostfxrGetRuntimeProperties; | ||
12 | hostfxr_set_error_writer_fn pfnHostfxrSetErrorWriter; | 11 | hostfxr_set_error_writer_fn pfnHostfxrSetErrorWriter; |
13 | hostfxr_close_fn pfnHostfxrClose; | 12 | hostfxr_close_fn pfnHostfxrClose; |
14 | hostfxr_get_runtime_delegate_fn pfnHostfxrGetRuntimeDelegate; | 13 | hostfxr_get_runtime_delegate_fn pfnHostfxrGetRuntimeDelegate; |
15 | get_function_pointer_fn pfnGetFunctionPointer; | 14 | get_function_pointer_fn pfnGetFunctionPointer; |
16 | coreclr_initialize_ptr pfnCoreclrInitialize; | ||
17 | coreclr_create_delegate_ptr pfnCoreclrCreateDelegate; | ||
18 | void* pClrHandle; | ||
19 | UINT dwDomainId; | ||
20 | }; | 15 | }; |
21 | 16 | ||
22 | HRESULT DnchostLoadRuntime( | 17 | HRESULT DnchostLoadRuntime( |
@@ -30,6 +25,5 @@ HRESULT DnchostLoadRuntime( | |||
30 | HRESULT DnchostCreateFactory( | 25 | HRESULT DnchostCreateFactory( |
31 | __in HOSTFXR_STATE* pState, | 26 | __in HOSTFXR_STATE* pState, |
32 | __in LPCWSTR wzBaFactoryAssemblyName, | 27 | __in LPCWSTR wzBaFactoryAssemblyName, |
33 | __in LPCWSTR wzBaFactoryAssemblyPath, | ||
34 | __out IBootstrapperApplicationFactory** ppAppFactory | 28 | __out IBootstrapperApplicationFactory** ppAppFactory |
35 | ); | 29 | ); |
diff --git a/src/ext/Bal/dnchost/precomp.h b/src/ext/Bal/dnchost/precomp.h index 5f365fba..2166a23d 100644 --- a/src/ext/Bal/dnchost/precomp.h +++ b/src/ext/Bal/dnchost/precomp.h | |||
@@ -27,6 +27,5 @@ | |||
27 | 27 | ||
28 | #include <preqba.h> | 28 | #include <preqba.h> |
29 | 29 | ||
30 | #include "coreclrhost.h" | ||
31 | #include "dncutil.h" | 30 | #include "dncutil.h" |
32 | #include "dnchost.h" | 31 | #include "dnchost.h" |