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

Implement NativeLibrary.GetEntryPointModuleHandle #57610

Merged
merged 42 commits into from
Mar 21, 2022

Conversation

jkoritzinsky
Copy link
Member

@jkoritzinsky jkoritzinsky commented Aug 17, 2021

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

@dotnet-issue-labeler
Copy link

Note regarding the new-api-needs-documentation label:

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.

@AaronRobinsonMSFT AaronRobinsonMSFT added this to the 7.0.0 milestone Aug 17, 2021
@jkotas
Copy link
Member

jkotas commented Aug 17, 2021

Bring in some more QCall infrastructure that matches the CoreCLR

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.

@jkoritzinsky
Copy link
Member Author

Bring in some more QCall infrastructure that matches the CoreCLR

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 __Internal that I wanted to piggy-back on and it felt weird to have most of NativeLibrary be implemented in the runtimes but have one method implemented in src/libraries/Native, but I can move it there if we want.

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.

…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)
@jkoritzinsky jkoritzinsky marked this pull request as ready for review March 18, 2022 02:00
@jkoritzinsky
Copy link
Member Author

All of the test failures are unrelated. This is finally ready for review!

@jkoritzinsky
Copy link
Member Author

Test failures are #66852.

Merging now to make sure we get in for Preview 3

@jkoritzinsky jkoritzinsky merged commit e22ebdf into dotnet:main Mar 21, 2022
@jkoritzinsky jkoritzinsky deleted the nativelibrary_entrymodule branch March 21, 2022 17:08
static void* g_defaultSearchOrderPseudoHandle = NULL;
void* SystemNative_GetDefaultSearchOrderPseudoHandle(void)
{
if (g_defaultSearchOrderPseudoHandle == NULL)
Copy link
Member

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.

Copy link
Member Author

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?

Copy link
Member

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.

radekdoulik pushed a commit to radekdoulik/runtime that referenced this pull request Mar 30, 2022
@ghost ghost locked as resolved and limited conversation to collaborators Apr 20, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
7 participants