Skip to content
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

Override corehost_resolve_component_dependencies and corehost_set_error_writer PInvokes in singlefile scenario. #60046

Merged
merged 4 commits into from
Oct 6, 2021

Conversation

VSadov
Copy link
Member

@VSadov VSadov commented Oct 6, 2021

Re: #59961

When we embed native runtime/helpers statically in the singlefile host, the host also adds PInvoke overrides, so that PInvokes would still work and use embedded implementation.

What we missed is that the host component itself (hostpolicy) has 2 exported functions accessible from managed libraries via PInvokes. This change adds overrides for these as well.

…error_writer` PInvokes in singlefile scenario.
@ghost
Copy link

ghost commented Oct 6, 2021

Tagging subscribers to this area: @vitek-karas, @agocke, @VSadov
See info in area-owners.md if you want to be subscribed.

Issue Details

Re: #59961

Author: VSadov
Assignees: -
Labels:

area-Host

Milestone: -

Copy link
Member

@vitek-karas vitek-karas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

@vitek-karas
Copy link
Member

We should try to backport this to 6.0

@vitek-karas
Copy link
Member

The fix for the test failures should be in VSadov#3.

@@ -55,11 +56,15 @@ namespace
const void* STDMETHODCALLTYPE pinvoke_override(const char* libraryName, const char* entrypointName)
{
#if defined(_WIN32)
const char* hostPolicyLib = "hostpolicy.dll";
Copy link
Member

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 and libhostpolicy on Unix?

Copy link
Member Author

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

internal const string HostPolicy = "hostpolicy.dll";

and

internal const string HostPolicy = "libhostpolicy";

hostpolicy seems to be using a naming approach that is different from System.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.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tracking issue: #60080

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, Thanks!

if (strcmp(entrypointName, "corehost_set_error_writer") == 0)
{
return (void*)corehost_set_error_writer;
}
Copy link
Member

@am11 am11 Oct 6, 2021

Choose a reason for hiding this comment

The 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
}
}
trace::warning(_X("Hostpolicy P/Invoke override for [%s] was not found in the bundle bundle."), entrypointName);
assert(false); // all cases should be handled above

Copy link
Member Author

Choose a reason for hiding this comment

The 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.

Copy link
Member Author

Choose a reason for hiding this comment

The 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.
Otherwise it should be a "method missing" exception that can be caught and handled/ignored.

I think this part should stay as-is.

Fixes the test failures when hostpolicy is used at runtime.
@VSadov VSadov marked this pull request as ready for review October 6, 2021 19:36
@VSadov
Copy link
Member Author

VSadov commented Oct 6, 2021

The windows x86 Debug failure is happening in other runs too - #60097

@VSadov VSadov merged commit bbc898f into dotnet:main Oct 6, 2021
@VSadov VSadov deleted the plugins branch October 6, 2021 23:52
@VSadov
Copy link
Member Author

VSadov commented Oct 7, 2021

/backport to release/6.0

@github-actions
Copy link
Contributor

github-actions bot commented Oct 7, 2021

Started backporting to release/6.0: https://github.com/dotnet/runtime/actions/runs/1314783140

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants