-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Conversation
src/vm/dllimport.cpp
Outdated
// Local helper function for the LoadLibraryModule function below | ||
// Local helper function to load a library. | ||
// Load the library directly, and don't register it yet with PAL. Returns the native system libray handle. | ||
// * External callers likeAssemblyNative::InternalLoadUnmanagedDllFromPath() and the upcoming |
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.
"like AssemblyNative::InternalLoadUnmanagedDllFromPath()"
src/vm/dllimport.cpp
Outdated
// Load the library directly, and don't register it yet with PAL. Returns the native system libray handle. | ||
// * External callers likeAssemblyNative::InternalLoadUnmanagedDllFromPath() and the upcoming | ||
// System.Runtime.Interop.Marshall.LoadLibrary() need the raw system handle | ||
// * Internal callers like LoadLibraryModule() can obrain it via PAL_RegisterLibraryDirect() |
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.
"obtain"
*szComma = '\0'; | ||
while (COMCharacter::nativeIsWhiteSpace(*(++szComma))); | ||
*szComma = '\0'; | ||
while (COMCharacter::nativeIsWhiteSpace(*(++szComma))); |
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.
Please move the ;
to the next line or comment that we are trimming here.
@swaroop-sridhar I am sorry for the delay, I was focusing on other stuff. I am planning to review this later today. |
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.
One thing to consider. You have added comments describing when the HMODULE is actually the native handle, which is great. But I wonder if it would be even better to change the return type of these functions to VOID*.
src/vm/dllimport.cpp
Outdated
@@ -6069,7 +6069,13 @@ class LoadLibErrorTracker | |||
SString m_message; | |||
}; // class LoadLibErrorTracker | |||
|
|||
// Local helper function for the LoadLibraryModule function below | |||
// Local helper function to load a library. | |||
// Load the library directly, and don't register it yet with PAL. Returns the native system libray handle. |
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.
A nit - maybe update to "don't register it yet with PAL on Unix" as there is no PAL on Windows. There is another place with a similar comment.
src/vm/dllimport.cpp
Outdated
|
||
if (pMD->HasDefaultDllImportSearchPathsAttribute()) | ||
if(pModule->HasDefaultDllImportSearchPathsAttribute()) |
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.
A nit - missing space after if
at multiple places. I know it didn't come from your change, but it would be nice to fix when you are editing the code.
src/vm/dllimport.cpp
Outdated
// System.Runtime.Interop.Marshall.LoadLibrary() need the raw system handle | ||
// * Internal callers like LoadLibraryModule() can obrain it via PAL_RegisterLibraryDirect() | ||
// | ||
// This method returns native system libray handle not registered with the PAL |
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.
A nit: libray -> library (multiple places)
src/vm/dllimport.cpp
Outdated
// First checks if the method has DefaultDllImportSearchPathsAttribute. If method has the attribute | ||
// then dllImportSearchPathFlag is set to its value. | ||
// Otherwise checks if the assembly has the attribute. | ||
// If assembly has the attribute then flag ise set to its value. |
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.
A nit: ise -> is
Or even better: define |
I thought about this, but held back because the types defined in I'll make the change now. |
Thanks for the feedback @janvorli @jkotas @AaronRobinsonMSFT |
src/pal/inc/pal.h
Outdated
// In Windows, NATIVE_LIBRARY_HANDLE is the same as HMODULE. | ||
// On Unix systems, NATIVE_LIBRARY_HANDLE type represents a library handle not registered with the PAL. | ||
// To get a HMODULE on Unix, call PAL_RegisterLibraryDirect() on a NATIVE_LIBRARY_HANDLE. | ||
typedef HANDLE NATIVE_LIBRARY_HANDLE; |
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.
A nit - the dlopen returns void*, so it would be cleaner to define it that way.
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, I cannot see the type definition for Windows. The pal.h is included for Unix only.
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 added a definition in common.h
, for the !FEATURE_PAL
case Thanks
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.
inc/palclr.h would be a better place for it. It is where all similar definitions are.
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, I changed the Windows definition to be in palclr.h via palclr_win.h
7b14435
to
220797a
Compare
@dotnet-bot test dotnet-coreclr |
@dotnet-bot test Ubuntu x64 Checked CoreFX Tests |
This change refactors the code in DllImport in preparation for implementing the new NativeLibrary API here: dotnet/corefx#32015 The two main changes are: 1) A change in the semantics of the internal LoadLibrary helper functions. When a native library is loaded, there are two categories of callers expecting different return values: External callers like AssemblyNative::InternalLoadUnmanagedDllFromPath() and the upcoming System.Runtime.Interop.Marshall.LoadLibrary() need the raw system handle Internal callers like LoadLibraryModule() need the PAL registered handle This change modifies the internal LoadLibraryModule* methods to work in terms of native system handles, so that external callers can obrain them directly. Methods requiring PAL-handles can register them explicitly. There is no change in external signature of DllImport class, or the native Dll cache in AppDomain class. 2) Differentiate HMODULE and NATIVE_LIBRARY_HANDLE This change defines NATIVE_LIBRARY_HANDLE type to represent raw system handles to native libraries that are not registered with the PAL (On Unix systems). The types on PAL and DlImport methods are adjusted to make this semantic distinction explicit.
ec861ec
to
0a0077c
Compare
@dotnet-bot test this please |
* Refactor LoadLibrary Methods This change refactors the code in DllImport in preparation for implementing the new NativeLibrary API here: dotnet/corefxdotnet/coreclr#32015 The two main changes are: 1) A change in the semantics of the internal LoadLibrary helper functions. When a native library is loaded, there are two categories of callers expecting different return values: External callers like AssemblyNative::InternalLoadUnmanagedDllFromPath() and the upcoming System.Runtime.Interop.Marshall.LoadLibrary() need the raw system handle Internal callers like LoadLibraryModule() need the PAL registered handle This change modifies the internal LoadLibraryModule* methods to work in terms of native system handles, so that external callers can obrain them directly. Methods requiring PAL-handles can register them explicitly. There is no change in external signature of DllImport class, or the native Dll cache in AppDomain class. 2) Differentiate HMODULE and NATIVE_LIBRARY_HANDLE This change defines NATIVE_LIBRARY_HANDLE type to represent raw system handles to native libraries that are not registered with the PAL (On Unix systems). The types on PAL and DlImport methods are adjusted to make this semantic distinction explicit. * Fix loading LibC via PAL_LoadLibraryDirect() Commit migrated from dotnet/coreclr@214c3b6
This change refactors the code in DllImport in preparation
for implementing the new NativeLibrary API here:
dotnet/corefx#32015
In particular, it introduces a change in the semantics of the
internal LoadLibrary helper functions.
When a native library is loaded, there are two categories of callers
expecting different return values:
and the upcoming System.Runtime.Interop.Marshall.LoadLibrary()
need the raw system handle
This change modifies the internal LoadLibraryModule* methods to work
in terms of native system handles, so that external callers can obrain
them directly. Methods requiring PAL-handles can register them explicitly.
[PS: NDirect::LoadLibraryFromPath was already written to return the
system handle instead of the PAL handle. This change extends
the behavior to other private members.]
There is no change in external signature of DllImport class, or the
native Dll cache in AppDomain class.