diff options
| author | Sean Hall <r.sean.hall@gmail.com> | 2020-07-22 19:55:20 +1000 |
|---|---|---|
| committer | Sean Hall <r.sean.hall@gmail.com> | 2020-07-22 20:13:49 +1000 |
| commit | d96ba4263bf243dedb62e9090072fba53bfe1316 (patch) | |
| tree | 44fe48f8b8671834795b90d14e17fad889710751 /src | |
| parent | 70b5d207d799308a6c3742f5d0348ab4fca75a3d (diff) | |
| download | wix-d96ba4263bf243dedb62e9090072fba53bfe1316.tar.gz wix-d96ba4263bf243dedb62e9090072fba53bfe1316.tar.bz2 wix-d96ba4263bf243dedb62e9090072fba53bfe1316.zip | |
Use hdt_get_function_pointer in dnchost when available.
Diffstat (limited to 'src')
| -rw-r--r-- | src/WixToolset.Dnc.Host/BootstrapperApplicationFactory.cs | 2 | ||||
| -rw-r--r-- | src/WixToolset.Dnc.Host/WixToolset.Dnc.Host.csproj | 3 | ||||
| -rw-r--r-- | src/dnchost/dncutil.cpp | 61 | ||||
| -rw-r--r-- | src/dnchost/dncutil.h | 2 | ||||
| -rw-r--r-- | src/dnchost/precomp.h | 1 |
5 files changed, 61 insertions, 8 deletions
diff --git a/src/WixToolset.Dnc.Host/BootstrapperApplicationFactory.cs b/src/WixToolset.Dnc.Host/BootstrapperApplicationFactory.cs index 0c6ea367..d38fd1a9 100644 --- a/src/WixToolset.Dnc.Host/BootstrapperApplicationFactory.cs +++ b/src/WixToolset.Dnc.Host/BootstrapperApplicationFactory.cs | |||
| @@ -7,6 +7,8 @@ namespace WixToolset.Dnc.Host | |||
| 7 | using System.Reflection; | 7 | using System.Reflection; |
| 8 | using System.Runtime.InteropServices; | 8 | using System.Runtime.InteropServices; |
| 9 | 9 | ||
| 10 | delegate IBootstrapperApplicationFactory StaticEntryDelegate([MarshalAs(UnmanagedType.LPWStr)] string baFactoryAssemblyName, [MarshalAs(UnmanagedType.LPWStr)] string baFactoryAssemblyPath); | ||
| 11 | |||
| 10 | /// <summary> | 12 | /// <summary> |
| 11 | /// Entry point for the .NET Core host to create and return the BA to the engine. | 13 | /// Entry point for the .NET Core host to create and return the BA to the engine. |
| 12 | /// Reflection is used instead of referencing WixToolset.Mba.Core directly to avoid requiring it in the AssemblyLoadContext. | 14 | /// Reflection is used instead of referencing WixToolset.Mba.Core directly to avoid requiring it in the AssemblyLoadContext. |
diff --git a/src/WixToolset.Dnc.Host/WixToolset.Dnc.Host.csproj b/src/WixToolset.Dnc.Host/WixToolset.Dnc.Host.csproj index 495b13a2..707edd1b 100644 --- a/src/WixToolset.Dnc.Host/WixToolset.Dnc.Host.csproj +++ b/src/WixToolset.Dnc.Host/WixToolset.Dnc.Host.csproj | |||
| @@ -24,7 +24,10 @@ | |||
| 24 | <Line Include='#define DNC_ASSEMBLY_FILE_NAME L"$(AssemblyName).dll"' /> | 24 | <Line Include='#define DNC_ASSEMBLY_FILE_NAME L"$(AssemblyName).dll"' /> |
| 25 | <Line Include='#define DNC_ASSEMBLY_FULL_NAME "%(AssemblyIdentity.Identity)"' /> | 25 | <Line Include='#define DNC_ASSEMBLY_FULL_NAME "%(AssemblyIdentity.Identity)"' /> |
| 26 | <Line Include='#define DNC_ENTRY_TYPE "$(RootNamespace).BootstrapperApplicationFactory"' /> | 26 | <Line Include='#define DNC_ENTRY_TYPE "$(RootNamespace).BootstrapperApplicationFactory"' /> |
| 27 | <Line Include='#define DNC_ENTRY_TYPEW L"$(RootNamespace).BootstrapperApplicationFactory,$(AssemblyName)"' /> | ||
| 27 | <Line Include='#define DNC_STATIC_ENTRY_METHOD "CreateBAFactory"' /> | 28 | <Line Include='#define DNC_STATIC_ENTRY_METHOD "CreateBAFactory"' /> |
| 29 | <Line Include='#define DNC_STATIC_ENTRY_METHODW L"CreateBAFactory"' /> | ||
| 30 | <Line Include='#define DNC_STATIC_ENTRY_DELEGATEW L"$(RootNamespace).StaticEntryDelegate,$(AssemblyName)"' /> | ||
| 28 | </ItemGroup> | 31 | </ItemGroup> |
| 29 | <Message Importance="normal" Text="Generating identity definitions into @(HeaderPath->'%(FullPath)')" /> | 32 | <Message Importance="normal" Text="Generating identity definitions into @(HeaderPath->'%(FullPath)')" /> |
| 30 | <WriteLinesToFile File="@(HeaderPath)" Lines="@(Line)" Overwrite="True" /> | 33 | <WriteLinesToFile File="@(HeaderPath)" Lines="@(Line)" Overwrite="True" /> |
diff --git a/src/dnchost/dncutil.cpp b/src/dnchost/dncutil.cpp index 996bf086..4a82d961 100644 --- a/src/dnchost/dncutil.cpp +++ b/src/dnchost/dncutil.cpp | |||
| @@ -3,7 +3,9 @@ | |||
| 3 | #include "precomp.h" | 3 | #include "precomp.h" |
| 4 | 4 | ||
| 5 | // https://github.com/dotnet/runtime/blob/master/src/installer/corehost/error_codes.h | 5 | // https://github.com/dotnet/runtime/blob/master/src/installer/corehost/error_codes.h |
| 6 | #define InvalidArgFailure 0x80008081 | ||
| 6 | #define HostApiBufferTooSmall 0x80008098 | 7 | #define HostApiBufferTooSmall 0x80008098 |
| 8 | #define HostApiUnsupportedVersion 0x800080a2 | ||
| 7 | 9 | ||
| 8 | // internal function declarations | 10 | // internal function declarations |
| 9 | 11 | ||
| @@ -24,6 +26,10 @@ static HRESULT InitializeCoreClr( | |||
| 24 | __in HOSTFXR_STATE* pState, | 26 | __in HOSTFXR_STATE* pState, |
| 25 | __in LPCWSTR wzNativeHostPath | 27 | __in LPCWSTR wzNativeHostPath |
| 26 | ); | 28 | ); |
| 29 | static HRESULT InitializeCoreClrPre5( | ||
| 30 | __in HOSTFXR_STATE* pState, | ||
| 31 | __in LPCWSTR wzNativeHostPath | ||
| 32 | ); | ||
| 27 | static HRESULT LoadCoreClr( | 33 | static HRESULT LoadCoreClr( |
| 28 | __in HOSTFXR_STATE* pState, | 34 | __in HOSTFXR_STATE* pState, |
| 29 | __in LPCWSTR wzCoreClrPath | 35 | __in LPCWSTR wzCoreClrPath |
| @@ -75,14 +81,28 @@ HRESULT DnchostCreateFactory( | |||
| 75 | HRESULT hr = S_OK; | 81 | HRESULT hr = S_OK; |
| 76 | PFNCREATEBAFACTORY pfnCreateBAFactory = NULL; | 82 | PFNCREATEBAFACTORY pfnCreateBAFactory = NULL; |
| 77 | 83 | ||
| 78 | hr = pState->pfnCoreclrCreateDelegate( | 84 | if (pState->pfnGetFunctionPointer) |
| 79 | pState->pClrHandle, | 85 | { |
| 80 | pState->dwDomainId, | 86 | hr = pState->pfnGetFunctionPointer( |
| 81 | DNC_ASSEMBLY_FULL_NAME, | 87 | DNC_ENTRY_TYPEW, |
| 82 | DNC_ENTRY_TYPE, | 88 | DNC_STATIC_ENTRY_METHODW, |
| 83 | DNC_STATIC_ENTRY_METHOD, | 89 | DNC_STATIC_ENTRY_DELEGATEW, |
| 84 | reinterpret_cast<void**>(&pfnCreateBAFactory)); | 90 | NULL, |
| 85 | BalExitOnFailure(hr, "Failed to create delegate in app domain."); | 91 | NULL, |
| 92 | reinterpret_cast<void**>(&pfnCreateBAFactory)); | ||
| 93 | BalExitOnFailure(hr, "Failed to create delegate through GetFunctionPointer."); | ||
| 94 | } | ||
| 95 | else | ||
| 96 | { | ||
| 97 | hr = pState->pfnCoreclrCreateDelegate( | ||
| 98 | pState->pClrHandle, | ||
| 99 | pState->dwDomainId, | ||
| 100 | DNC_ASSEMBLY_FULL_NAME, | ||
| 101 | DNC_ENTRY_TYPE, | ||
| 102 | DNC_STATIC_ENTRY_METHOD, | ||
| 103 | reinterpret_cast<void**>(&pfnCreateBAFactory)); | ||
| 104 | BalExitOnFailure(hr, "Failed to create delegate in app domain."); | ||
| 105 | } | ||
| 86 | 106 | ||
| 87 | *ppAppFactory = pfnCreateBAFactory(wzBaFactoryAssemblyName, wzBaFactoryAssemblyPath); | 107 | *ppAppFactory = pfnCreateBAFactory(wzBaFactoryAssemblyName, wzBaFactoryAssemblyPath); |
| 88 | 108 | ||
| @@ -149,6 +169,9 @@ static HRESULT LoadHostfxr( | |||
| 149 | pState->pfnHostfxrClose = reinterpret_cast<hostfxr_close_fn>(::GetProcAddress(hHostfxr, "hostfxr_close")); | 169 | pState->pfnHostfxrClose = reinterpret_cast<hostfxr_close_fn>(::GetProcAddress(hHostfxr, "hostfxr_close")); |
| 150 | BalExitOnNullWithLastError(pState->pfnHostfxrClose, hr, "Failed to get procedure address for hostfxr_close."); | 170 | BalExitOnNullWithLastError(pState->pfnHostfxrClose, hr, "Failed to get procedure address for hostfxr_close."); |
| 151 | 171 | ||
| 172 | pState->pfnHostfxrGetRuntimeDelegate = reinterpret_cast<hostfxr_get_runtime_delegate_fn>(::GetProcAddress(hHostfxr, "hostfxr_get_runtime_delegate")); | ||
| 173 | BalExitOnNullWithLastError(pState->pfnHostfxrGetRuntimeDelegate, hr, "Failed to get procedure address for hostfxr_get_runtime_delegate."); | ||
| 174 | |||
| 152 | LExit: | 175 | LExit: |
| 153 | // Never unload the module since it isn't meant to be unloaded. | 176 | // Never unload the module since it isn't meant to be unloaded. |
| 154 | 177 | ||
| @@ -194,6 +217,28 @@ static HRESULT InitializeCoreClr( | |||
| 194 | ) | 217 | ) |
| 195 | { | 218 | { |
| 196 | HRESULT hr = S_OK; | 219 | HRESULT hr = S_OK; |
| 220 | |||
| 221 | hr = pState->pfnHostfxrGetRuntimeDelegate(pState->hostContextHandle, hdt_get_function_pointer, reinterpret_cast<void**>(&pState->pfnGetFunctionPointer)); | ||
| 222 | if (InvalidArgFailure == hr || // old versions of hostfxr don't allow calling GetRuntimeDelegate from InitializeForApp. | ||
| 223 | HostApiUnsupportedVersion == hr) // hdt_get_function_pointer was added in .NET 5. | ||
| 224 | { | ||
| 225 | hr = InitializeCoreClrPre5(pState, wzNativeHostPath); | ||
| 226 | } | ||
| 227 | else | ||
| 228 | { | ||
| 229 | ExitOnFailure(hr, "HostfxrGetRuntimeDelegate failed"); | ||
| 230 | } | ||
| 231 | |||
| 232 | LExit: | ||
| 233 | return hr; | ||
| 234 | } | ||
| 235 | |||
| 236 | static HRESULT InitializeCoreClrPre5( | ||
| 237 | __in HOSTFXR_STATE* pState, | ||
| 238 | __in LPCWSTR wzNativeHostPath | ||
| 239 | ) | ||
| 240 | { | ||
| 241 | HRESULT hr = S_OK; | ||
| 197 | int32_t rc = 0; | 242 | int32_t rc = 0; |
| 198 | LPCWSTR* rgPropertyKeys = NULL; | 243 | LPCWSTR* rgPropertyKeys = NULL; |
| 199 | LPCWSTR* rgPropertyValues = NULL; | 244 | LPCWSTR* rgPropertyValues = NULL; |
diff --git a/src/dnchost/dncutil.h b/src/dnchost/dncutil.h index 1a7c16e3..85eda3b2 100644 --- a/src/dnchost/dncutil.h +++ b/src/dnchost/dncutil.h | |||
| @@ -14,6 +14,8 @@ struct HOSTFXR_STATE | |||
| 14 | hostfxr_get_runtime_properties_fn pfnHostfxrGetRuntimeProperties; | 14 | hostfxr_get_runtime_properties_fn pfnHostfxrGetRuntimeProperties; |
| 15 | hostfxr_set_error_writer_fn pfnHostfxrSetErrorWriter; | 15 | hostfxr_set_error_writer_fn pfnHostfxrSetErrorWriter; |
| 16 | hostfxr_close_fn pfnHostfxrClose; | 16 | hostfxr_close_fn pfnHostfxrClose; |
| 17 | hostfxr_get_runtime_delegate_fn pfnHostfxrGetRuntimeDelegate; | ||
| 18 | get_function_pointer_fn pfnGetFunctionPointer; | ||
| 17 | coreclr_initialize_ptr pfnCoreclrInitialize; | 19 | coreclr_initialize_ptr pfnCoreclrInitialize; |
| 18 | coreclr_create_delegate_ptr pfnCoreclrCreateDelegate; | 20 | coreclr_create_delegate_ptr pfnCoreclrCreateDelegate; |
| 19 | void* pClrHandle; | 21 | void* pClrHandle; |
diff --git a/src/dnchost/precomp.h b/src/dnchost/precomp.h index d19a0780..84ff6424 100644 --- a/src/dnchost/precomp.h +++ b/src/dnchost/precomp.h | |||
| @@ -24,6 +24,7 @@ | |||
| 24 | #define NETHOST_USE_AS_STATIC | 24 | #define NETHOST_USE_AS_STATIC |
| 25 | #include <nethost.h> | 25 | #include <nethost.h> |
| 26 | #include <hostfxr.h> | 26 | #include <hostfxr.h> |
| 27 | #include <coreclr_delegates.h> | ||
| 27 | 28 | ||
| 28 | #include "coreclrhost.h" | 29 | #include "coreclrhost.h" |
| 29 | #include "dncutil.h" | 30 | #include "dncutil.h" |
