-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Implement NativeLibrary.GetEntryPointModuleHandle #57610
Implement NativeLibrary.GetEntryPointModuleHandle #57610
Conversation
…gn to make it easier to share QCalls and to hook them up in Mono.
…can be used as a QCall entrypoint in Mono.
Note regarding the This serves as a reminder for when your PR is modifying a ref *.cs file and adding/modifying public APIs, to please make sure the API implementation in the src *.cs file is documented with triple slash comments, so the PR reviewers can sign off that change. |
src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/NativeLibrary.cs
Show resolved
Hide resolved
src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/NativeLibrary.cs
Outdated
Show resolved
Hide resolved
In this specific case, it would be even better to move the unmanaged part to src/libraries/Native (it is done that way in NativeAOT already) so the whole thing can be shared. I understand that it would be more work. |
I didn't want to do that initially since Mono already has some special handling for If I do move it, I'd like to leave the mono QCall infra in this PR (or worst case move it into another PR) to make it easier to add QCalls to Mono in the future. |
src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/NativeLibrary.cs
Outdated
Show resolved
Hide resolved
…one without having to follow the pattern (makes it easier to remove this new QCall and move it to the libraries native portion)
… prototype (it's no longer exposed outside native-library.c since it's no longer used in a QCall)
…untime into nativelibrary_entrymodule
…ble-free check against. P/Invoking messes up the ref-counts since the runtime loads the native library, so the double free test didn't work.
All of the test failures are unrelated. This is finally ready for review! |
src/tests/Interop/NativeLibrary/NativeLibraryToLoad/GlobalLoadHelper.cpp
Show resolved
Hide resolved
src/tests/Interop/NativeLibrary/NativeLibraryToLoad/CMakeLists.txt
Outdated
Show resolved
Hide resolved
Test failures are #66852. Merging now to make sure we get in for Preview 3 |
static void* g_defaultSearchOrderPseudoHandle = NULL; | ||
void* SystemNative_GetDefaultSearchOrderPseudoHandle(void) | ||
{ | ||
if (g_defaultSearchOrderPseudoHandle == 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.
This has potential race condition depending on how the C++ decides to compile it. The C/C++ compiler is free to reorder the if check and reading of g_defaultSearchOrderPseudoHandle
to return. It means that the method can return NULL instead of the actual value.
This is real problem. We had many bugs like that over the years - they are always very hard to trace down.
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.
This can be fixed by making g_defaultSearchOrderPseudoHandle
volatile, correct?
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.
Yup. Also, you may want to cache the value in a local so that it does not need to be fetched from memory twice.
Fixes #56331
Fixes #7267
I know there was a continuing discussion on naming, so we can continue that here if we so desire.
cc: @jkotas @AaronRobinsonMSFT @lambdageek