From 2187b7b3d701311e45a0a417f733e52b3d55616a Mon Sep 17 00:00:00 2001 From: =?utf8?q?Aleksey=20Kliger=20=28=CE=BBgeek=29?= Date: Fri, 19 Jul 2019 00:01:56 -0400 Subject: [PATCH] [loader] Pass ALC to mono_domain_loaded_internal, and then to domain search hook (mono/mono#15743) * Add a temporary mono_domain_ambient_alc function Just use this to mark places where we need to pass through an ALC * [runtime] Mark mono_assembly_loaded_full external only. Runtime should use mono_assembly_loaded_internal. * [loader] Add mono_install_assembly_search_hook_v2 Use it to install mono_domain_assembly_search and mono_domain_assembly_postload_search. The principal difference is that we can pass an assembly load context to the hook. But also we cleanup the "requesting assembly" hack for mono_domain_assembly_postload_search. * [domain] Comments and mono_assembly_get_alc () * [debugger] Comment on suspicious loader lock Commit migrated from https://github.com/mono/mono/commit/a37ad98b470381950c876bb0928cab57fe8156b2 --- src/mono/mono/dis/main.c | 4 +- src/mono/mono/metadata/appdomain.c | 34 +++++++--- src/mono/mono/metadata/assembly-internals.h | 8 +++ src/mono/mono/metadata/assembly.c | 100 ++++++++++++++++------------ src/mono/mono/metadata/assembly.h | 18 +++-- src/mono/mono/metadata/domain-internals.h | 20 +++++- src/mono/mono/metadata/metadata-internals.h | 9 +++ src/mono/mono/metadata/reflection.c | 3 +- src/mono/mono/mini/debugger-agent.c | 2 +- 9 files changed, 133 insertions(+), 65 deletions(-) diff --git a/src/mono/mono/dis/main.c b/src/mono/mono/dis/main.c index 7e16a7f..846e7e8 100644 --- a/src/mono/mono/dis/main.c +++ b/src/mono/mono/dis/main.c @@ -1942,7 +1942,7 @@ monodis_assembly_load_hook (MonoAssembly *assembly, gpointer user_data) } static MonoAssembly * -monodis_assembly_search_hook (MonoAssemblyName *aname, gpointer user_data) +monodis_assembly_search_hook (MonoAssemblyLoadContext *alc, MonoAssembly *requesting, MonoAssemblyName *aname, gboolean refonly, gboolean postload, gpointer user_data, MonoError *error) { GList *tmp; @@ -2047,7 +2047,7 @@ main (int argc, char *argv []) mono_thread_info_runtime_init (&ticallbacks); mono_install_assembly_load_hook (monodis_assembly_load_hook, NULL); - mono_install_assembly_search_hook (monodis_assembly_search_hook, NULL); + mono_install_assembly_search_hook_v2 (monodis_assembly_search_hook, NULL, FALSE, FALSE); /* * If we just have one file, use the corlib version it requires. diff --git a/src/mono/mono/metadata/appdomain.c b/src/mono/mono/metadata/appdomain.c index 6cd52c1..9f51044 100644 --- a/src/mono/mono/metadata/appdomain.c +++ b/src/mono/mono/metadata/appdomain.c @@ -111,8 +111,13 @@ mono_domain_assembly_preload (MonoAssemblyLoadContext *alc, MonoError *error); static MonoAssembly * -mono_domain_assembly_search (MonoAssemblyName *aname, - gpointer user_data); +mono_domain_assembly_search (MonoAssemblyLoadContext *alc, MonoAssembly *requesting, + MonoAssemblyName *aname, + gboolean refonly, + gboolean postload, + gpointer user_data, + MonoError *error); + static void mono_domain_fire_assembly_load (MonoAssembly *assembly, gpointer user_data); @@ -299,10 +304,10 @@ mono_runtime_init_checked (MonoDomain *domain, MonoThreadStartCB start_cb, MonoT mono_install_assembly_preload_hook_v2 (mono_domain_assembly_preload, GUINT_TO_POINTER (FALSE), FALSE); mono_install_assembly_preload_hook_v2 (mono_domain_assembly_preload, GUINT_TO_POINTER (TRUE), TRUE); - mono_install_assembly_search_hook (mono_domain_assembly_search, GUINT_TO_POINTER (FALSE)); - mono_install_assembly_refonly_search_hook (mono_domain_assembly_search, GUINT_TO_POINTER (TRUE)); - mono_install_assembly_postload_search_hook ((MonoAssemblySearchFunc)mono_domain_assembly_postload_search, GUINT_TO_POINTER (FALSE)); - mono_install_assembly_postload_refonly_search_hook ((MonoAssemblySearchFunc)mono_domain_assembly_postload_search, GUINT_TO_POINTER (TRUE)); + mono_install_assembly_search_hook_v2 (mono_domain_assembly_search, GUINT_TO_POINTER (FALSE), FALSE, FALSE); + mono_install_assembly_search_hook_v2 (mono_domain_assembly_search, GUINT_TO_POINTER (TRUE), TRUE, FALSE); + mono_install_assembly_search_hook_v2 (mono_domain_assembly_postload_search, GUINT_TO_POINTER (FALSE), FALSE, TRUE); + mono_install_assembly_search_hook_v2 (mono_domain_assembly_postload_search, GUINT_TO_POINTER (TRUE), TRUE, TRUE); mono_install_assembly_load_hook (mono_domain_fire_assembly_load, NULL); mono_install_assembly_asmctx_from_path_hook (mono_domain_asmctx_from_path, NULL); @@ -1298,6 +1303,7 @@ ves_icall_System_AppDomain_GetAssemblies (MonoAppDomainHandle ad, MonoBoolean re ass = (MonoAssembly *)tmp->data; MonoBoolean ass_refonly = mono_asmctx_get_kind (&ass->context) == MONO_ASMCTX_REFONLY; /* .NET Framework GetAssemblies() includes LoadFrom and Load(byte[]) assemblies, too */ + /* For netcore, this should return all the assemblies in the domain - from every ALC */ if (refonly != ass_refonly) continue; if (ass->corlib_internal) @@ -1381,8 +1387,11 @@ leave: } MonoAssembly * -mono_domain_assembly_postload_search (MonoAssemblyName *aname, MonoAssembly *requesting, - gboolean refonly) +mono_domain_assembly_postload_search (MonoAssemblyLoadContext *alc, MonoAssembly *requesting, + MonoAssemblyName *aname, + gboolean refonly, gboolean postload, + gpointer user_data, + MonoError *error_out) { ERROR_DECL (error); MonoAssembly *assembly; @@ -2321,14 +2330,17 @@ mono_assembly_load_from_assemblies_path (gchar **assemblies_path, MonoAssemblyNa * Check whenever a given assembly was already loaded in the current appdomain. */ static MonoAssembly * -mono_domain_assembly_search (MonoAssemblyName *aname, - gpointer user_data) +mono_domain_assembly_search (MonoAssemblyLoadContext *alc, MonoAssembly *requesting, + MonoAssemblyName *aname, + gboolean refonly, + gboolean postload, + gpointer user_data, + MonoError *error) { g_assert (aname != NULL); MonoDomain *domain = mono_domain_get (); GSList *tmp; MonoAssembly *ass; - gboolean refonly = GPOINTER_TO_UINT (user_data); const gboolean strong_name = aname->public_key_token[0] != 0; /* If it's not a strong name, any version that has the right simple * name is good enough to satisfy the request. .NET Framework also diff --git a/src/mono/mono/metadata/assembly-internals.h b/src/mono/mono/metadata/assembly-internals.h index ccbbbe0..17781e9 100644 --- a/src/mono/mono/metadata/assembly-internals.h +++ b/src/mono/mono/metadata/assembly-internals.h @@ -53,6 +53,11 @@ typedef MonoAssembly * (*MonoAssemblyPreLoadFuncV2) (MonoAssemblyLoadContext *al void mono_install_assembly_preload_hook_v2 (MonoAssemblyPreLoadFuncV2 func, void *user_data, gboolean refonly); +typedef MonoAssembly * (*MonoAssemblySearchFuncV2) (MonoAssemblyLoadContext *alc, MonoAssembly *requesting, MonoAssemblyName *aname, gboolean refonly, gboolean postload, gpointer user_data, MonoError *error); + +void +mono_install_assembly_search_hook_v2 (MonoAssemblySearchFuncV2 func, void *user_data, gboolean refonly, gboolean postload); + /* If predicate returns true assembly should be loaded, if false ignore it. */ typedef gboolean (*MonoAssemblyCandidatePredicate)(MonoAssembly *, gpointer); @@ -114,6 +119,9 @@ mono_assembly_binding_applies_to_image (MonoImage* image, MonoImageOpenStatus *s MonoAssembly* mono_assembly_load_from_assemblies_path (gchar **assemblies_path, MonoAssemblyName *aname, MonoAssemblyContextKind asmctx); +MonoAssembly * +mono_assembly_loaded_internal (MonoAssemblyLoadContext *alc, MonoAssemblyName *aname, gboolean refonly); + MONO_PROFILER_API MonoAssemblyName* mono_assembly_get_name_internal (MonoAssembly *assembly); diff --git a/src/mono/mono/metadata/assembly.c b/src/mono/mono/metadata/assembly.c index 1e22741..36fadf3 100644 --- a/src/mono/mono/metadata/assembly.c +++ b/src/mono/mono/metadata/assembly.c @@ -373,7 +373,7 @@ static GSList *loaded_assembly_bindings = NULL; /* Class lazy loading functions */ static GENERATE_TRY_GET_CLASS_WITH_CACHE (internals_visible, "System.Runtime.CompilerServices", "InternalsVisibleToAttribute") static MonoAssembly* -mono_assembly_invoke_search_hook_internal (MonoAssemblyName *aname, MonoAssembly *requesting, gboolean refonly, gboolean postload); +mono_assembly_invoke_search_hook_internal (MonoAssemblyLoadContext *alc, MonoAssembly *requesting, MonoAssemblyName *aname, gboolean refonly, gboolean postload); static MonoAssembly* mono_assembly_request_byname_nosearch (MonoAssemblyName *aname, const MonoAssemblyByNameRequest *req, MonoImageOpenStatus *status); static MonoAssembly* @@ -1482,10 +1482,10 @@ load_reference_by_aname_refonly_asmctx (MonoAssemblyName *aname, MonoAssembly *a req.basedir = assm->basedir; reference = mono_assembly_request_byname (aname, &req, status); } else { - reference = mono_assembly_loaded_full (aname, TRUE); + reference = mono_assembly_loaded_internal (NULL, aname, TRUE); if (!reference) /* Try a postload search hook */ - reference = mono_assembly_invoke_search_hook_internal (aname, assm, TRUE, TRUE); + reference = mono_assembly_invoke_search_hook_internal (NULL, assm, aname, TRUE, TRUE); } /* @@ -1559,7 +1559,7 @@ load_reference_by_aname_individual_asmctx (MonoAssemblyName *aname, MonoAssembly aname = mono_assembly_remap_version (aname, &maped_aname); aname = mono_assembly_apply_binding (aname, &maped_name_pp); - reference = mono_assembly_loaded_full (aname, FALSE); + reference = mono_assembly_loaded_internal (mono_domain_ambient_alc (mono_domain_get ()), aname, FALSE); /* Still try to load from application base directory, MONO_PATH or the * GAC. This is consistent with what .NET Framework (4.7) actually * does, rather than what the documentation implies: If `LoadFile` is @@ -1808,45 +1808,34 @@ free_assembly_load_hooks (void) typedef struct AssemblySearchHook AssemblySearchHook; struct AssemblySearchHook { AssemblySearchHook *next; - MonoAssemblySearchFunc func; + union { + MonoAssemblySearchFunc v1; + MonoAssemblySearchFuncV2 v2; + } func; gboolean refonly; gboolean postload; + int version; gpointer user_data; }; static AssemblySearchHook *assembly_search_hook = NULL; static MonoAssembly* -mono_assembly_invoke_search_hook_internal (MonoAssemblyName *aname, MonoAssembly *requesting, gboolean refonly, gboolean postload) +mono_assembly_invoke_search_hook_internal (MonoAssemblyLoadContext *alc, MonoAssembly *requesting, MonoAssemblyName *aname, gboolean refonly, gboolean postload) { AssemblySearchHook *hook; for (hook = assembly_search_hook; hook; hook = hook->next) { if ((hook->refonly == refonly) && (hook->postload == postload)) { MonoAssembly *ass; - /** - * A little explanation is in order here. - * - * The default postload search hook needs to know the requesting assembly to report it to managed code. - * The embedding API exposes a search hook that doesn't take such argument. - * - * The original fix would call the default search hook before all the registered ones and pass - * the requesting assembly to it. It works but broke a very suddle embedding API aspect that some users - * rely on. Which is the ordering between user hooks and the default runtime hook. - * - * Registering the hook after mono_jit_init would let your hook run before the default one and - * when using it to handle non standard app layouts this could save your app from a massive amount - * of syscalls that the default hook does when probing all sorts of places. Slow targets with horrible IO - * are all using this trick and if we broke this assumption they would be very disapointed at us. - * - * So what's the fix? We register the default hook using regular means and special case it when iterating - * over the registered hooks. This preserves ordering and enables managed resolve hooks to get the requesting - * assembly. - */ - if (hook->func == (void*)mono_domain_assembly_postload_search) - ass = mono_domain_assembly_postload_search (aname, requesting, refonly); - else - ass = hook->func (aname, hook->user_data); + if (hook->version == 1) { + ass = hook->func.v1 (aname, hook->user_data); + } else { + ERROR_DECL (hook_error); + g_assert (hook->version == 2); + ass = hook->func.v2 (alc, requesting, aname, refonly, postload, hook->user_data, hook_error); + mono_error_assert_ok (hook_error); /* FIXME: proper error handling */ + } if (ass) return ass; } @@ -1861,18 +1850,35 @@ mono_assembly_invoke_search_hook_internal (MonoAssemblyName *aname, MonoAssembly MonoAssembly* mono_assembly_invoke_search_hook (MonoAssemblyName *aname) { - return mono_assembly_invoke_search_hook_internal (aname, NULL, FALSE, FALSE); + return mono_assembly_invoke_search_hook_internal (NULL, NULL, aname, FALSE, FALSE); } static void -mono_install_assembly_search_hook_internal (MonoAssemblySearchFunc func, gpointer user_data, gboolean refonly, gboolean postload) +mono_install_assembly_search_hook_internal_v1 (MonoAssemblySearchFunc func, gpointer user_data, gboolean refonly, gboolean postload) { AssemblySearchHook *hook; g_return_if_fail (func != NULL); hook = g_new0 (AssemblySearchHook, 1); - hook->func = func; + hook->version = 1; + hook->func.v1 = func; + hook->user_data = user_data; + hook->refonly = refonly; + hook->postload = postload; + hook->next = assembly_search_hook; + assembly_search_hook = hook; +} + +void +mono_install_assembly_search_hook_v2 (MonoAssemblySearchFuncV2 func, void *user_data, gboolean refonly, gboolean postload) +{ + if (func == NULL) + return; + + AssemblySearchHook *hook = g_new0 (AssemblySearchHook, 1); + hook->version = 2; + hook->func.v2 = func; hook->user_data = user_data; hook->refonly = refonly; hook->postload = postload; @@ -1886,7 +1892,7 @@ mono_install_assembly_search_hook_internal (MonoAssemblySearchFunc func, gpointe void mono_install_assembly_search_hook (MonoAssemblySearchFunc func, gpointer user_data) { - mono_install_assembly_search_hook_internal (func, user_data, FALSE, FALSE); + mono_install_assembly_search_hook_internal_v1 (func, user_data, FALSE, FALSE); } static void @@ -1906,7 +1912,7 @@ free_assembly_search_hooks (void) void mono_install_assembly_refonly_search_hook (MonoAssemblySearchFunc func, gpointer user_data) { - mono_install_assembly_search_hook_internal (func, user_data, TRUE, FALSE); + mono_install_assembly_search_hook_internal_v1 (func, user_data, TRUE, FALSE); } /** @@ -1915,15 +1921,16 @@ mono_install_assembly_refonly_search_hook (MonoAssemblySearchFunc func, gpointer void mono_install_assembly_postload_search_hook (MonoAssemblySearchFunc func, gpointer user_data) { - mono_install_assembly_search_hook_internal (func, user_data, FALSE, TRUE); + mono_install_assembly_search_hook_internal_v1 (func, user_data, FALSE, TRUE); } void mono_install_assembly_postload_refonly_search_hook (MonoAssemblySearchFunc func, gpointer user_data) { - mono_install_assembly_search_hook_internal (func, user_data, TRUE, TRUE); + mono_install_assembly_search_hook_internal_v1 (func, user_data, TRUE, TRUE); } + typedef struct AssemblyPreLoadHook AssemblyPreLoadHook; struct AssemblyPreLoadHook { AssemblyPreLoadHook *next; @@ -2891,7 +2898,7 @@ mono_assembly_request_load_from (MonoImage *image, const char *fname, */ if (ass->aname.name && asmctx != MONO_ASMCTX_INDIVIDUAL) { /* FIXME: I think individual context should probably also look for an existing MonoAssembly here, we just need to pass the asmctx to the search hook so that it does a filename match (I guess?) */ - ass2 = mono_assembly_invoke_search_hook_internal (&ass->aname, NULL, asmctx == MONO_ASMCTX_REFONLY, FALSE); + ass2 = mono_assembly_invoke_search_hook_internal (req->alc, NULL, &ass->aname, asmctx == MONO_ASMCTX_REFONLY, FALSE); if (ass2) { mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_ASSEMBLY, "Image %s[%p] reusing existing assembly %s[%p]", ass->aname.name, ass, ass2->aname.name, ass2); g_free (ass); @@ -3692,9 +3699,9 @@ mono_assembly_load_with_partial_name_internal (const char *name, MonoImageOpenSt aname = mono_assembly_remap_version (aname, &mapped_aname); /* FIXME: get the ALC as an argument from the caller */ - MonoAssemblyLoadContext *alc = mono_domain_default_alc (mono_domain_get ()); + MonoAssemblyLoadContext *alc = mono_domain_ambient_alc (mono_domain_get ()); - res = mono_assembly_loaded_full (aname, FALSE); + res = mono_assembly_loaded_internal (alc, aname, FALSE); if (res) { mono_assembly_name_free (aname); return res; @@ -4422,7 +4429,7 @@ mono_assembly_request_byname_nosearch (MonoAssemblyName *aname, if (!refonly) aname = mono_assembly_apply_binding (aname, &maped_name_pp); - result = mono_assembly_loaded_full (aname, refonly); + result = mono_assembly_loaded_internal (req->request.alc, aname, refonly); if (result) return result; @@ -4539,7 +4546,7 @@ mono_assembly_request_byname (MonoAssemblyName *aname, const MonoAssemblyByNameR if (!result && !req->no_postload_search) { /* Try a postload search hook */ - result = mono_assembly_invoke_search_hook_internal (aname, req->requesting_assembly, refonly, TRUE); + result = mono_assembly_invoke_search_hook_internal (req->request.alc, req->requesting_assembly, aname, refonly, TRUE); result = prevent_reference_assembly_from_running (result, refonly); } return result; @@ -4610,12 +4617,19 @@ mono_assembly_load (MonoAssemblyName *aname, const char *basedir, MonoImageOpenS MonoAssembly* mono_assembly_loaded_full (MonoAssemblyName *aname, gboolean refonly) { + MonoAssemblyLoadContext *alc = mono_domain_ambient_alc (mono_domain_get ()); + return mono_assembly_loaded_internal (alc, aname, refonly); +} + +MonoAssembly * +mono_assembly_loaded_internal (MonoAssemblyLoadContext *alc, MonoAssemblyName *aname, gboolean refonly) +{ MonoAssembly *res; MonoAssemblyName maped_aname; aname = mono_assembly_remap_version (aname, &maped_aname); - res = mono_assembly_invoke_search_hook_internal (aname, NULL, refonly, FALSE); + res = mono_assembly_invoke_search_hook_internal (alc, NULL, aname, refonly, FALSE); return res; } @@ -4634,7 +4648,7 @@ mono_assembly_loaded (MonoAssemblyName *aname) { MonoAssembly *res; MONO_ENTER_GC_UNSAFE; - res = mono_assembly_loaded_full (aname, FALSE); + res = mono_assembly_loaded_internal (mono_domain_ambient_alc (mono_domain_get ()), aname, FALSE); MONO_EXIT_GC_UNSAFE; return res; } diff --git a/src/mono/mono/metadata/assembly.h b/src/mono/mono/metadata/assembly.h index 19f44f3d..d0e4a3d 100644 --- a/src/mono/mono/metadata/assembly.h +++ b/src/mono/mono/metadata/assembly.h @@ -40,7 +40,8 @@ MonoAssembly* mono_assembly_load_with_partial_name (const char *name, MonoImageO MONO_API MONO_RT_EXTERNAL_ONLY MonoAssembly* mono_assembly_loaded (MonoAssemblyName *aname); -MONO_API MonoAssembly* mono_assembly_loaded_full (MonoAssemblyName *aname, mono_bool refonly); +MONO_API MONO_RT_EXTERNAL_ONLY +MonoAssembly* mono_assembly_loaded_full (MonoAssemblyName *aname, mono_bool refonly); MONO_API void mono_assembly_get_assemblyref (MonoImage *image, int index, MonoAssemblyName *aname); MONO_API void mono_assembly_load_reference (MonoImage *image, int index); MONO_API void mono_assembly_load_references (MonoImage *image, MonoImageOpenStatus *status); @@ -69,19 +70,24 @@ MONO_API void mono_install_assembly_load_hook (MonoAssemblyLoadFunc fun * assemblies for a given assembly name. */ typedef MonoAssembly *(*MonoAssemblySearchFunc) (MonoAssemblyName *aname, void* user_data); -MONO_API void mono_install_assembly_search_hook (MonoAssemblySearchFunc func, void* user_data); -MONO_API void mono_install_assembly_refonly_search_hook (MonoAssemblySearchFunc func, void* user_data); +MONO_API MONO_RT_EXTERNAL_ONLY +void mono_install_assembly_search_hook (MonoAssemblySearchFunc func, void* user_data); +MONO_API MONO_RT_EXTERNAL_ONLY +void mono_install_assembly_refonly_search_hook (MonoAssemblySearchFunc func, void* user_data); -MONO_API MonoAssembly* mono_assembly_invoke_search_hook (MonoAssemblyName *aname); +MONO_API MONO_RT_EXTERNAL_ONLY +MonoAssembly* mono_assembly_invoke_search_hook (MonoAssemblyName *aname); /* * Installs a new search function which is used as a last resort when loading * an assembly fails. This could invoke AssemblyResolve events. */ -MONO_API void +MONO_API MONO_RT_EXTERNAL_ONLY +void mono_install_assembly_postload_search_hook (MonoAssemblySearchFunc func, void* user_data); -MONO_API void +MONO_API MONO_RT_EXTERNAL_ONLY +void mono_install_assembly_postload_refonly_search_hook (MonoAssemblySearchFunc func, void* user_data); diff --git a/src/mono/mono/metadata/domain-internals.h b/src/mono/mono/metadata/domain-internals.h index f7942e0..9c1de42 100644 --- a/src/mono/mono/metadata/domain-internals.h +++ b/src/mono/mono/metadata/domain-internals.h @@ -376,6 +376,13 @@ struct _MonoDomain { /* Needed by Thread:GetDomainID() */ gint32 domain_id; gint32 shadow_serial; + /* + * For framework Mono, this is every assembly loaded in this + * domain. For netcore, this is every assembly loaded in every ALC in + * this domain. In netcore, the thread that adds an assembly to its + * MonoAssemblyLoadContext:loaded_assemblies should also add it to this + * list. + */ GSList *domain_assemblies; MonoAssembly *entry_assembly; char *friendly_name; @@ -632,7 +639,7 @@ MonoAssembly * mono_try_assembly_resolve (MonoDomain *domain, const char *fname, MonoAssembly *requesting, gboolean refonly, MonoError *error); MonoAssembly * -mono_domain_assembly_postload_search (MonoAssemblyName *aname, MonoAssembly *requesting, gboolean refonly); +mono_domain_assembly_postload_search (MonoAssemblyLoadContext *alc, MonoAssembly *requesting, MonoAssemblyName *aname, gboolean refonly, gboolean postload, gpointer user_data, MonoError *error); void mono_domain_set_options_from_config (MonoDomain *domain); @@ -675,4 +682,15 @@ MonoAssemblyLoadContext * mono_domain_create_individual_alc (MonoDomain *domain, uint32_t this_gchandle, gboolean collectible, MonoError *error); #endif +static inline +MonoAssemblyLoadContext * +mono_domain_ambient_alc (MonoDomain *domain) +{ + /* + * FIXME: All the callers of mono_domain_ambient_alc should get an ALC + * passed to them from their callers. + */ + return mono_domain_default_alc (domain); +} + #endif /* __MONO_METADATA_DOMAIN_INTERNALS_H__ */ diff --git a/src/mono/mono/metadata/metadata-internals.h b/src/mono/mono/metadata/metadata-internals.h index e1bbdb1..9a6036f 100644 --- a/src/mono/mono/metadata/metadata-internals.h +++ b/src/mono/mono/metadata/metadata-internals.h @@ -1195,4 +1195,13 @@ mono_image_get_alc (MonoImage *image) #endif } +#ifdef ENABLE_NETCORE +static inline +MonoAssemblyLoadContext * +mono_assembly_get_alc (MonoAssembly *assm) +{ + return assm->image->alc; +} +#endif + #endif /* __MONO_METADATA_INTERNALS_H__ */ diff --git a/src/mono/mono/metadata/reflection.c b/src/mono/mono/metadata/reflection.c index a94b1f2..1763871 100644 --- a/src/mono/mono/metadata/reflection.c +++ b/src/mono/mono/metadata/reflection.c @@ -14,6 +14,7 @@ */ #include #include "mono/utils/mono-membar.h" +#include "mono/metadata/assembly-internals.h" #include "mono/metadata/reflection-internals.h" #include "mono/metadata/tabledefs.h" #include "mono/metadata/metadata-internals.h" @@ -1930,7 +1931,7 @@ _mono_reflection_get_type_from_info (MonoTypeNameParse *info, MonoImage *image, error_init (error); if (info->assembly.name) { - MonoAssembly *assembly = mono_assembly_loaded_full (&info->assembly, FALSE); + MonoAssembly *assembly = mono_assembly_loaded_internal (mono_domain_ambient_alc (mono_domain_get ()), &info->assembly, FALSE); if (!assembly && image && image->assembly && mono_assembly_names_equal (&info->assembly, &image->assembly->aname)) /* * This could happen in the AOT compiler case when the search hook is not diff --git a/src/mono/mono/mini/debugger-agent.c b/src/mono/mono/mini/debugger-agent.c index 5d65657..eb9113f 100644 --- a/src/mono/mono/mini/debugger-agent.c +++ b/src/mono/mono/mini/debugger-agent.c @@ -7232,7 +7232,7 @@ domain_commands (int command, guint8 *p, guint8 *end, Buffer *buf) domain = decode_domainid (p, &p, end, NULL, &err); if (err != ERR_NONE) return err; - mono_loader_lock (); + mono_loader_lock (); // FIXME: should be the domain assemblies lock? count = 0; for (tmp = domain->domain_assemblies; tmp; tmp = tmp->next) { count ++; -- 2.7.4