Skip to content

Commit cc7b99b

Browse files
authored
Fix mono alc from gchandle (#62120)
* remove MonoManagedAssemblyLoadContext * fix mono_alc_from_gchandle use field * change by vargaz review * formatting * fixed compiler error
1 parent 1962c6c commit cc7b99b

File tree

2 files changed

+13
-12
lines changed

2 files changed

+13
-12
lines changed

src/mono/mono/metadata/assembly-load-context.c

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -424,11 +424,19 @@ mono_alc_from_gchandle (MonoGCHandle alc_gchandle)
424424
if (alc_gchandle == default_alc->gchandle)
425425
return default_alc;
426426

427-
HANDLE_FUNCTION_ENTER ();
428-
MonoManagedAssemblyLoadContextHandle managed_alc = MONO_HANDLE_CAST (MonoManagedAssemblyLoadContext, mono_gchandle_get_target_handle (alc_gchandle));
429-
g_assert (!MONO_HANDLE_IS_NULL (managed_alc));
430-
MonoAssemblyLoadContext *alc = MONO_HANDLE_GETVAL (managed_alc, native_assembly_load_context);
431-
HANDLE_FUNCTION_RETURN_VAL (alc);
427+
MONO_STATIC_POINTER_INIT (MonoClassField, resolve)
428+
429+
MonoClass *alc_class = mono_class_get_assembly_load_context_class ();
430+
g_assert (alc_class);
431+
resolve = mono_class_get_field_from_name_full (alc_class, "_nativeAssemblyLoadContext", NULL);
432+
433+
MONO_STATIC_POINTER_INIT_END (MonoClassField, resolve)
434+
435+
g_assert (resolve);
436+
437+
MonoAssemblyLoadContext *alc = NULL;
438+
mono_field_get_value_internal (mono_gchandle_get_target_internal (alc_gchandle), resolve, &alc);
439+
return alc;
432440
}
433441

434442
MonoGCHandle

src/mono/mono/metadata/object-internals.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1406,13 +1406,6 @@ typedef enum {
14061406
UNLOADING = 1
14071407
} MonoManagedAssemblyLoadContextInternalState;
14081408

1409-
// Keep in sync with System.Runtime.Loader.AssemblyLoadContext
1410-
typedef struct {
1411-
MonoObject object;
1412-
MonoAssemblyLoadContext *native_assembly_load_context;
1413-
} MonoManagedAssemblyLoadContext;
1414-
1415-
TYPED_HANDLE_DECL (MonoManagedAssemblyLoadContext);
14161409

14171410
/* All MonoInternalThread instances should be pinned, so it's safe to use the raw ptr. However
14181411
* for uniformity, icall wrapping will make handles anyway. So this is the method for getting the payload.

0 commit comments

Comments
 (0)