summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeremy Koritzinsky <jkoritzinsky@gmail.com>2019-01-18 23:39:54 (GMT)
committerGitHub <noreply@github.com>2019-01-18 23:39:54 (GMT)
commit0c6ad4c8d3869b54364b15f21b8b6b5a6fe7a94a (patch)
tree256d6ab0839dfd15a85fb72c02018d06ed541b3e
parent87fb9af12afb29087a818bd588037996a97bf000 (diff)
downloadcoreclr-0c6ad4c8d3869b54364b15f21b8b6b5a6fe7a94a.zip
coreclr-0c6ad4c8d3869b54364b15f21b8b6b5a6fe7a94a.tar.gz
coreclr-0c6ad4c8d3869b54364b15f21b8b6b5a6fe7a94a.tar.bz2
Fix calling conventions on reverse PInvoke callbacks. (#22044)
-rw-r--r--src/System.Private.CoreLib/src/System/Runtime/Loader/AssemblyDependencyResolver.cs5
-rw-r--r--tests/src/Loader/AssemblyDependencyResolverTests/HostPolicyMock.cs10
2 files changed, 10 insertions, 5 deletions
diff --git a/src/System.Private.CoreLib/src/System/Runtime/Loader/AssemblyDependencyResolver.cs b/src/System.Private.CoreLib/src/System/Runtime/Loader/AssemblyDependencyResolver.cs
index a05b71c..f1a2a1f 100644
--- a/src/System.Private.CoreLib/src/System/Runtime/Loader/AssemblyDependencyResolver.cs
+++ b/src/System.Private.CoreLib/src/System/Runtime/Loader/AssemblyDependencyResolver.cs
@@ -64,6 +64,7 @@ namespace System.Runtime.Loader
{
// Reset the error write to the one used before
corehost_set_error_writer(previousErrorWriterPtr);
+ GC.KeepAlive(errorWriter);
}
}
catch (EntryPointNotFoundException entryPointNotFoundException)
@@ -289,13 +290,13 @@ namespace System.Runtime.Loader
}
#endif
- [UnmanagedFunctionPointer(CallingConvention.Cdecl, CharSet = HostpolicyCharSet)]
+ [UnmanagedFunctionPointer(CallingConvention.Winapi, CharSet = HostpolicyCharSet)]
internal delegate void corehost_resolve_component_dependencies_result_fn(
string assembly_paths,
string native_search_paths,
string resource_search_paths);
- [UnmanagedFunctionPointer(CallingConvention.Cdecl, CharSet = HostpolicyCharSet)]
+ [UnmanagedFunctionPointer(CallingConvention.Winapi, CharSet = HostpolicyCharSet)]
internal delegate void corehost_error_writer_fn(
string message);
diff --git a/tests/src/Loader/AssemblyDependencyResolverTests/HostPolicyMock.cs b/tests/src/Loader/AssemblyDependencyResolverTests/HostPolicyMock.cs
index 1c212ef..ca4d698 100644
--- a/tests/src/Loader/AssemblyDependencyResolverTests/HostPolicyMock.cs
+++ b/tests/src/Loader/AssemblyDependencyResolverTests/HostPolicyMock.cs
@@ -28,7 +28,7 @@ namespace AssemblyDependencyResolverTests
[DllImport("hostpolicy", CharSet = HostpolicyCharSet)]
private static extern IntPtr Get_corehost_set_error_writer_lastSet_error_writer();
- [UnmanagedFunctionPointer(CallingConvention.Cdecl, CharSet = HostpolicyCharSet)]
+ [UnmanagedFunctionPointer(CallingConvention.Winapi, CharSet = HostpolicyCharSet)]
internal delegate void Callback_corehost_resolve_component_dependencies(
string component_main_assembly_path);
@@ -39,7 +39,7 @@ namespace AssemblyDependencyResolverTests
private static Type _assemblyDependencyResolverType;
private static Type _corehost_error_writer_fnType;
- [UnmanagedFunctionPointer(CallingConvention.Cdecl, CharSet = HostpolicyCharSet)]
+ [UnmanagedFunctionPointer(CallingConvention.Winapi, CharSet = HostpolicyCharSet)]
public delegate void ErrorWriterDelegate(string message);
public static string DeleteExistingHostpolicy(string coreRoot)
@@ -88,11 +88,13 @@ namespace AssemblyDependencyResolverTests
internal class MockValues_corehost_resolve_componet_dependencies : IDisposable
{
+ private Callback_corehost_resolve_component_dependencies callback;
+
public Action<string> Callback
{
set
{
- var callback = new Callback_corehost_resolve_component_dependencies(value);
+ callback = new Callback_corehost_resolve_component_dependencies(value);
if (callback != null)
{
Set_corehost_resolve_component_dependencies_Callback(
@@ -113,6 +115,8 @@ namespace AssemblyDependencyResolverTests
string.Empty,
string.Empty);
Set_corehost_resolve_component_dependencies_Callback(IntPtr.Zero);
+ GC.KeepAlive(callback);
+ callback = null;
}
}