Skip to content

Commit

Permalink
Completely get rid of "refonly" from Mono (#47973)
Browse files Browse the repository at this point in the history
* InternalGetAssemblyName can open the image !refonly

Initially this was opening in refonly mode in order to be able to get
the name of problematic assemblies.  See
d64b25a

However that concept doesn't exist anymore in netcore mono.  So open
the image normally.

* Get rid of MonoImage ref_only field

* no refonly mono_domain_get_assemblies

* no refonly arg to assembly search hooks

* No refonly preload hook

* No refonly assembly_loaded_internal

* No refonly mono_error_set_simple_file_not_found

* There's no GAC or shadow copying

* Remove MonoAssembly in_gac field

* remove unused var
  • Loading branch information
lambdageek authored Feb 8, 2021
1 parent 45287ed commit 1fe9cbf
Show file tree
Hide file tree
Showing 22 changed files with 107 additions and 192 deletions.
36 changes: 12 additions & 24 deletions src/mono/mono/metadata/appdomain.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,12 @@ static MonoAssembly *
mono_domain_assembly_preload (MonoAssemblyLoadContext *alc,
MonoAssemblyName *aname,
gchar **assemblies_path,
gboolean refonly,
gpointer user_data,
MonoError *error);

static MonoAssembly *
mono_domain_assembly_search (MonoAssemblyLoadContext *alc, MonoAssembly *requesting,
MonoAssemblyName *aname,
gboolean refonly,
gboolean postload,
gpointer user_data,
MonoError *error);
Expand Down Expand Up @@ -288,9 +286,9 @@ mono_runtime_init_checked (MonoDomain *domain, MonoThreadStartCB start_cb, MonoT
mono_gc_init_icalls ();

// We have to append here because otherwise this will run before the netcore hook (which is installed first), see https://github.com/dotnet/runtime/issues/34273
mono_install_assembly_preload_hook_v2 (mono_domain_assembly_preload, GUINT_TO_POINTER (FALSE), FALSE, TRUE);
mono_install_assembly_search_hook_v2 (mono_domain_assembly_search, GUINT_TO_POINTER (FALSE), FALSE, FALSE, FALSE);
mono_install_assembly_search_hook_v2 (mono_domain_assembly_postload_search, GUINT_TO_POINTER (FALSE), FALSE, TRUE, FALSE);
mono_install_assembly_preload_hook_v2 (mono_domain_assembly_preload, GUINT_TO_POINTER (FALSE), 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_postload_search, GUINT_TO_POINTER (FALSE), TRUE, FALSE);
mono_install_assembly_load_hook_v2 (mono_domain_fire_assembly_load, NULL, FALSE);

mono_thread_init (start_cb, attach_cb);
Expand Down Expand Up @@ -691,12 +689,12 @@ add_assembly_to_array (MonoDomain *domain, MonoArrayHandle dest, int dest_idx, M
}

static MonoArrayHandle
get_assembly_array_from_domain (MonoDomain *domain, MonoBoolean refonly, MonoError *error)
get_assembly_array_from_domain (MonoDomain *domain, MonoError *error)
{
int i;
GPtrArray *assemblies;

assemblies = mono_domain_get_assemblies (domain, refonly);
assemblies = mono_domain_get_assemblies (domain);

MonoArrayHandle res = mono_array_new_handle (domain, mono_class_get_assembly_class (), assemblies->len, error);
goto_if_nok (error, leave);
Expand All @@ -714,24 +712,24 @@ MonoArrayHandle
ves_icall_System_Runtime_Loader_AssemblyLoadContext_InternalGetLoadedAssemblies (MonoError *error)
{
MonoDomain *domain = mono_domain_get ();
return get_assembly_array_from_domain (domain, FALSE, error);
return get_assembly_array_from_domain (domain, error);
}

MonoAssembly*
mono_try_assembly_resolve (MonoAssemblyLoadContext *alc, const char *fname_raw, MonoAssembly *requesting, gboolean refonly, MonoError *error)
mono_try_assembly_resolve (MonoAssemblyLoadContext *alc, const char *fname_raw, MonoAssembly *requesting, MonoError *error)
{
HANDLE_FUNCTION_ENTER ();
error_init (error);
MonoAssembly *result = NULL;
MonoStringHandle fname = mono_string_new_handle (mono_alc_domain (alc), fname_raw, error);
goto_if_nok (error, leave);
result = mono_try_assembly_resolve_handle (alc, fname, requesting, refonly, error);
result = mono_try_assembly_resolve_handle (alc, fname, requesting, error);
leave:
HANDLE_FUNCTION_RETURN_VAL (result);
}

MonoAssembly*
mono_try_assembly_resolve_handle (MonoAssemblyLoadContext *alc, MonoStringHandle fname, MonoAssembly *requesting, gboolean refonly, MonoError *error)
mono_try_assembly_resolve_handle (MonoAssemblyLoadContext *alc, MonoStringHandle fname, MonoAssembly *requesting, MonoError *error)
{
HANDLE_FUNCTION_ENTER ();
MonoAssembly *ret = NULL;
Expand Down Expand Up @@ -784,7 +782,7 @@ mono_try_assembly_resolve_handle (MonoAssemblyLoadContext *alc, MonoStringHandle
MonoAssembly *
mono_domain_assembly_postload_search (MonoAssemblyLoadContext *alc, MonoAssembly *requesting,
MonoAssemblyName *aname,
gboolean refonly, gboolean postload,
gboolean postload,
gpointer user_data,
MonoError *error_out)
{
Expand All @@ -796,7 +794,7 @@ mono_domain_assembly_postload_search (MonoAssemblyLoadContext *alc, MonoAssembly

/* FIXME: We invoke managed code here, so there is a potential for deadlocks */

assembly = mono_try_assembly_resolve (alc, aname_str, requesting, refonly, error);
assembly = mono_try_assembly_resolve (alc, aname_str, requesting, error);
g_free (aname_str);
mono_error_cleanup (error);

Expand Down Expand Up @@ -946,13 +944,6 @@ mono_domain_asmctx_from_path (const char *fname, MonoAssembly *requesting_assemb
return FALSE;
}

char *
mono_make_shadow_copy (const char *filename, MonoError *error)
{
error_init (error);
return (char *) filename;
}

/**
* mono_domain_from_appdomain:
*/
Expand Down Expand Up @@ -1079,7 +1070,6 @@ static MonoAssembly *
mono_domain_assembly_preload (MonoAssemblyLoadContext *alc,
MonoAssemblyName *aname,
gchar **assemblies_path,
gboolean refonly,
gpointer user_data,
MonoError *error)
{
Expand All @@ -1088,7 +1078,6 @@ mono_domain_assembly_preload (MonoAssemblyLoadContext *alc,

g_assert (alc);
g_assert (domain == mono_domain_get ());
g_assert (!refonly);

MonoAssemblyCandidatePredicate predicate = NULL;
void* predicate_ud = NULL;
Expand Down Expand Up @@ -1127,7 +1116,6 @@ mono_domain_assembly_preload (MonoAssemblyLoadContext *alc,
static MonoAssembly *
mono_domain_assembly_search (MonoAssemblyLoadContext *alc, MonoAssembly *requesting,
MonoAssemblyName *aname,
gboolean refonly,
gboolean postload,
gpointer user_data,
MonoError *error)
Expand Down Expand Up @@ -1246,7 +1234,7 @@ mono_alc_load_file (MonoAssemblyLoadContext *alc, MonoStringHandle fname, MonoAs
if (status == MONO_IMAGE_IMAGE_INVALID)
mono_error_set_bad_image_by_name (error, filename, "Invalid Image: %s", filename);
else
mono_error_set_simple_file_not_found (error, filename, FALSE);
mono_error_set_simple_file_not_found (error, filename);
}

leave:
Expand Down
10 changes: 5 additions & 5 deletions src/mono/mono/metadata/assembly-internals.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,14 @@ typedef gboolean (*MonoAssemblyAsmCtxFromPathFunc) (const char *absfname, MonoAs

void mono_install_assembly_asmctx_from_path_hook (MonoAssemblyAsmCtxFromPathFunc func, gpointer user_data);

typedef MonoAssembly * (*MonoAssemblyPreLoadFuncV2) (MonoAssemblyLoadContext *alc, MonoAssemblyName *aname, char **assemblies_path, gboolean refonly, gpointer user_data, MonoError *error);
typedef MonoAssembly * (*MonoAssemblyPreLoadFuncV2) (MonoAssemblyLoadContext *alc, MonoAssemblyName *aname, char **assemblies_path, gpointer user_data, MonoError *error);

void mono_install_assembly_preload_hook_v2 (MonoAssemblyPreLoadFuncV2 func, gpointer user_data, gboolean refonly, gboolean append);
void mono_install_assembly_preload_hook_v2 (MonoAssemblyPreLoadFuncV2 func, gpointer user_data, gboolean append);

typedef MonoAssembly * (*MonoAssemblySearchFuncV2) (MonoAssemblyLoadContext *alc, MonoAssembly *requesting, MonoAssemblyName *aname, gboolean refonly, gboolean postload, gpointer user_data, MonoError *error);
typedef MonoAssembly * (*MonoAssemblySearchFuncV2) (MonoAssemblyLoadContext *alc, MonoAssembly *requesting, MonoAssemblyName *aname, gboolean postload, gpointer user_data, MonoError *error);

void
mono_install_assembly_search_hook_v2 (MonoAssemblySearchFuncV2 func, gpointer user_data, gboolean refonly, gboolean postload, gboolean append);
mono_install_assembly_search_hook_v2 (MonoAssemblySearchFuncV2 func, gpointer user_data, gboolean postload, gboolean append);

typedef void (*MonoAssemblyLoadFuncV2) (MonoAssemblyLoadContext *alc, MonoAssembly *assembly, gpointer user_data, MonoError *error);

Expand Down Expand Up @@ -136,7 +136,7 @@ gboolean
mono_assembly_check_name_match (MonoAssemblyName *wanted_name, MonoAssemblyName *candidate_name);

MonoAssembly *
mono_assembly_loaded_internal (MonoAssemblyLoadContext *alc, MonoAssemblyName *aname, gboolean refonly);
mono_assembly_loaded_internal (MonoAssemblyLoadContext *alc, MonoAssemblyName *aname);

MONO_PROFILER_API MonoAssemblyName*
mono_assembly_get_name_internal (MonoAssembly *assembly);
Expand Down
Loading

0 comments on commit 1fe9cbf

Please sign in to comment.