-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Conversation
src/System.Private.CoreLib/src/System/Runtime/Loader/AssemblyLoadContext.cs
Show resolved
Hide resolved
|
||
if (dllResolveHandler != null) | ||
{ | ||
// Loop through the event subscribers and return the first non-null Assembly instance |
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.
return the first non-null Assembly instance
Copy&paste. This is not returning Assembly instances...
@@ -509,7 +540,22 @@ internal static void OnProcessExit() | |||
} | |||
} | |||
|
|||
/// Event handler for resolving native libraries. |
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.
If you want to use ///
comments, you have to make them a valid XML.
I do have a quick questions about the ordering here. What is the expectation of there being an app local native library that is the wrong version, but the user wants a different version with the same name. In the current algorithm, the app local version would be found first and the defined callback wouldn't be found. Is this what we want? In the below directory layout, would the application ever get the chance to load
|
This fallback does not help you with that. You have to use other ways to solve this - the NativeLibrary APIs, do not deploy bad applocal library, etc. No different from how would you solve the same situation for C/C++ code. |
Other than the fact that if the user defined a P/Invoke that is now no longer valid and it isn't obvious that the wrong library was loaded until the extension library or app developer gets a very unexpected bug. Not arguing if this is or isn't the wrong approach, just wanted to clarify this is the intent. So our expectation here is that the events are for P/Invokes with a well structured app layout that is known to app and potential plugin developers. In the event there is a situation where non-versioned libraries can pollute the loader paths, using the |
Yes the primary motivation for the native library resolve event is resolution for plugins. The app and it components have to agree on native-library versions to avoid problems with native libraries in the app-global scope. |
tests/src/Interop/NativeLibraryResolveEvent/ResolveEventTests.cs
Outdated
Show resolved
Hide resolved
Thanks @AaronRobinsonMSFT I've made the additional changes. |
@dotnet-bot test Windows_NT arm Cross Checked Innerloop Build and Test |
@adityamandaleeka and I Iooked at the failure on ARM64. The Until this is fixed, I'll disable the test on ARM64 Windows. |
@swaroop-sridhar The assertion is familiar, but of course it could be getting triggered in this case for a completely different reason than previous occurrences. I'll investigate what's going on with EH in this situation. Thanks for reporting it! |
src/vm/dllimport.cpp
Outdated
@@ -6656,27 +6736,37 @@ HINSTANCE NDirect::LoadLibraryModule(NDirectMethodDesc * pMD, LoadLibErrorTracke | |||
if (SString::_wcsicmp(wszLibName, MAIN_CLR_MODULE_NAME_W) == 0) | |||
{ | |||
hmod = GetCLRModule(); | |||
if (hmod == NULL) |
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.
Should this condition rather be if (hmod != NULL)
?
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.
Also, do we need the check for NULL at all? This should never be NULL.
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.
I am surprised that this is not causing things to fail. It looks like that this special path that checks for MAIN_CLR_MODULE_NAME_W
is probably just dead code and can be just deleted.
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.
Yes, sorry, fixed it.
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.
Could you please rather just delete it?
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.
I've fixed the comparison for now. I'll remove the check along with the PAL registration cleanup in another upcoming PR.
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.
@janvorli can you please confirm if this check is now defunct? Thanks.
https://github.com/dotnet/coreclr/blob/master/src/vm/dllimport.cpp#L6657-L6667
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.
Yes, this is defunct. The few places that PInvoke into coreclr in CoreLib use the proper name (libcoreclr) and I expect we will get rid of those few places too at some point.
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.
Thanks for the explanation, I deleted the code.
e78519f
to
678c6dd
Compare
@dotnet-bot test Windows_NT arm Cross Checked Innerloop Build and Test |
This change adds the Native library resolving event, to be raised as the last attempt to resolve a native DLL in an AssemblyLoadContext. With this change, the DllImport resolution sequence is as follows (stopping at any step with successful resolution): * If the invoking-assembly is not in the default load context, call AssemblyLoadContext.LoadUnmanagedDll() * Run the default load logic, try loading from: * AppDomain cache * NATIVE_DLL_SEARCH_DIRECTORIES * Invoking-assembly directory, System32, etc. based on DllImportSearchPaths * Raise the ResolvingUnmanagedDll event API Review: https://github.com/dotnet/corefx/issues/32850 The ResolveEventTests triggered a pre-existing bug in the exception handling code (#21964). Disabling the test on ARM64 Windows until the issue is fixed.
678c6dd
to
5ceff61
Compare
The "Tizen armel Cross Checked Innerloop Build and Test" leg is failing in every build, and looks unrelated. So will merge the change. |
This change adds the Native library resolving event, to be raised as the last attempt to resolve a native DLL in an AssemblyLoadContext. With this change, the DllImport resolution sequence is as follows (stopping at any step with successful resolution): * If the invoking-assembly is not in the default load context, call AssemblyLoadContext.LoadUnmanagedDll() * Run the default load logic, try loading from: * AppDomain cache * NATIVE_DLL_SEARCH_DIRECTORIES * Invoking-assembly directory, System32, etc. based on DllImportSearchPaths * Raise the ResolvingUnmanagedDll event API Review: https://github.com/dotnet/corefx/issues/32850 The ResolveEventTests triggered a pre-existing bug in the exception handling code (dotnet/coreclr#21964). Disabling the test on ARM64 Windows until the issue is fixed. Commit migrated from dotnet/coreclr@8b7d300
This change adds the Native library resolving event, to be raised as the last attempt to resolve a native DLL in an AssemblyLoadContext.
With this change, the DllImport resolution sequence is as follows (stopping at any step with successful resolution):
API Review: https://github.com/dotnet/corefx/issues/32850