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

Fix mono alc from gchandle #62120

Merged
merged 5 commits into from
Nov 30, 2021
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
18 changes: 13 additions & 5 deletions src/mono/mono/metadata/assembly-load-context.c
Original file line number Diff line number Diff line change
Expand Up @@ -424,11 +424,19 @@ mono_alc_from_gchandle (MonoGCHandle alc_gchandle)
if (alc_gchandle == default_alc->gchandle)
return default_alc;

HANDLE_FUNCTION_ENTER ();
MonoManagedAssemblyLoadContextHandle managed_alc = MONO_HANDLE_CAST (MonoManagedAssemblyLoadContext, mono_gchandle_get_target_handle (alc_gchandle));
g_assert (!MONO_HANDLE_IS_NULL (managed_alc));
MonoAssemblyLoadContext *alc = MONO_HANDLE_GETVAL (managed_alc, native_assembly_load_context);
HANDLE_FUNCTION_RETURN_VAL (alc);
MONO_STATIC_POINTER_INIT (MonoClassField, resolve)

MonoClass *alc_class = mono_class_get_assembly_load_context_class ();
g_assert (alc_class);
resolve = mono_class_get_field_from_name_full (alc_class, "_nativeAssemblyLoadContext", NULL);

vargaz marked this conversation as resolved.
Show resolved Hide resolved
MONO_STATIC_POINTER_INIT_END (MonoClassField, resolve)

g_assert (resolve);

MonoAssemblyLoadContext *alc = NULL;
mono_field_get_value_internal (mono_gchandle_get_target_internal (alc_gchandle), resolve, &alc);
return alc;
vargaz marked this conversation as resolved.
Show resolved Hide resolved
}

MonoGCHandle
Expand Down
7 changes: 0 additions & 7 deletions src/mono/mono/metadata/object-internals.h
Original file line number Diff line number Diff line change
Expand Up @@ -1406,13 +1406,6 @@ typedef enum {
UNLOADING = 1
} MonoManagedAssemblyLoadContextInternalState;

// Keep in sync with System.Runtime.Loader.AssemblyLoadContext
typedef struct {
MonoObject object;
MonoAssemblyLoadContext *native_assembly_load_context;
} MonoManagedAssemblyLoadContext;

TYPED_HANDLE_DECL (MonoManagedAssemblyLoadContext);

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