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
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -126,24 +126,14 @@ public void StartProfileOptimization(string? profile)
// success.
private static Assembly? MonoResolveUsingResolvingEvent(IntPtr gchALC, string assemblyName)
{
AssemblyLoadContext context;
// This check exists because the function can be called early in startup, before the default ALC is initialized
if (gchALC == IntPtr.Zero)
context = Default;
else
context = (AssemblyLoadContext)(GCHandle.FromIntPtr(gchALC).Target)!;
AssemblyLoadContext context = GetAssemblyLoadContext(gchALC);
return context.ResolveUsingEvent(new AssemblyName(assemblyName));
}

// Invoked by Mono to resolve requests to load satellite assemblies.
private static Assembly? MonoResolveUsingResolveSatelliteAssembly(IntPtr gchALC, string assemblyName)
{
AssemblyLoadContext context;
// This check exists because the function can be called early in startup, before the default ALC is initialized
if (gchALC == IntPtr.Zero)
context = Default;
else
context = (AssemblyLoadContext)(GCHandle.FromIntPtr(gchALC).Target)!;
AssemblyLoadContext context = GetAssemblyLoadContext(gchALC);
return context.ResolveSatelliteAssembly(new AssemblyName(assemblyName));
}

Expand Down
12 changes: 8 additions & 4 deletions src/mono/mono/metadata/assembly-load-context.c
Original file line number Diff line number Diff line change
Expand Up @@ -445,9 +445,6 @@ invoke_resolve_method (MonoMethod *resolve_method, MonoAssemblyLoadContext *alc,
if (mono_runtime_get_no_exec ())
return NULL;

if (!mono_gchandle_get_target_internal (alc->gchandle))
return NULL;

HANDLE_FUNCTION_ENTER ();

aname_str = mono_stringify_assembly_name (aname);
Expand All @@ -457,7 +454,14 @@ invoke_resolve_method (MonoMethod *resolve_method, MonoAssemblyLoadContext *alc,

MonoReflectionAssemblyHandle assm;
gpointer gchandle;
gchandle = (gpointer)alc->gchandle;
/* for the default ALC, pass NULL to ask for the Default ALC - see
vargaz marked this conversation as resolved.
Show resolved Hide resolved
* AssemblyLoadContext.GetAssemblyLoadContext(IntPtr gchManagedAssemblyLoadContext) - which
* will create the managed ALC object if it hasn't been created yet
*/
if (alc->gchandle == default_alc->gchandle)
gchandle = NULL;
else
gchandle = GUINT_TO_POINTER (alc->gchandle);
gpointer args [2];
args [0] = &gchandle;
args [1] = MONO_HANDLE_RAW (aname_obj);
Expand Down
21 changes: 16 additions & 5 deletions src/mono/mono/metadata/native-library.c
Original file line number Diff line number Diff line change
Expand Up @@ -628,17 +628,21 @@ netcore_resolve_with_load (MonoAssemblyLoadContext *alc, const char *scope, Mono
if (mono_runtime_get_no_exec ())
return NULL;

if (!mono_gchandle_get_target_internal (alc->gchandle))
return NULL;

HANDLE_FUNCTION_ENTER ();

MonoStringHandle scope_handle;
scope_handle = mono_string_new_handle (scope, error);
goto_if_nok (error, leave);

gpointer gchandle;
gchandle = GUINT_TO_POINTER (alc->gchandle);
/* for the default ALC, pass NULL to ask for the Default ALC - see
* AssemblyLoadContext.GetAssemblyLoadContext(IntPtr gchManagedAssemblyLoadContext) - which
* will create the managed ALC object if it hasn't been created yet
*/
if (alc->gchandle == mono_alc_get_default ()->gchandle)
gchandle = NULL;
else
gchandle = GUINT_TO_POINTER (alc->gchandle);
gpointer args [3];
args [0] = MONO_HANDLE_RAW (scope_handle);
args [1] = &gchandle;
Expand Down Expand Up @@ -708,7 +712,14 @@ netcore_resolve_with_resolving_event (MonoAssemblyLoadContext *alc, MonoAssembly
goto_if_nok (error, leave);

gpointer gchandle;
lambdageek marked this conversation as resolved.
Show resolved Hide resolved
gchandle = GUINT_TO_POINTER (alc->gchandle);
/* for the default ALC, pass NULL to ask for the Default ALC - see
* AssemblyLoadContext.GetAssemblyLoadContext(IntPtr gchManagedAssemblyLoadContext) - which
* will create the managed ALC object if it hasn't been created yet
*/
if (alc->gchandle == mono_alc_get_default ()->gchandle)
gchandle = NULL;
else
gchandle = GUINT_TO_POINTER (alc->gchandle);
gpointer args [4];
args [0] = MONO_HANDLE_RAW (scope_handle);
args [1] = MONO_HANDLE_RAW (assembly_handle);
Expand Down