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

[loader] Call managed resolving events for the default ALC #56398

Merged
merged 3 commits into from
Jul 30, 2021

Conversation

lambdageek
Copy link
Member

Refine the work in f70b5b7

The issue is that even if we know that the ALC gchandle points to null in native, we can't automatically skip the call to the managed resolving event (for native library, for example) because the native event is indirectly responsible for creating the default ALC managed object.

Instead, check in native if the gchandle is equal to the default ALC's gchandle (which is initially allocated with a null target) and if so pass IntPtr.Zero to the managed code, which will call AssemblyLoadContext.GetAssemblyLoadContext (IntPtr gch) which in turn will construct the managed object for the default ALC.

Fixes #55921

Refine the work in
dotnet@f70b5b7

The issue is that even if we know that the ALC gchandle points to null in
native, we can't automatically skip the call to the managed resolving
event (for native library, for example) because the native event is indirectly
responsible for creating the default ALC managed object.

Instead, check in native if the gchandle is equal to the default ALC's
gchandle (which is initially allocated with a null target) and if so pass
IntPtr.Zero to the managed code, which will call
`AssemblyLoadContext.GEtAssemblyLoadContext (IntPtr gch)` which in turn will
construct the managed object for the default ALC.

Fixes dotnet#55921
@ghost
Copy link

ghost commented Jul 27, 2021

Tagging subscribers to this area:
See info in area-owners.md if you want to be subscribed.

Issue Details

Refine the work in f70b5b7

The issue is that even if we know that the ALC gchandle points to null in native, we can't automatically skip the call to the managed resolving event (for native library, for example) because the native event is indirectly responsible for creating the default ALC managed object.

Instead, check in native if the gchandle is equal to the default ALC's gchandle (which is initially allocated with a null target) and if so pass IntPtr.Zero to the managed code, which will call AssemblyLoadContext.GetAssemblyLoadContext (IntPtr gch) which in turn will construct the managed object for the default ALC.

Fixes #55921

Author: lambdageek
Assignees: -
Labels:

area-AssemblyLoader-mono

Milestone: -

@lambdageek
Copy link
Member Author

@uweigand can you try this on the s390 port and check whether it resolves the issue? Also do you know what might be a good way to do a standalone repro?

@uweigand
Copy link
Contributor

@uweigand can you try this on the s390 port and check whether it resolves the issue?

Sure, I'll try this (latest version) and let you know ...

Also do you know what might be a good way to do a standalone repro?

Unfortunately not really, I was only seeing this with roslyn analzers. Not sure what exactly those do to trigger the issue ...

@uweigand
Copy link
Contributor

@lambdageek This patch does indeed fix the problem I was seeing, thanks!

@lambdageek
Copy link
Member Author

/backport to release/6.0-preview7

@github-actions
Copy link
Contributor

Started backporting to release/6.0-preview7: https://github.com/dotnet/runtime/actions/runs/1072400612

@lambdageek lambdageek merged commit 0b96651 into dotnet:main Jul 30, 2021
@ghost ghost locked as resolved and limited conversation to collaborators Aug 29, 2021
@lambdageek lambdageek deleted the fix-gh-55921 branch March 19, 2022 16:45
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.

[mono] Crash in roslyn due to null AssemblyLoadContext.GetLoadContext result
4 participants