Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 1 addition & 5 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 @@ -456,8 +453,7 @@ invoke_resolve_method (MonoMethod *resolve_method, MonoAssemblyLoadContext *alc,
goto_if_nok (error, leave);

MonoReflectionAssemblyHandle assm;
gpointer gchandle;
gchandle = (gpointer)alc->gchandle;
gpointer gchandle = mono_alc_get_gchandle_for_resolving (alc);
gpointer args [2];
args [0] = &gchandle;
args [1] = MONO_HANDLE_RAW (aname_obj);
Expand Down
13 changes: 13 additions & 0 deletions src/mono/mono/metadata/loader-internals.h
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,19 @@ mono_alc_get_ambient (void)
return mono_alc_get_default ();
}

static inline MonoGCHandle
mono_alc_get_gchandle_for_resolving (MonoAssemblyLoadContext *alc)
{
/* 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)
return NULL;
else
return GUINT_TO_POINTER (alc->gchandle);
}

MonoAssemblyLoadContext *
mono_alc_from_gchandle (MonoGCHandle alc_gchandle);

Expand Down
12 changes: 2 additions & 10 deletions src/mono/mono/metadata/native-library.c
Original file line number Diff line number Diff line change
Expand Up @@ -628,17 +628,13 @@ 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);
gpointer gchandle = mono_alc_get_gchandle_for_resolving (alc);
gpointer args [3];
args [0] = MONO_HANDLE_RAW (scope_handle);
args [1] = &gchandle;
Expand Down Expand Up @@ -694,9 +690,6 @@ netcore_resolve_with_resolving_event (MonoAssemblyLoadContext *alc, MonoAssembly
if (mono_runtime_get_no_exec ())
return NULL;

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

HANDLE_FUNCTION_ENTER ();

MonoStringHandle scope_handle;
Expand All @@ -707,8 +700,7 @@ netcore_resolve_with_resolving_event (MonoAssemblyLoadContext *alc, MonoAssembly
assembly_handle = mono_assembly_get_object_handle (assembly, error);
goto_if_nok (error, leave);

gpointer gchandle;
gchandle = GUINT_TO_POINTER (alc->gchandle);
gpointer gchandle = mono_alc_get_gchandle_for_resolving (alc);
gpointer args [4];
args [0] = MONO_HANDLE_RAW (scope_handle);
args [1] = MONO_HANDLE_RAW (assembly_handle);
Expand Down