-
Notifications
You must be signed in to change notification settings - Fork 5k
Override corehost_resolve_component_dependencies
and corehost_set_error_writer
PInvokes in singlefile scenario.
#60046
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
6d35e41
f909924
74d0f19
4ababdb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -2,6 +2,7 @@ | |||||||||||
// The .NET Foundation licenses this file to you under the MIT license. | ||||||||||||
|
||||||||||||
#include "hostpolicy_context.h" | ||||||||||||
#include "hostpolicy.h" | ||||||||||||
|
||||||||||||
#include "deps_resolver.h" | ||||||||||||
#include <error_codes.h> | ||||||||||||
|
@@ -55,11 +56,15 @@ namespace | |||||||||||
const void* STDMETHODCALLTYPE pinvoke_override(const char* libraryName, const char* entrypointName) | ||||||||||||
{ | ||||||||||||
#if defined(_WIN32) | ||||||||||||
const char* hostPolicyLib = "hostpolicy.dll"; | ||||||||||||
|
||||||||||||
if (strcmp(libraryName, "System.IO.Compression.Native") == 0) | ||||||||||||
{ | ||||||||||||
return CompressionResolveDllImport(entrypointName); | ||||||||||||
} | ||||||||||||
#else | ||||||||||||
const char* hostPolicyLib = "libhostpolicy"; | ||||||||||||
|
||||||||||||
if (strcmp(libraryName, "libSystem.IO.Compression.Native") == 0) | ||||||||||||
{ | ||||||||||||
return CompressionResolveDllImport(entrypointName); | ||||||||||||
|
@@ -80,6 +85,19 @@ namespace | |||||||||||
return CryptoResolveDllImport(entrypointName); | ||||||||||||
} | ||||||||||||
#endif | ||||||||||||
// there are two PInvokes in the hostpolicy itself, redirect them here. | ||||||||||||
if (strcmp(libraryName, hostPolicyLib) == 0) | ||||||||||||
{ | ||||||||||||
if (strcmp(entrypointName, "corehost_resolve_component_dependencies") == 0) | ||||||||||||
{ | ||||||||||||
return (void*)corehost_resolve_component_dependencies; | ||||||||||||
} | ||||||||||||
|
||||||||||||
if (strcmp(entrypointName, "corehost_set_error_writer") == 0) | ||||||||||||
{ | ||||||||||||
return (void*)corehost_set_error_writer; | ||||||||||||
} | ||||||||||||
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. An assert and a warning after this block might help us catch other cases in the future. Something like:
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is ok for any user to try calling methods that do not exist in hostpolicy. It is also (although very unlikely) that unrelated hostpolicy.dll may exist and user PInvokes something from it that is real. Also there could be additional overrides registered at higher level, - in theory. Basically, while very unlikely, there could be scenarios when not finding an override for a hostpolicy PInvoke is expected and ok. I think, as a matter of testing in controlled environment, an assert makes sense here, but not a warning, since, strictly speaking this is not a failure. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually even an assert could become a blocking nuisance if someone needs to use Checked/Debug build and there is a call to something that does not exist in hostpolicy. I think this part should stay as-is. |
||||||||||||
} | ||||||||||||
|
||||||||||||
#if defined(TARGET_OSX) | ||||||||||||
if (strcmp(libraryName, "libSystem.Security.Cryptography.Native.Apple") == 0) | ||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the extension needed for hostpolicy, but not for
System.IO.Compression.Native
on Windows andlibhostpolicy
on Unix?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is the differences between
runtime/src/libraries/Common/src/Interop/Windows/Interop.Libraries.cs
Line 46 in be91858
and
runtime/src/libraries/Common/src/Interop/Unix/Interop.Libraries.cs
Line 15 in be91858
hostpolicy
seems to be using a naming approach that is different fromSystem.IO.Compression.Native
and I am not sure if there are reasons for that of if changing could introduce any additional risk.It could be worth to consider removing the ".dll" in 7.0.
This fix will be likely ported to 6.0, so I think it should not be in this change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tracking issue: #60080
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, Thanks!