From 2bced3941536df037e0b73220852a004d01556ad Mon Sep 17 00:00:00 2001 From: Zoltan Varga Date: Sat, 6 Feb 2021 19:32:50 -0500 Subject: [PATCH] Cleanup assembly loading code. (#47958) MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit * Cleanup the assembly loading code. * Remove the 'problematic' assembly code. Co-authored-by: Aleksey Kliger (λgeek) --- src/mono/CMakeLists.txt | 6 - src/mono/cmake/config.h.in | 6 - src/mono/cmake/options.cmake | 2 - src/mono/mono/metadata/assembly.c | 1342 +-------------------------- src/mono/mono/metadata/domain-internals.h | 9 - src/mono/mono/metadata/domain.c | 2 - src/mono/mono/metadata/image-internals.h | 6 - src/mono/mono/metadata/image.c | 271 +----- src/mono/mono/metadata/metadata-internals.h | 3 - src/mono/mono/mini/driver.c | 9 +- 10 files changed, 11 insertions(+), 1645 deletions(-) diff --git a/src/mono/CMakeLists.txt b/src/mono/CMakeLists.txt index 918cfb4..1a967bf 100644 --- a/src/mono/CMakeLists.txt +++ b/src/mono/CMakeLists.txt @@ -71,12 +71,9 @@ set(MONO_CORLIB_VERSION 1A5E0066-58DC-428A-B21C-0AD6CDAE2789) set(DISABLE_REMOTING 1) set(DISABLE_APPDOMAINS 1) -set(DISABLE_SHADOW_COPY 1) set(DISABLE_CLEANUP 1) -set(DISABLE_ASSEMBLY_REMAPPING 1) set(DISABLE_MDB 1) set(DISABLE_COM 1) -set(DISABLE_GAC 1) set(DISABLE_PERFCOUNTERS 1) set(DISABLE_ATTACH 1) set(DISABLE_CONFIG 1) @@ -84,9 +81,6 @@ set(DISABLE_CFGDIR_CONFIG 1) set(DISABLE_VERIFIER 1) # Dependencies between options -if(DISABLE_ASSEMBLY_REMAPPING) - set(DISABLE_DESKTOP_LOADER 1) -endif() if(ENABLE_INTERP_LIB) set(DISABLE_INTERPRETER 1) endif() diff --git a/src/mono/cmake/config.h.in b/src/mono/cmake/config.h.in index d7d4266..670b6ba 100644 --- a/src/mono/cmake/config.h.in +++ b/src/mono/cmake/config.h.in @@ -416,9 +416,6 @@ /* Disable generics support */ #cmakedefine DISABLE_GENERICS 1 -/* Disable Shadow Copy for AppDomains */ -#cmakedefine DISABLE_SHADOW_COPY 1 - /* Disable agent attach support */ #cmakedefine DISABLE_ATTACH 1 @@ -450,9 +447,6 @@ /* Disable String normalization support. */ #cmakedefine DISABLE_NORMALIZATION 1 -/* Disable desktop assembly loader semantics. */ -#cmakedefine DISABLE_DESKTOP_LOADER 1 - /* Disable shared perfcounters. */ #cmakedefine DISABLE_SHARED_PERFCOUNTERS 1 diff --git a/src/mono/cmake/options.cmake b/src/mono/cmake/options.cmake index 9bcc13c..79b9aed 100644 --- a/src/mono/cmake/options.cmake +++ b/src/mono/cmake/options.cmake @@ -14,7 +14,6 @@ option (DISABLE_LOGGING "Disable support debug logging") option (DISABLE_COM "Disable COM support") option (DISABLE_SSA "Disable advanced SSA JIT optimizations") option (DISABLE_GENERICS "Disable generics support") -option (DISABLE_SHADOW_COPY "Disable Shadow Copy for AppDomains") option (DISABLE_ATTACH "Disable agent attach support") option (DISABLE_VERIFIER "Disables the verifier") option (DISABLE_JIT "Disable the JIT, only full-aot mode or interpreter will be supported by the runtime.") @@ -23,7 +22,6 @@ option (DISABLE_SIMD "Disable SIMD intrinsics related optimizations.") option (DISABLE_DEBUGGER_AGENT "Disable Soft Debugger Agent.") option (DISABLE_PERFCOUNTERS "Disable Performance Counters.") option (DISABLE_NORMALIZATION "Disable String normalization support.") -option (DISABLE_DESKTOP_LOADER "Disable desktop assembly loader semantics.") option (DISABLE_SHARED_PERFCOUNTERS "Disable shared perfcounters.") option (DISABLE_APPDOMAINS "Disable support for multiple appdomains.") option (DISABLE_REMOTING "Disable remoting support (This disables type proxies and make com non-functional)") diff --git a/src/mono/mono/metadata/assembly.c b/src/mono/mono/metadata/assembly.c index 1c9f501..b059101 100644 --- a/src/mono/mono/metadata/assembly.c +++ b/src/mono/mono/metadata/assembly.c @@ -57,15 +57,6 @@ #include #endif -/* AssemblyVersionMap: an assembly name, the assembly version set on which it is based, the assembly name it is replaced with and whether only versions lower than the current runtime version should be remapped */ -typedef struct { - const char* assembly_name; - guint8 version_set_index; - const char* new_assembly_name; - gboolean only_lower_versions; - gboolean framework_facade_assembly; -} AssemblyVersionMap; - /* the default search path is empty, the first slot is replaced with the computed value */ static char* default_path [] = { @@ -77,280 +68,6 @@ default_path [] = { /* Contains the list of directories to be searched for assemblies (MONO_PATH) */ static char **assemblies_path = NULL; -#ifndef DISABLE_GAC -/* Contains the list of directories that point to auxiliary GACs */ -static char **extra_gac_paths = NULL; -#endif - -#ifndef DISABLE_DESKTOP_LOADER - -#define FACADE_ASSEMBLY(str) {str, 0, NULL, FALSE, TRUE} - -static GHashTable* assembly_remapping_table; -/* The list of system assemblies what will be remapped to the running - * runtime version. - * This list is stored in @assembly_remapping_table during initialization. - * Keep it sorted just to make maintenance easier. - * - * The integer number is an index in the MonoRuntimeInfo structure, whose - * values can be found in domain.c - supported_runtimes. Look there - * to understand what remapping will be made. - * - * .NET version can be found at https://github.com/dotnet/coreclr/blob/master/src/inc/fxretarget.h#L99 - * - */ -static const AssemblyVersionMap framework_assemblies [] = { - {"Accessibility", 0}, - {"Commons.Xml.Relaxng", 0}, - {"CustomMarshalers", 0}, - {"I18N", 0}, - {"I18N.CJK", 0}, - {"I18N.MidEast", 0}, - {"I18N.Other", 0}, - {"I18N.Rare", 0}, - {"I18N.West", 0}, - {"Microsoft.Build.Engine", 2, NULL, TRUE}, - {"Microsoft.Build.Framework", 2, NULL, TRUE}, - {"Microsoft.Build.Tasks", 2, "Microsoft.Build.Tasks.v4.0"}, - {"Microsoft.Build.Tasks.v3.5", 2, "Microsoft.Build.Tasks.v4.0"}, - {"Microsoft.Build.Utilities", 2, "Microsoft.Build.Utilities.v4.0"}, - {"Microsoft.Build.Utilities.v3.5", 2, "Microsoft.Build.Utilities.v4.0"}, - {"Microsoft.CSharp", 0}, - {"Microsoft.VisualBasic", 1}, - {"Microsoft.VisualC", 1}, - FACADE_ASSEMBLY ("Microsoft.Win32.Primitives"), - FACADE_ASSEMBLY ("Microsoft.Win32.Registry"), - FACADE_ASSEMBLY ("Microsoft.Win32.Registry.AccessControl"), - {"Mono.Cairo", 0}, - {"Mono.CompilerServices.SymbolWriter", 0}, - {"Mono.Data", 0}, - {"Mono.Data.SybaseClient", 0}, - {"Mono.Data.Tds", 0}, - {"Mono.Data.TdsClient", 0}, - {"Mono.GetOptions", 0}, - {"Mono.Http", 0}, - {"Mono.Posix", 0}, - {"Mono.Security", 0}, - {"Mono.Security.Win32", 0}, - {"Mono.Xml.Ext", 0}, - {"Novell.Directory.Ldap", 0}, - {"PEAPI", 0}, - {"System", 0}, - FACADE_ASSEMBLY ("System.AppContext"), - FACADE_ASSEMBLY ("System.Buffers"), - FACADE_ASSEMBLY ("System.Collections"), - FACADE_ASSEMBLY ("System.Collections.Concurrent"), - FACADE_ASSEMBLY ("System.Collections.NonGeneric"), - FACADE_ASSEMBLY ("System.Collections.Specialized"), - FACADE_ASSEMBLY ("System.ComponentModel"), - FACADE_ASSEMBLY ("System.ComponentModel.Annotations"), - {"System.ComponentModel.Composition", 2}, - {"System.ComponentModel.DataAnnotations", 2}, - FACADE_ASSEMBLY ("System.ComponentModel.EventBasedAsync"), - FACADE_ASSEMBLY ("System.ComponentModel.Primitives"), - FACADE_ASSEMBLY ("System.ComponentModel.TypeConverter"), - {"System.Configuration", 0}, - {"System.Configuration.Install", 0}, - FACADE_ASSEMBLY ("System.Console"), - {"System.Core", 2}, - {"System.Data", 0}, - FACADE_ASSEMBLY ("System.Data.Common"), - {"System.Data.DataSetExtensions", 0}, - {"System.Data.Entity", 0}, - {"System.Data.Linq", 2}, - {"System.Data.OracleClient", 0}, - {"System.Data.Services", 2}, - {"System.Data.Services.Client", 2}, - FACADE_ASSEMBLY ("System.Data.SqlClient"), - {"System.Data.SqlXml", 0}, - {"System.Deployment", 0}, - {"System.Design", 0}, - FACADE_ASSEMBLY ("System.Diagnostics.Contracts"), - FACADE_ASSEMBLY ("System.Diagnostics.Debug"), - FACADE_ASSEMBLY ("System.Diagnostics.FileVersionInfo"), - FACADE_ASSEMBLY ("System.Diagnostics.Process"), - FACADE_ASSEMBLY ("System.Diagnostics.StackTrace"), - FACADE_ASSEMBLY ("System.Diagnostics.TextWriterTraceListener"), - FACADE_ASSEMBLY ("System.Diagnostics.Tools"), - FACADE_ASSEMBLY ("System.Diagnostics.TraceEvent"), - FACADE_ASSEMBLY ("System.Diagnostics.TraceSource"), - FACADE_ASSEMBLY ("System.Diagnostics.Tracing"), - {"System.DirectoryServices", 0}, - {"System.DirectoryServices.Protocols", 0}, - {"System.Drawing", 0}, - FACADE_ASSEMBLY ("System.Drawing.Common"), - {"System.Drawing.Design", 0}, - FACADE_ASSEMBLY ("System.Drawing.Primitives"), - {"System.Dynamic", 0}, - FACADE_ASSEMBLY ("System.Dynamic.Runtime"), - {"System.EnterpriseServices", 0}, - FACADE_ASSEMBLY ("System.Globalization"), - FACADE_ASSEMBLY ("System.Globalization.Calendars"), - FACADE_ASSEMBLY ("System.Globalization.Extensions"), - {"System.IdentityModel", 3}, - {"System.IdentityModel.Selectors", 3}, - FACADE_ASSEMBLY ("System.IO"), - {"System.IO.Compression", 2}, - {"System.IO.Compression.FileSystem", 0}, - FACADE_ASSEMBLY ("System.IO.Compression.ZipFile"), - FACADE_ASSEMBLY ("System.IO.FileSystem"), - FACADE_ASSEMBLY ("System.IO.FileSystem.AccessControl"), - FACADE_ASSEMBLY ("System.IO.FileSystem.DriveInfo"), - FACADE_ASSEMBLY ("System.IO.FileSystem.Primitives"), - FACADE_ASSEMBLY ("System.IO.FileSystem.Watcher"), - FACADE_ASSEMBLY ("System.IO.IsolatedStorage"), - FACADE_ASSEMBLY ("System.IO.MemoryMappedFiles"), - FACADE_ASSEMBLY ("System.IO.Packaging"), - FACADE_ASSEMBLY ("System.IO.Pipes"), - FACADE_ASSEMBLY ("System.IO.UnmanagedMemoryStream"), - FACADE_ASSEMBLY ("System.Linq"), - FACADE_ASSEMBLY ("System.Linq.Expressions"), - FACADE_ASSEMBLY ("System.Linq.Parallel"), - FACADE_ASSEMBLY ("System.Linq.Queryable"), - {"System.Management", 0}, - FACADE_ASSEMBLY ("System.Memory"), - {"System.Messaging", 0}, - {"System.Net", 2}, - FACADE_ASSEMBLY ("System.Net.AuthenticationManager"), - FACADE_ASSEMBLY ("System.Net.Cache"), - {"System.Net.Http", 4}, - {"System.Net.Http.Rtc", 0}, - {"System.Net.Http.WebRequest", 0}, - FACADE_ASSEMBLY ("System.Net.HttpListener"), - FACADE_ASSEMBLY ("System.Net.Mail"), - FACADE_ASSEMBLY ("System.Net.NameResolution"), - FACADE_ASSEMBLY ("System.Net.NetworkInformation"), - FACADE_ASSEMBLY ("System.Net.Ping"), - FACADE_ASSEMBLY ("System.Net.Primitives"), - FACADE_ASSEMBLY ("System.Net.Requests"), - FACADE_ASSEMBLY ("System.Net.Security"), - FACADE_ASSEMBLY ("System.Net.ServicePoint"), - FACADE_ASSEMBLY ("System.Net.Sockets"), - FACADE_ASSEMBLY ("System.Net.Utilities"), - FACADE_ASSEMBLY ("System.Net.WebHeaderCollection"), - FACADE_ASSEMBLY ("System.Net.WebSockets"), - FACADE_ASSEMBLY ("System.Net.WebSockets.Client"), - {"System.Numerics", 3}, - {"System.Numerics.Vectors", 3}, - FACADE_ASSEMBLY ("System.ObjectModel"), - FACADE_ASSEMBLY ("System.Reflection"), - {"System.Reflection.Context", 0}, - FACADE_ASSEMBLY ("System.Reflection.DispatchProxy"), - FACADE_ASSEMBLY ("System.Reflection.Emit"), - FACADE_ASSEMBLY ("System.Reflection.Emit.ILGeneration"), - FACADE_ASSEMBLY ("System.Reflection.Emit.Lightweight"), - FACADE_ASSEMBLY ("System.Reflection.Extensions"), - FACADE_ASSEMBLY ("System.Reflection.Primitives"), - FACADE_ASSEMBLY ("System.Reflection.TypeExtensions"), - FACADE_ASSEMBLY ("System.Resources.Reader"), - FACADE_ASSEMBLY ("System.Resources.ReaderWriter"), - FACADE_ASSEMBLY ("System.Resources.ResourceManager"), - FACADE_ASSEMBLY ("System.Resources.Writer"), - FACADE_ASSEMBLY ("System.Runtime"), - {"System.Runtime.Caching", 0}, - FACADE_ASSEMBLY ("System.Runtime.CompilerServices.VisualC"), - {"System.Runtime.DurableInstancing", 0}, - FACADE_ASSEMBLY ("System.Runtime.Extensions"), - FACADE_ASSEMBLY ("System.Runtime.Handles"), - FACADE_ASSEMBLY ("System.Runtime.InteropServices"), - FACADE_ASSEMBLY ("System.Runtime.InteropServices.RuntimeInformation"), - FACADE_ASSEMBLY ("System.Runtime.InteropServices.WindowsRuntime"), - FACADE_ASSEMBLY ("System.Runtime.Loader"), - FACADE_ASSEMBLY ("System.Runtime.Numerics"), - {"System.Runtime.Remoting", 0}, - {"System.Runtime.Serialization", 3}, - FACADE_ASSEMBLY ("System.Runtime.Serialization.Formatters"), - {"System.Runtime.Serialization.Formatters.Soap", 0}, - FACADE_ASSEMBLY ("System.Runtime.Serialization.Json"), - FACADE_ASSEMBLY ("System.Runtime.Serialization.Primitives"), - FACADE_ASSEMBLY ("System.Runtime.Serialization.Xml"), - {"System.Security", 0}, - FACADE_ASSEMBLY ("System.Security.AccessControl"), - FACADE_ASSEMBLY ("System.Security.Claims"), - FACADE_ASSEMBLY ("System.Security.Cryptography.Algorithms"), - FACADE_ASSEMBLY ("System.Security.Cryptography.Cng"), - FACADE_ASSEMBLY ("System.Security.Cryptography.Csp"), - FACADE_ASSEMBLY ("System.Security.Cryptography.DeriveBytes"), - FACADE_ASSEMBLY ("System.Security.Cryptography.Encoding"), - FACADE_ASSEMBLY ("System.Security.Cryptography.Encryption"), - FACADE_ASSEMBLY ("System.Security.Cryptography.Encryption.Aes"), - FACADE_ASSEMBLY ("System.Security.Cryptography.Encryption.ECDiffieHellman"), - FACADE_ASSEMBLY ("System.Security.Cryptography.Encryption.ECDsa"), - FACADE_ASSEMBLY ("System.Security.Cryptography.Hashing"), - FACADE_ASSEMBLY ("System.Security.Cryptography.Hashing.Algorithms"), - FACADE_ASSEMBLY ("System.Security.Cryptography.OpenSsl"), - FACADE_ASSEMBLY ("System.Security.Cryptography.Pkcs"), - FACADE_ASSEMBLY ("System.Security.Cryptography.Primitives"), - FACADE_ASSEMBLY ("System.Security.Cryptography.ProtectedData"), - FACADE_ASSEMBLY ("System.Security.Cryptography.RSA"), - FACADE_ASSEMBLY ("System.Security.Cryptography.RandomNumberGenerator"), - FACADE_ASSEMBLY ("System.Security.Cryptography.X509Certificates"), - FACADE_ASSEMBLY ("System.Security.Principal"), - FACADE_ASSEMBLY ("System.Security.Principal.Windows"), - FACADE_ASSEMBLY ("System.Security.SecureString"), - {"System.ServiceModel", 3}, - {"System.ServiceModel.Activation", 0}, - {"System.ServiceModel.Discovery", 0}, - FACADE_ASSEMBLY ("System.ServiceModel.Duplex"), - FACADE_ASSEMBLY ("System.ServiceModel.Http"), - FACADE_ASSEMBLY ("System.ServiceModel.NetTcp"), - FACADE_ASSEMBLY ("System.ServiceModel.Primitives"), - {"System.ServiceModel.Routing", 0}, - FACADE_ASSEMBLY ("System.ServiceModel.Security"), - {"System.ServiceModel.Web", 2}, - {"System.ServiceProcess", 0}, - FACADE_ASSEMBLY ("System.ServiceProcess.ServiceController"), - FACADE_ASSEMBLY ("System.Text.Encoding"), - FACADE_ASSEMBLY ("System.Text.Encoding.CodePages"), - FACADE_ASSEMBLY ("System.Text.Encoding.Extensions"), - FACADE_ASSEMBLY ("System.Text.RegularExpressions"), - FACADE_ASSEMBLY ("System.Threading"), - FACADE_ASSEMBLY ("System.Threading.AccessControl"), - FACADE_ASSEMBLY ("System.Threading.Overlapped"), - FACADE_ASSEMBLY ("System.Threading.Tasks"), - {"System.Threading.Tasks.Dataflow", 0, NULL, TRUE}, - FACADE_ASSEMBLY ("System.Threading.Tasks.Extensions"), - FACADE_ASSEMBLY ("System.Threading.Tasks.Parallel"), - FACADE_ASSEMBLY ("System.Threading.Thread"), - FACADE_ASSEMBLY ("System.Threading.ThreadPool"), - FACADE_ASSEMBLY ("System.Threading.Timer"), - {"System.Transactions", 0}, - FACADE_ASSEMBLY ("System.ValueTuple"), - {"System.Web", 0}, - {"System.Web.Abstractions", 2}, - {"System.Web.ApplicationServices", 0}, - {"System.Web.DynamicData", 2}, - {"System.Web.Extensions", 2}, - {"System.Web.Extensions.Design", 0}, - {"System.Web.Mobile", 0}, - {"System.Web.RegularExpressions", 0}, - {"System.Web.Routing", 2}, - {"System.Web.Services", 0}, - {"System.Windows", 0}, - {"System.Windows.Forms", 0}, - {"System.Windows.Forms.DataVisualization", 0}, - {"System.Workflow.Activities", 0}, - {"System.Workflow.ComponentModel", 0}, - {"System.Workflow.Runtime", 0}, - {"System.Xaml", 0}, - {"System.Xml", 0}, - {"System.Xml.Linq", 2}, - FACADE_ASSEMBLY ("System.Xml.ReaderWriter"), - {"System.Xml.Serialization", 0}, - FACADE_ASSEMBLY ("System.Xml.XDocument"), - FACADE_ASSEMBLY ("System.Xml.XPath"), - FACADE_ASSEMBLY ("System.Xml.XPath.XmlDocument"), - FACADE_ASSEMBLY ("System.Xml.XPath.XDocument"), - FACADE_ASSEMBLY ("System.Xml.XmlDocument"), - FACADE_ASSEMBLY ("System.Xml.XmlSerializer"), - FACADE_ASSEMBLY ("System.Xml.Xsl.Primitives"), - {"WindowsBase", 3}, - {"cscompmgd", 0}, - {"mscorlib", 0}, - FACADE_ASSEMBLY ("netstandard"), -}; -#endif - /* keeps track of loaded assemblies, excluding dynamic ones */ static GList *loaded_assemblies = NULL; static MonoAssembly *corlib; @@ -377,23 +94,10 @@ static const MonoBundledAssembly **bundles; static const MonoBundledSatelliteAssembly **satellite_bundles; -static mono_mutex_t assembly_binding_mutex; - -/* Loaded assembly binding info */ -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 (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* -mono_assembly_load_full_gac_base_default (MonoAssemblyName *aname, const char *basedir, MonoAssemblyLoadContext *alc, MonoAssemblyContextKind asmctx, MonoImageOpenStatus *status); -static MonoAssembly* -chain_redirections_loadfrom (MonoAssemblyLoadContext *alc, MonoImage *image, MonoImageOpenStatus *out_status); -static MonoAssembly* -mono_problematic_image_reprobe (MonoAssemblyLoadContext *alc, MonoImage *image, MonoImageOpenStatus *status); static MonoAssembly * invoke_assembly_preload_hook (MonoAssemblyLoadContext *alc, MonoAssemblyName *aname, gchar **apath); @@ -401,13 +105,6 @@ invoke_assembly_preload_hook (MonoAssemblyLoadContext *alc, MonoAssemblyName *an static MonoBoolean mono_assembly_is_in_gac (const gchar *filanem); -static MonoAssembly* -prevent_reference_assembly_from_running (MonoAssembly* candidate, gboolean refonly); - -/* Assembly name matching */ -static gboolean -framework_assembly_sn_match (MonoAssemblyName *wanted_name, MonoAssemblyName *candidate_name); - static const char * mono_asmctx_get_name (const MonoAssemblyContext *asmctx); @@ -508,66 +205,6 @@ check_path_env (void) g_free (path); } -#ifndef DISABLE_GAC -static void -check_extra_gac_path_env (void) -{ - char *path; - char **splitted, **dest; - - path = g_getenv ("MONO_GAC_PREFIX"); - if (!path) - return; - - splitted = g_strsplit (path, G_SEARCHPATH_SEPARATOR_S, 1000); - g_free (path); - - if (extra_gac_paths) - g_strfreev (extra_gac_paths); - extra_gac_paths = dest = splitted; - while (*splitted){ - if (**splitted) - *dest++ = *splitted; - splitted++; - } - *dest = *splitted; - - if (!g_hasenv ("MONO_DEBUG")) - return; - - while (*splitted) { - if (**splitted && !g_file_test (*splitted, G_FILE_TEST_IS_DIR)) - g_warning ("'%s' in MONO_GAC_PREFIX doesn't exist or has wrong permissions.", *splitted); - - splitted++; - } -} -#endif /* DISABLE_GAC */ - -static gboolean -assembly_binding_maps_name (MonoAssemblyBindingInfo *info, MonoAssemblyName *aname) -{ - if (!info || !info->name) - return FALSE; - - if (strcmp (info->name, aname->name)) - return FALSE; - - if (info->major != aname->major || info->minor != aname->minor) - return FALSE; - - if ((info->culture != NULL && info->culture [0]) != (aname->culture != NULL && aname->culture [0])) - return FALSE; - - if (info->culture && aname->culture && strcmp (info->culture, aname->culture)) - return FALSE; - - if (!mono_public_tokens_are_equal (info->public_key_token, aname->public_key_token)) - return FALSE; - - return TRUE; -} - static void mono_assembly_binding_info_free (MonoAssemblyBindingInfo *info) { @@ -578,103 +215,6 @@ mono_assembly_binding_info_free (MonoAssemblyBindingInfo *info) g_free (info->culture); } -static void -get_publisher_policy_info (MonoImage *image, MonoAssemblyName *aname, MonoAssemblyBindingInfo *binding_info) -{ - MonoTableInfo *t; - guint32 cols [MONO_MANIFEST_SIZE]; - const gchar *filename; - gchar *subpath, *fullpath; - - t = &image->tables [MONO_TABLE_MANIFESTRESOURCE]; - /* MS Impl. accepts policy assemblies with more than - * one manifest resource, and only takes the first one */ - if (t->rows < 1) { - binding_info->is_valid = FALSE; - return; - } - - mono_metadata_decode_row (t, 0, cols, MONO_MANIFEST_SIZE); - if ((cols [MONO_MANIFEST_IMPLEMENTATION] & MONO_IMPLEMENTATION_MASK) != MONO_IMPLEMENTATION_FILE) { - binding_info->is_valid = FALSE; - return; - } - - filename = mono_metadata_string_heap (image, cols [MONO_MANIFEST_NAME]); - g_assert (filename != NULL); - - subpath = g_path_get_dirname (image->name); - fullpath = g_build_path (G_DIR_SEPARATOR_S, subpath, filename, (const char*)NULL); - mono_config_parse_publisher_policy (fullpath, binding_info); - g_free (subpath); - g_free (fullpath); - - /* Define the optional elements/attributes before checking */ - if (!binding_info->culture) - binding_info->culture = g_strdup (""); - - /* Check that the most important elements/attributes exist */ - if (!binding_info->name || !binding_info->public_key_token [0] || !binding_info->has_old_version_bottom || - !binding_info->has_new_version || !assembly_binding_maps_name (binding_info, aname)) { - mono_assembly_binding_info_free (binding_info); - binding_info->is_valid = FALSE; - return; - } - - binding_info->is_valid = TRUE; -} - -static int -compare_versions (AssemblyVersionSet *v, MonoAssemblyName *aname) -{ - if (v->major > aname->major) - return 1; - else if (v->major < aname->major) - return -1; - - if (v->minor > aname->minor) - return 1; - else if (v->minor < aname->minor) - return -1; - - if (v->build > aname->build) - return 1; - else if (v->build < aname->build) - return -1; - - if (v->revision > aname->revision) - return 1; - else if (v->revision < aname->revision) - return -1; - - return 0; -} - -static gboolean -check_policy_versions (MonoAssemblyBindingInfo *info, MonoAssemblyName *name) -{ - if (!info->is_valid) - return FALSE; - - /* If has_old_version_top doesn't exist, we don't have an interval */ - if (!info->has_old_version_top) { - if (compare_versions (&info->old_version_bottom, name) == 0) - return TRUE; - - return FALSE; - } - - /* Check that the version defined by name is valid for the interval */ - if (compare_versions (&info->old_version_top, name) < 0) - return FALSE; - - /* We should be greater or equal than the small version */ - if (compare_versions (&info->old_version_bottom, name) > 0) - return FALSE; - - return TRUE; -} - /** * mono_assembly_names_equal: * \param l first assembly @@ -1101,35 +641,10 @@ mono_assemblies_init (void) mono_set_rootdir (); check_path_env (); -#ifndef DISABLE_GAC - check_extra_gac_path_env (); -#endif mono_os_mutex_init_recursive (&assemblies_mutex); - mono_os_mutex_init (&assembly_binding_mutex); - -#ifndef DISABLE_DESKTOP_LOADER - assembly_remapping_table = g_hash_table_new (g_str_hash, g_str_equal); - - int i; - for (i = 0; i < G_N_ELEMENTS (framework_assemblies); ++i) - g_hash_table_insert (assembly_remapping_table, (void*)framework_assemblies [i].assembly_name, (void*)&framework_assemblies [i]); -#endif mono_install_assembly_asmctx_from_path_hook (assembly_loadfrom_asmctx_from_path, NULL); - -} - -static void -mono_assembly_binding_lock (void) -{ - mono_locks_os_acquire (&assembly_binding_mutex, AssemblyBindingLock); -} - -static void -mono_assembly_binding_unlock (void) -{ - mono_locks_os_release (&assembly_binding_mutex, AssemblyBindingLock); } gboolean @@ -1440,62 +955,6 @@ mono_assembly_remap_version (MonoAssemblyName *aname, MonoAssemblyName *dest_ana return dest_aname; } - -#ifndef DISABLE_DESKTOP_LOADER - const AssemblyVersionMap *vmap = (AssemblyVersionMap *)g_hash_table_lookup (assembly_remapping_table, aname->name); - if (vmap) { - const AssemblyVersionSet* vset; - int index = vmap->version_set_index; - g_assert (index < G_N_ELEMENTS (current_runtime->version_sets)); - vset = ¤t_runtime->version_sets [index]; - - if (vmap->framework_facade_assembly) { - mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_ASSEMBLY, "Assembly %s is a framework Facade asseembly", - aname->name); - return aname; - } - - if (aname->major == vset->major && aname->minor == vset->minor && - aname->build == vset->build && aname->revision == vset->revision) { - mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_ASSEMBLY, "Found assembly remapping for %s and was for the same version %d.%d.%d.%d", - aname->name, - aname->major, aname->minor, aname->build, aname->revision); - return aname; - } - - if (vmap->only_lower_versions && compare_versions ((AssemblyVersionSet*)vset, aname) < 0) { - mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_ASSEMBLY, - "Found lower-versions-only assembly remaping to load %s %d.%d.%d.%d but mapping has %d.%d.%d.%d", - aname->name, - aname->major, aname->minor, aname->build, aname->revision, - vset->major, vset->minor, vset->build, vset->revision - ); - return aname; - } - - if ((aname->major | aname->minor | aname->build | aname->revision) != 0) - mono_trace (G_LOG_LEVEL_WARNING, MONO_TRACE_ASSEMBLY, - "The request to load the assembly %s v%d.%d.%d.%d was remapped to v%d.%d.%d.%d", - aname->name, - aname->major, aname->minor, aname->build, aname->revision, - vset->major, vset->minor, vset->build, vset->revision - ); - - memcpy (dest_aname, aname, sizeof(MonoAssemblyName)); - dest_aname->major = vset->major; - dest_aname->minor = vset->minor; - dest_aname->build = vset->build; - dest_aname->revision = vset->revision; - if (vmap->new_assembly_name != NULL) { - dest_aname->name = vmap->new_assembly_name; - mono_trace (G_LOG_LEVEL_WARNING, MONO_TRACE_ASSEMBLY, - "The assembly name %s was remapped to %s", - aname->name, - dest_aname->name); - } - return dest_aname; - } -#endif return aname; } @@ -2178,29 +1637,6 @@ invoke_assembly_preload_hook (MonoAssemblyLoadContext *alc, MonoAssemblyName *an return NULL; } -static MonoAssembly * -invoke_assembly_refonly_preload_hook (MonoAssemblyLoadContext *alc, MonoAssemblyName *aname, gchar **apath) -{ - AssemblyPreLoadHook *hook; - MonoAssembly *assembly; - - for (hook = assembly_refonly_preload_hook; hook; hook = hook->next) { - if (hook->version == 1) - assembly = hook->func.v1 (aname, apath, hook->user_data); - else { - ERROR_DECL (error); - g_assert (hook->version == 2); - assembly = hook->func.v2 (alc, aname, apath, TRUE, hook->user_data, error); - /* TODO: propagate error out to callers */ - mono_error_assert_ok (error); - } - if (assembly != NULL) - return assembly; - } - - return NULL; -} - /** * mono_install_assembly_preload_hook: */ @@ -2525,7 +1961,8 @@ mono_assembly_open_full (const char *filename, MonoImageOpenStatus *status, gboo static gboolean assembly_loadfrom_asmctx_from_path (const char *filename, MonoAssembly *requesting_assembly, - gpointer user_data, MonoAssemblyContextKind *out_asmctx) { + gpointer user_data, MonoAssemblyContextKind *out_asmctx) +{ if (requesting_assembly && mono_asmctx_get_kind (&requesting_assembly->context) == MONO_ASMCTX_LOADFROM) { if (mono_path_filename_in_basedir (filename, requesting_assembly->basedir)) { *out_asmctx = MONO_ASMCTX_LOADFROM; @@ -2651,22 +2088,6 @@ mono_assembly_request_open (const char *filename, const MonoAssemblyOpenRequest return NULL; } - if (load_req.asmctx == MONO_ASMCTX_LOADFROM || load_req.asmctx == MONO_ASMCTX_INDIVIDUAL) { - MonoAssembly *redirected_asm = NULL; - MonoImageOpenStatus new_status = MONO_IMAGE_OK; - if ((redirected_asm = chain_redirections_loadfrom (load_req.alc, image, &new_status))) { - mono_image_close (image); - image = redirected_asm->image; - mono_image_addref (image); /* so that mono_image_close, below, has something to do */ - /* fall thru to if (image->assembly) below */ - } else if (new_status != MONO_IMAGE_OK) { - *status = new_status; - mono_image_close (image); - g_free (fname); - return NULL; - } - } - if (image->assembly) { /* We want to return the MonoAssembly that's already loaded, * but if we're using the strict assembly loader, we also need @@ -2849,93 +2270,6 @@ mono_assembly_has_reference_assembly_attribute (MonoAssembly *assembly, MonoErro } /** - * chain_redirections_loadfrom: - * \param alc AssemblyLoadContext to load into - * \param image a MonoImage that we wanted to load using LoadFrom context - * \param status set if there was an error opening the redirected image - * - * Check if we need to open a different image instead of the given one for some reason. - * Returns NULL and sets status to \c MONO_IMAGE_OK if the given image was good. - * - * Otherwise returns the assembly that we opened instead or sets status if - * there was a problem opening the redirected image. - * - */ -MonoAssembly* -chain_redirections_loadfrom (MonoAssemblyLoadContext *alc, MonoImage *image, MonoImageOpenStatus *out_status) -{ - MonoImageOpenStatus status = MONO_IMAGE_OK; - MonoAssembly *redirected = NULL; - - redirected = mono_problematic_image_reprobe (alc, image, &status); - if (redirected || status != MONO_IMAGE_OK) { - *out_status = status; - return redirected; - } - - *out_status = MONO_IMAGE_OK; - return NULL; -} - -/** - * mono_problematic_image_reprobe: - * \param alc AssemblyLoadContex to load into - * \param image A MonoImage - * \param status set on error - * - * If the given image is problematic for mono (see image.c), then try to load - * by assembly name in the default context (which should succeed with Mono's - * own implementations of those assemblies). - * - * Returns NULL and sets status to MONO_IMAGE_OK if no redirect is needed. - * - * Otherwise returns the assembly we were redirected to, or NULL and sets a - * non-ok status on failure. - * - * IMPORTANT NOTE: Don't call this if \c image was found by probing the search - * path, you will end up in a loop and a stack overflow. - */ -MonoAssembly* -mono_problematic_image_reprobe (MonoAssemblyLoadContext *alc, MonoImage *image, MonoImageOpenStatus *status) -{ - g_assert (status != NULL); - - if (G_LIKELY (!mono_is_problematic_image (image))) { - *status = MONO_IMAGE_OK; - return NULL; - } - MonoAssemblyName probed_aname; - if (!mono_assembly_fill_assembly_name_full (image, &probed_aname, TRUE)) { - *status = MONO_IMAGE_IMAGE_INVALID; - return NULL; - } - if (mono_trace_is_traced (G_LOG_LEVEL_DEBUG, MONO_TRACE_ASSEMBLY)) { - char *probed_fullname = mono_stringify_assembly_name (&probed_aname); - mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_ASSEMBLY, "Requested to load from problematic image %s, probing instead for assembly with name %s", image->name, probed_fullname); - g_free (probed_fullname); - } - const char *new_basedir = NULL; - MonoAssemblyContextKind new_asmctx = MONO_ASMCTX_DEFAULT; - MonoAssembly *new_requesting = NULL; - MonoImageOpenStatus new_status = MONO_IMAGE_OK; - MonoAssemblyByNameRequest new_req; - mono_assembly_request_prepare_byname (&new_req, new_asmctx, alc); - new_req.requesting_assembly = new_requesting; - new_req.basedir = new_basedir; - // Note: this interacts with mono_image_open_a_lot (). If the path from - // which we tried to load the problematic image is among the probing - // paths, the MonoImage will be in the hash of loaded images and we - // would just get it back again here, except for the code there that - // mitigates the situation. Instead - MonoAssembly *result_ass = mono_assembly_request_byname (&probed_aname, &new_req, &new_status); - - if (! (result_ass && new_status == MONO_IMAGE_OK)) { - *status = new_status; - } - mono_assembly_name_free_internal (&probed_aname); - return result_ass; -} -/** * mono_assembly_open: * \param filename Opens the assembly pointed out by this name * \param status return status code @@ -3404,23 +2738,6 @@ build_assembly_name (const char *name, const char *version, const char *culture, } static gboolean -parse_assembly_directory_name (const char *name, const char *dirname, MonoAssemblyName *aname) -{ - gchar **parts; - gboolean res; - - parts = g_strsplit (dirname, "_", 3); - if (!parts || !parts[0] || !parts[1] || !parts[2]) { - g_strfreev (parts); - return FALSE; - } - - res = build_assembly_name (name, parts[0], parts[1], parts[2], NULL, 0, 0, aname, FALSE); - g_strfreev (parts); - return res; -} - -static gboolean split_key_value (const gchar *pair, gchar **key, guint32 *keylen, gchar **value) { char *eqsign = (char*)strchr (pair, '='); @@ -3738,79 +3055,6 @@ mono_assembly_name_culture_is_neutral (const MonoAssemblyName *aname) return (!aname->culture || aname->culture [0] == 0); } -static MonoAssembly* -probe_for_partial_name (const char *basepath, const char *fullname, MonoAssemblyLoadContext *alc, MonoAssemblyName *aname, MonoImageOpenStatus *status) -{ - gchar *fullpath = NULL; - GDir *dirhandle; - const char* direntry; - MonoAssemblyName gac_aname; - gint major=-1, minor=0, build=0, revision=0; - gboolean exact_version; - - dirhandle = g_dir_open (basepath, 0, NULL); - if (!dirhandle) - return NULL; - - exact_version = (aname->major | aname->minor | aname->build | aname->revision) != 0; - - while ((direntry = g_dir_read_name (dirhandle))) { - gboolean match = TRUE; - - if(!parse_assembly_directory_name (aname->name, direntry, &gac_aname)) - continue; - - if (aname->culture != NULL && strcmp (aname->culture, gac_aname.culture) != 0) - match = FALSE; - - if (match && strlen ((char*)aname->public_key_token) > 0 && - !mono_public_tokens_are_equal (aname->public_key_token, gac_aname.public_key_token)) - match = FALSE; - - if (match) { - if (exact_version) { - match = (aname->major == gac_aname.major && aname->minor == gac_aname.minor && - aname->build == gac_aname.build && aname->revision == gac_aname.revision); - } - else if (gac_aname.major < major) - match = FALSE; - else if (gac_aname.major == major) { - if (gac_aname.minor < minor) - match = FALSE; - else if (gac_aname.minor == minor) { - if (gac_aname.build < build) - match = FALSE; - else if (gac_aname.build == build && gac_aname.revision <= revision) - match = FALSE; - } - } - } - - if (match) { - major = gac_aname.major; - minor = gac_aname.minor; - build = gac_aname.build; - revision = gac_aname.revision; - g_free (fullpath); - fullpath = g_build_path (G_DIR_SEPARATOR_S, basepath, direntry, fullname, (const char*)NULL); - } - - mono_assembly_name_free_internal (&gac_aname); - } - - g_dir_close (dirhandle); - - if (fullpath == NULL) - return NULL; - else { - MonoAssemblyOpenRequest req; - mono_assembly_request_prepare_open (&req, MONO_ASMCTX_DEFAULT, alc); - MonoAssembly *res = mono_assembly_request_open (fullpath, &req, status); - g_free (fullpath); - return res; - } -} - /** * mono_assembly_load_with_partial_name: * \param name an assembly name that is then parsed by `api:mono_assembly_name_parse`. @@ -3879,37 +3123,6 @@ mono_assembly_load_with_partial_name_internal (const char *name, MonoAssemblyLoa return res; } -#ifndef DISABLE_GAC - gchar *fullname, *gacpath; - gchar **paths; - fullname = g_strdup_printf ("%s.dll", aname->name); - - if (extra_gac_paths) { - paths = extra_gac_paths; - while (!res && *paths) { - gacpath = g_build_path (G_DIR_SEPARATOR_S, *paths, "lib", "mono", "gac", aname->name, (const char*)NULL); - res = probe_for_partial_name (gacpath, fullname, alc, aname, status); - g_free (gacpath); - paths++; - } - } - - if (res) { - res->in_gac = TRUE; - g_free (fullname); - mono_assembly_name_free_internal (aname); - return res; - } - - gacpath = g_build_path (G_DIR_SEPARATOR_S, mono_assembly_getrootdir (), "mono", "gac", aname->name, (const char*)NULL); - res = probe_for_partial_name (gacpath, fullname, alc, aname, status); - g_free (gacpath); - - g_free (fullname); - if (res) - res->in_gac = TRUE; -#endif - mono_assembly_name_free_internal (aname); if (!res) { @@ -3927,386 +3140,9 @@ mono_assembly_load_with_partial_name_internal (const char *name, MonoAssemblyLoa static MonoBoolean mono_assembly_is_in_gac (const gchar *filename) { -#ifndef DISABLE_GAC - const gchar *rootdir; - gchar *gp; - gchar **paths; - - if (filename == NULL) - return FALSE; - - for (paths = extra_gac_paths; paths && *paths; paths++) { - if (strstr (*paths, filename) != *paths) - continue; - - gp = (gchar *) (filename + strlen (*paths)); - if (*gp != G_DIR_SEPARATOR) - continue; - gp++; - if (strncmp (gp, "lib", 3)) - continue; - gp += 3; - if (*gp != G_DIR_SEPARATOR) - continue; - gp++; - if (strncmp (gp, "mono", 4)) - continue; - gp += 4; - if (*gp != G_DIR_SEPARATOR) - continue; - gp++; - if (strncmp (gp, "gac", 3)) - continue; - gp += 3; - if (*gp != G_DIR_SEPARATOR) - continue; - - return TRUE; - } - - rootdir = mono_assembly_getrootdir (); - if (strstr (filename, rootdir) != filename) - return FALSE; - - gp = (gchar *) (filename + strlen (rootdir)); - if (*gp != G_DIR_SEPARATOR) - return FALSE; - gp++; - if (strncmp (gp, "mono", 4)) - return FALSE; - gp += 4; - if (*gp != G_DIR_SEPARATOR) - return FALSE; - gp++; - if (strncmp (gp, "gac", 3)) - return FALSE; - gp += 3; - if (*gp != G_DIR_SEPARATOR) - return FALSE; - return TRUE; -#else return FALSE; -#endif /* DISABLE_GAC */ -} - -static MonoImage* -mono_assembly_load_publisher_policy (MonoAssemblyName *aname) -{ - MonoImage *image = NULL; -#ifndef DISABLE_GAC - gchar *filename, *pname, *name, *culture, *version, *fullpath, *subpath; - gchar **paths; - gint32 len; - - if (strstr (aname->name, ".dll")) { - len = strlen (aname->name) - 4; - name = (gchar *)g_malloc (len + 1); - memcpy (name, aname->name, len); - name[len] = 0; - } else - name = g_strdup (aname->name); - - if (aname->culture) - culture = g_utf8_strdown (aname->culture, -1); - else - culture = g_strdup (""); - - pname = g_strdup_printf ("policy.%d.%d.%s", aname->major, aname->minor, name); - version = g_strdup_printf ("0.0.0.0_%s_%s", culture, aname->public_key_token); - g_free (name); - g_free (culture); - - filename = g_strconcat (pname, ".dll", (const char*)NULL); - subpath = g_build_path (G_DIR_SEPARATOR_S, pname, version, filename, (const char*)NULL); - g_free (pname); - g_free (version); - g_free (filename); - - image = NULL; - if (extra_gac_paths) { - paths = extra_gac_paths; - while (!image && *paths) { - fullpath = g_build_path (G_DIR_SEPARATOR_S, *paths, - "lib", "mono", "gac", subpath, (const char*)NULL); - image = mono_image_open (fullpath, NULL); - g_free (fullpath); - paths++; - } - } - - if (image) { - g_free (subpath); - return image; - } - - fullpath = g_build_path (G_DIR_SEPARATOR_S, mono_assembly_getrootdir (), - "mono", "gac", subpath, NULL); - image = mono_image_open (fullpath, NULL); - g_free (subpath); - g_free (fullpath); -#endif - - return image; -} - -static MonoAssemblyName* -mono_assembly_bind_version (MonoAssemblyBindingInfo *info, MonoAssemblyName *aname, MonoAssemblyName *dest_name) -{ - memcpy (dest_name, aname, sizeof (MonoAssemblyName)); - dest_name->major = info->new_version.major; - dest_name->minor = info->new_version.minor; - dest_name->build = info->new_version.build; - dest_name->revision = info->new_version.revision; - - return dest_name; -} - -/* LOCKING: assembly_binding lock must be held */ -static MonoAssemblyBindingInfo* -search_binding_loaded (MonoAssemblyName *aname) -{ - GSList *tmp; - - for (tmp = loaded_assembly_bindings; tmp; tmp = tmp->next) { - MonoAssemblyBindingInfo *info = (MonoAssemblyBindingInfo *)tmp->data; - if (assembly_binding_maps_name (info, aname)) - return info; - } - - return NULL; -} - -static gboolean -info_compare_versions (AssemblyVersionSet *left, AssemblyVersionSet *right) -{ - if (left->major != right->major || left->minor != right->minor || - left->build != right->build || left->revision != right->revision) - return FALSE; - - return TRUE; -} - -static gboolean -info_versions_equal (MonoAssemblyBindingInfo *left, MonoAssemblyBindingInfo *right) -{ - if (left->has_old_version_bottom != right->has_old_version_bottom) - return FALSE; - - if (left->has_old_version_top != right->has_old_version_top) - return FALSE; - - if (left->has_new_version != right->has_new_version) - return FALSE; - - if (left->has_old_version_bottom && !info_compare_versions (&left->old_version_bottom, &right->old_version_bottom)) - return FALSE; - - if (left->has_old_version_top && !info_compare_versions (&left->old_version_top, &right->old_version_top)) - return FALSE; - - if (left->has_new_version && !info_compare_versions (&left->new_version, &right->new_version)) - return FALSE; - - return TRUE; -} - -/* LOCKING: assumes all the necessary locks are held */ -static void -assembly_binding_info_parsed (MonoAssemblyBindingInfo *info, void *user_data) -{ - MonoAssemblyBindingInfo *info_copy; - GSList *tmp; - MonoAssemblyBindingInfo *info_tmp; - MonoDomain *domain = (MonoDomain*)user_data; - MonoMemoryManager *memory_manager = mono_domain_ambient_memory_manager (domain); // linked with mono_domain_parse_assembly_bindings - - if (!domain) - return; - - if (info->has_new_version && mono_assembly_is_problematic_version (info->name, info->new_version.major, info->new_version.minor, info->new_version.build, info->new_version.revision)) { - mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_ASSEMBLY, "Discarding assembly binding to problematic version %s v%d.%d.%d.%d", - info->name, info->new_version.major, info->new_version.minor, info->new_version.build, info->new_version.revision); - return; - } - - for (tmp = domain->assembly_bindings; tmp; tmp = tmp->next) { - info_tmp = (MonoAssemblyBindingInfo *)tmp->data; - if (strcmp (info->name, info_tmp->name) == 0 && info_versions_equal (info, info_tmp)) - return; - } - - info_copy = (MonoAssemblyBindingInfo *)mono_mem_manager_alloc0_nolock (memory_manager, sizeof (MonoAssemblyBindingInfo)); - memcpy (info_copy, info, sizeof (MonoAssemblyBindingInfo)); - if (info->name) - info_copy->name = mono_mempool_strdup (memory_manager->mp, info->name); - if (info->culture) - info_copy->culture = mono_mempool_strdup (memory_manager->mp, info->culture); - - domain->assembly_bindings = g_slist_append_mempool (memory_manager->mp, domain->assembly_bindings, info_copy); -} - -static int -get_version_number (int major, int minor) -{ - return major * 256 + minor; -} - -static gboolean -info_major_minor_in_range (MonoAssemblyBindingInfo *info, MonoAssemblyName *aname) -{ - int aname_version_number = get_version_number (aname->major, aname->minor); - if (!info->has_old_version_bottom) - return FALSE; - - if (get_version_number (info->old_version_bottom.major, info->old_version_bottom.minor) > aname_version_number) - return FALSE; - - if (info->has_old_version_top && get_version_number (info->old_version_top.major, info->old_version_top.minor) < aname_version_number) - return FALSE; - - /* This is not the nicest way to do it, but it's a by-product of the way parsing is done */ - info->major = aname->major; - info->minor = aname->minor; - - return TRUE; } -/* LOCKING: Assumes that we are already locked - both loader and domain locks */ -static MonoAssemblyBindingInfo* -get_per_domain_assembly_binding_info (MonoDomain *domain, MonoAssemblyName *aname) -{ - MonoAssemblyBindingInfo *info; - GSList *list; - - if (!domain->assembly_bindings) - return NULL; - - info = NULL; - for (list = domain->assembly_bindings; list; list = list->next) { - info = (MonoAssemblyBindingInfo *)list->data; - if (info && !strcmp (aname->name, info->name) && info_major_minor_in_range (info, aname)) - break; - info = NULL; - } - - if (info) { - if (info->name && info->public_key_token [0] && info->has_old_version_bottom && - info->has_new_version && assembly_binding_maps_name (info, aname)) - info->is_valid = TRUE; - else - info->is_valid = FALSE; - } - - return info; -} - -void -mono_domain_parse_assembly_bindings (MonoDomain *domain, int amajor, int aminor, gchar *domain_config_file_name) -{ - if (domain->assembly_bindings_parsed) - return; - - MonoMemoryManager *memory_manager = mono_domain_ambient_memory_manager (domain); // linked with assembly_binding_info_parsed - - mono_domain_lock (domain); - mono_mem_manager_lock (memory_manager); - if (!domain->assembly_bindings_parsed) { - - gchar *domain_config_file_path = mono_portability_find_file (domain_config_file_name, TRUE); - - if (!domain_config_file_path) - domain_config_file_path = domain_config_file_name; - - mono_config_parse_assembly_bindings (domain_config_file_path, amajor, aminor, domain, assembly_binding_info_parsed); - domain->assembly_bindings_parsed = TRUE; - if (domain_config_file_name != domain_config_file_path) - g_free (domain_config_file_path); - } - - mono_mem_manager_unlock (memory_manager); - mono_domain_unlock (domain); -} - -#ifndef DISABLE_GAC -/** - * mono_assembly_load_from_gac - * - * \param aname The assembly name object - */ -static MonoAssembly* -mono_assembly_load_from_gac (MonoAssemblyName *aname, gchar *filename, MonoImageOpenStatus *status, MonoBoolean refonly) -{ - MonoAssembly *result = NULL; - gchar *name, *version, *culture, *fullpath, *subpath; - gint32 len; - gchar **paths; - char *pubtok; - - if (aname->public_key_token [0] == 0) { - return NULL; - } - - if (strstr (aname->name, ".dll")) { - len = strlen (filename) - 4; - name = (gchar *)g_malloc (len + 1); - memcpy (name, aname->name, len); - name[len] = 0; - } else { - name = g_strdup (aname->name); - } - - if (aname->culture) { - culture = g_utf8_strdown (aname->culture, -1); - } else { - culture = g_strdup (""); - } - - pubtok = g_ascii_strdown ((char*)aname->public_key_token, MONO_PUBLIC_KEY_TOKEN_LENGTH); - version = g_strdup_printf ("%d.%d.%d.%d_%s_%s", aname->major, - aname->minor, aname->build, aname->revision, - culture, pubtok); - g_free (pubtok); - - subpath = g_build_path (G_DIR_SEPARATOR_S, name, version, filename, (const char*)NULL); - g_free (name); - g_free (version); - g_free (culture); - - MonoAssemblyOpenRequest req; - mono_assembly_request_prepare_open (&req, - refonly ? MONO_ASMCTX_REFONLY : MONO_ASMCTX_DEFAULT, - mono_domain_default_alc (mono_domain_get ())); - - if (extra_gac_paths) { - paths = extra_gac_paths; - while (!result && *paths) { - fullpath = g_build_path (G_DIR_SEPARATOR_S, *paths, "lib", "mono", "gac", subpath, (const char*)NULL); - result = mono_assembly_request_open (fullpath, &req, status); - g_free (fullpath); - paths++; - } - } - - if (result) { - result->in_gac = TRUE; - g_free (subpath); - return result; - } - - fullpath = g_build_path (G_DIR_SEPARATOR_S, mono_assembly_getrootdir (), - "mono", "gac", subpath, (const char*)NULL); - result = mono_assembly_request_open (fullpath, &req, status); - g_free (fullpath); - - if (result) - result->in_gac = TRUE; - - g_free (subpath); - - return result; -} -#endif /* DISABLE_GAC */ - MonoAssembly* mono_assembly_load_corlib (const MonoRuntimeInfo *runtime, MonoImageOpenStatus *status) { @@ -4339,20 +3175,6 @@ mono_assembly_load_corlib (const MonoRuntimeInfo *runtime, MonoImageOpenStatus * return corlib; } -static MonoAssembly* -prevent_reference_assembly_from_running (MonoAssembly* candidate, gboolean refonly) -{ - ERROR_DECL (refasm_error); - if (candidate && !refonly) { - /* .NET Framework seems to not check for ReferenceAssemblyAttribute on dynamic assemblies */ - if (!image_is_dynamic (candidate->image) && - mono_assembly_has_reference_assembly_attribute (candidate, refasm_error)) - candidate = NULL; - } - mono_error_cleanup (refasm_error); - return candidate; -} - gboolean mono_assembly_candidate_predicate_sn_same_name (MonoAssembly *candidate, gpointer ud) { @@ -4387,130 +3209,6 @@ mono_assembly_check_name_match (MonoAssemblyName *wanted_name, MonoAssemblyName } -gboolean -framework_assembly_sn_match (MonoAssemblyName *wanted_name, MonoAssemblyName *candidate_name) -{ -#ifndef DISABLE_DESKTOP_LOADER - g_assert (wanted_name != NULL); - g_assert (candidate_name != NULL); - const AssemblyVersionMap *vmap = (AssemblyVersionMap *)g_hash_table_lookup (assembly_remapping_table, wanted_name->name); - if (vmap) { - if (!vmap->framework_facade_assembly) { - /* If the wanted name is a framework assembly, it's enough for the name/version/culture to match. If the assembly was remapped, the public key token is likely unrelated. */ - gboolean result = mono_assembly_names_equal_flags (wanted_name, candidate_name, MONO_ANAME_EQ_IGNORE_PUBKEY); - mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_ASSEMBLY, "Predicate: candidate and wanted names %s (ignoring the public key token)", result ? "match, returning TRUE" : "don't match, returning FALSE"); - return result; - } else { - /* For facades, the name and public key token should - * match, but the version doesn't matter as long as the - * candidate is not older. */ - gboolean result = mono_assembly_names_equal_flags (wanted_name, candidate_name, MONO_ANAME_EQ_IGNORE_VERSION); - mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_ASSEMBLY, "Predicate: candidate and wanted names %s (ignoring version)", result ? "match" : "don't match, returning FALSE"); - if (result) { - // compare major of candidate and wanted - int c = assembly_names_compare_versions (candidate_name, wanted_name, 1); - mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_ASSEMBLY, "Predicate: candidate major version is %s wanted major version, returning %s\n", c == 0 ? "the same as" : (c < 0 ? "lower than" : "greater than"), - (c >= 0) ? "TRUE" : "FALSE"); - return (c >= 0); // don't accept a candidate that's older than wanted. - } else { - return FALSE; - } - } - } -#endif - return FALSE; -} - -/* Like mono_assembly_request_byname_nosearch, but don't ask the preload look (ie, - * the appdomain) to run. Just looks in the gac, the specified base dir or the - * default_path. Does NOT look in the appdomain application base or in the - * MONO_PATH. - */ -MonoAssembly* -mono_assembly_load_full_gac_base_default (MonoAssemblyName *aname, - const char *basedir, - MonoAssemblyLoadContext *alc, - MonoAssemblyContextKind asmctx, - MonoImageOpenStatus *status) -{ - MonoAssembly *result; - MonoAssemblyName maped_aname; - char *fullpath, *filename; - int ext_index; - const char *ext; - int len; - - /* If we remap e.g. 4.1.3.0 to 4.0.0.0, look in the 4.0.0.0 - * GAC directory, not 4.1.3.0 */ - aname = mono_assembly_remap_version (aname, &maped_aname); - - /* Currently we retrieve the loaded corlib for reflection - * only requests, like a common reflection only assembly - */ - gboolean name_is_corlib = strcmp (aname->name, MONO_ASSEMBLY_CORLIB_NAME) == 0; - /* Assembly.Load (new AssemblyName ("mscorlib.dll")) (respectively, - * "System.Private.CoreLib.dll" for netcore) is treated the same as - * "mscorlib" (resp "System.Private.CoreLib"). */ - name_is_corlib = name_is_corlib || strcmp (aname->name, MONO_ASSEMBLY_CORLIB_NAME ".dll") == 0; - if (name_is_corlib) { - return mono_assembly_load_corlib (mono_get_runtime_info (), status); - } - - MonoAssemblyCandidatePredicate predicate = NULL; - void* predicate_ud = NULL; - if (mono_loader_get_strict_assembly_name_check ()) { - predicate = &mono_assembly_candidate_predicate_sn_same_name; - predicate_ud = aname; - } - - MonoAssemblyOpenRequest req; - mono_assembly_request_prepare_open (&req, asmctx, alc); - req.request.predicate = predicate; - req.request.predicate_ud = predicate_ud; - - len = strlen (aname->name); - for (ext_index = 0; ext_index < 2; ext_index ++) { - ext = ext_index == 0 ? ".dll" : ".exe"; - if (len > 4 && (!strcmp (aname->name + len - 4, ".dll") || !strcmp (aname->name + len - 4, ".exe"))) { - filename = g_strdup (aname->name); - /* Don't try appending .dll/.exe if it already has one of those extensions */ - ext_index++; - } else { - filename = g_strconcat (aname->name, ext, (const char*)NULL); - } - -#ifndef DISABLE_GAC - const gboolean refonly = asmctx == MONO_ASMCTX_REFONLY; - - result = mono_assembly_load_from_gac (aname, filename, status, refonly); - if (result) { - g_free (filename); - return result; - } -#endif - - if (basedir) { - fullpath = g_build_filename (basedir, filename, (const char*)NULL); - result = mono_assembly_request_open (fullpath, &req, status); - g_free (fullpath); - if (result) { - result->in_gac = FALSE; - g_free (filename); - return result; - } - } - - result = load_in_path (filename, (const char**) default_path, &req, status); - if (result) - result->in_gac = FALSE; - g_free (filename); - if (result) - return result; - } - - return result; -} - MonoAssembly* mono_assembly_request_byname (MonoAssemblyName *aname, const MonoAssemblyByNameRequest *req, MonoImageOpenStatus *status) { @@ -4749,7 +3447,6 @@ mono_assembly_load_module_checked (MonoAssembly *assembly, uint32_t idx, MonoErr return mono_image_load_file_for_image_checked (assembly->image, idx, error); } - /** * mono_assembly_foreach: * \param func function to invoke for each assembly loaded @@ -4788,18 +3485,7 @@ mono_assembly_foreach (GFunc func, gpointer user_data) void mono_assemblies_cleanup (void) { - GSList *l; - mono_os_mutex_destroy (&assemblies_mutex); - mono_os_mutex_destroy (&assembly_binding_mutex); - - for (l = loaded_assembly_bindings; l; l = l->next) { - MonoAssemblyBindingInfo *info = (MonoAssemblyBindingInfo *)l->data; - - mono_assembly_binding_info_free (info); - g_free (info); - } - g_slist_free (loaded_assembly_bindings); free_assembly_asmctx_from_path_hooks (); free_assembly_load_hooks (); @@ -4807,30 +3493,6 @@ mono_assemblies_cleanup (void) free_assembly_preload_hooks (); } -/*LOCKING takes the assembly_binding lock*/ -void -mono_assembly_cleanup_domain_bindings (guint32 domain_id) -{ - GSList **iter; - - mono_assembly_binding_lock (); - iter = &loaded_assembly_bindings; - while (*iter) { - GSList *l = *iter; - MonoAssemblyBindingInfo *info = (MonoAssemblyBindingInfo *)l->data; - - if (info->domain_id == domain_id) { - *iter = l->next; - mono_assembly_binding_info_free (info); - g_free (info); - g_slist_free_1 (l); - } else { - iter = &l->next; - } - } - mono_assembly_binding_unlock (); -} - /* * Holds the assembly of the application, for * System.Diagnostics.Process::MainModule diff --git a/src/mono/mono/metadata/domain-internals.h b/src/mono/mono/metadata/domain-internals.h index e7aaeed..3f1c3ff 100644 --- a/src/mono/mono/metadata/domain-internals.h +++ b/src/mono/mono/metadata/domain-internals.h @@ -373,10 +373,6 @@ struct _MonoDomain { /* Contains the compiled method used by async resylt creation to capture thread context*/ gpointer capture_context_method; - /* Assembly bindings, the per-domain part */ - GSList *assembly_bindings; - gboolean assembly_bindings_parsed; - /* Used by socket-io.c */ /* These are domain specific, since the assembly can be unloaded */ MonoImage *socket_assembly; @@ -553,9 +549,6 @@ mono_runtime_set_no_exec (gboolean val); gboolean mono_runtime_get_no_exec (void); -void -mono_domain_parse_assembly_bindings (MonoDomain *domain, int amajor, int aminor, gchar *domain_config_file_name); - gboolean mono_assembly_name_parse (const char *name, MonoAssemblyName *aname); @@ -576,8 +569,6 @@ mono_domain_assembly_postload_search (MonoAssemblyLoadContext *alc, MonoAssembly int mono_framework_version (void); -void mono_assembly_cleanup_domain_bindings (guint32 domain_id); - MonoJitInfo* mono_jit_info_table_find_internal (MonoDomain *domain, gpointer addr, gboolean try_aot, gboolean allow_trampolines); typedef void (*MonoJitInfoFunc) (MonoJitInfo *ji, gpointer user_data); diff --git a/src/mono/mono/metadata/domain.c b/src/mono/mono/metadata/domain.c index 9816784..3e1895d 100644 --- a/src/mono/mono/metadata/domain.c +++ b/src/mono/mono/metadata/domain.c @@ -432,8 +432,6 @@ mono_domain_create (void) domain->lock_free_mp = lock_free_mempool_new (); domain->env = mono_g_hash_table_new_type_internal ((GHashFunc)mono_string_hash_internal, (GCompareFunc)mono_string_equal_internal, MONO_HASH_KEY_VALUE_GC, MONO_ROOT_SOURCE_DOMAIN, domain, "Domain Environment Variable Table"); domain->domain_assemblies = NULL; - domain->assembly_bindings = NULL; - domain->assembly_bindings_parsed = FALSE; domain->proxy_vtable_hash = g_hash_table_new ((GHashFunc)mono_ptrarray_hash, (GCompareFunc)mono_ptrarray_equal); mono_jit_code_hash_init (&domain->jit_code_hash); domain->ldstr_table = mono_g_hash_table_new_type_internal ((GHashFunc)mono_string_hash_internal, (GCompareFunc)mono_string_equal_internal, MONO_HASH_KEY_VALUE_GC, MONO_ROOT_SOURCE_DOMAIN, domain, "Domain String Pool Table"); diff --git a/src/mono/mono/metadata/image-internals.h b/src/mono/mono/metadata/image-internals.h index 22965a7..7e6bf74 100644 --- a/src/mono/mono/metadata/image-internals.h +++ b/src/mono/mono/metadata/image-internals.h @@ -24,10 +24,4 @@ mono_image_load_module_checked (MonoImage *image, int idx, MonoError *error); MonoImage * mono_image_open_a_lot (MonoAssemblyLoadContext *alc, const char *fname, MonoImageOpenStatus *status, gboolean refonly, gboolean load_from_context); -gboolean -mono_is_problematic_image (MonoImage *image); - -gboolean -mono_is_problematic_file (const char *fname); - #endif /* __MONO_METADATA_IMAGE_INTERNALS_H__ */ diff --git a/src/mono/mono/metadata/image.c b/src/mono/mono/metadata/image.c index 2f57765..acc05d5 100644 --- a/src/mono/mono/metadata/image.c +++ b/src/mono/mono/metadata/image.c @@ -109,7 +109,7 @@ mono_images_unlock(void) } static MonoImage * -mono_image_open_a_lot_parameterized (MonoLoadedImages *li, MonoAssemblyLoadContext *alc, const char *fname, MonoImageOpenStatus *status, gboolean refonly, gboolean load_from_context, gboolean *problematic); +mono_image_open_a_lot_parameterized (MonoLoadedImages *li, MonoAssemblyLoadContext *alc, const char *fname, MonoImageOpenStatus *status, gboolean refonly, gboolean load_from_context); /* Maps string keys to MonoImageStorage values. * @@ -1160,178 +1160,6 @@ install_pe_loader (void) mono_install_image_loader (&pe_loader); } -#ifndef DISABLE_DESKTOP_LOADER - -/* -Ignored assemblies. - -There are some assemblies we need to ignore because they include an implementation that doesn't work under mono. -Mono provides its own implementation of those assemblies so it's safe to do so. - -The ignored_assemblies list is generated using tools/nuget-hash-extractor and feeding the problematic nugets to it. - -Right now the list of nugets are the ones that provide the assemblies in $ignored_assemblies_file_names. - -This is to be removed once a proper fix is shipped through nuget. - -Please keep this in sync with mcs/tools/xbuild/data/deniedAssembliesList.txt -If any assemblies are added/removed, then this should be regenerated with: - - $ mono tools/nuget-hash-extractor/nuget-hash-extractor.exe nugets guids_for_msbuild > mcs/tools/xbuild/data/deniedAssembliesList.txt - -*/ - -typedef enum { - SYS_RT_INTEROP_RUNTIME_INFO = 0, //System.Runtime.InteropServices.RuntimeInformation - SYS_GLOBALIZATION_EXT = 1, //System.Globalization.Extensions - SYS_IO_COMPRESSION = 2, //System.IO.Compression - SYS_NET_HTTP = 3, //System.Net.Http - SYS_TEXT_ENC_CODEPAGES = 4, //System.Text.Encoding.CodePages - SYS_THREADING_OVERLAPPED = 5, //System.Threading.Overlapped -} IgnoredAssemblyNames; - -typedef struct { - int hash; - int assembly_name; - char guid [40]; -} IgnoredAssembly; - -typedef struct { - int assembly_name; - guint16 major, minor, build, revision; -} IgnoredAssemblyVersion; - -static const char *ignored_assemblies_file_names[] = { - "System.Runtime.InteropServices.RuntimeInformation.dll", - "System.Globalization.Extensions.dll", - "System.IO.Compression.dll", - "System.Net.Http.dll", - "System.Text.Encoding.CodePages.dll", - "System.Threading.Overlapped.dll" -}; - -#define IGNORED_ASSEMBLY(HASH, NAME, GUID, VER_STR) { (int)HASH, NAME, GUID } - -static const IgnoredAssembly ignored_assemblies [] = { - IGNORED_ASSEMBLY (0x10CADA75, SYS_NET_HTTP, "EA2EC6DC-51DD-479C-BFC2-E713FB9E7E47", "4.1.1 net46"), - IGNORED_ASSEMBLY (0x1136045D, SYS_GLOBALIZATION_EXT, "475DBF02-9F68-44F1-8FB5-C9F69F1BD2B1", "4.0.0 net46"), - IGNORED_ASSEMBLY (0x1438EAE0, SYS_RT_INTEROP_RUNTIME_INFO, "F580BAAC-12BD-4716-B486-C0A5E3EE6EEA", "15.5.0-preview-20171027-2 net461"), - IGNORED_ASSEMBLY (0x16BCA997, SYS_RT_INTEROP_RUNTIME_INFO, "CA2D23DE-55E1-45D8-9720-0EBE3EEC1DF2", "2.0.0-preview3-20170622-1 net462"), - IGNORED_ASSEMBLY (0x17A113, SYS_RT_INTEROP_RUNTIME_INFO, "D87389D8-6E9C-48CF-B128-3637018577AF", "2.1.0-preview1-62414-02 net47"), - IGNORED_ASSEMBLY (0x1CBD59A2, SYS_IO_COMPRESSION, "44FCA06C-A510-4B3E-BDBF-D08D697EF65A", "4.1.0 net46"), - IGNORED_ASSEMBLY (0x1EA951BB, SYS_IO_COMPRESSION, "05C07BD4-AFF1-4B12-900B-F0A5EB88DDB4", "2.1.0-preview1-62414-02 net461"), - IGNORED_ASSEMBLY (0x1FB3F8E8, SYS_GLOBALIZATION_EXT, "B9BA8638-25D2-4A3B-B91F-16B3D3799861", "2.1.100-preview-62617-01 net461"), - IGNORED_ASSEMBLY (0x2706B80, SYS_NET_HTTP, "8E2F55F3-D010-417B-A742-21386EDDD388", "2.0.0-preview3-20170622-1 net461"), - IGNORED_ASSEMBLY (0x27726A90, SYS_NET_HTTP, "269B562C-CC15-4736-B1B1-68D4A43CAA98", "4.1.0 net46"), - IGNORED_ASSEMBLY (0x284ECF63, SYS_THREADING_OVERLAPPED, "E933407E-C846-4413-82C5-09F4BCFA67F1", "2.1.0-preview1-62414-02 net461"), - IGNORED_ASSEMBLY (0x358C9723, SYS_GLOBALIZATION_EXT, "5FCD54F0-4B97-4259-875D-30E481F02EA2", "4.0.1 net46"), - IGNORED_ASSEMBLY (0x39C3575D, SYS_GLOBALIZATION_EXT, "3B30D67C-B16B-47BC-B949-9500B5AAAAFB", "2.1.0-preview1-62414-02 net471"), - IGNORED_ASSEMBLY (0x3E21E75A, SYS_TEXT_ENC_CODEPAGES, "67D3A14A-8F55-4C9F-9699-EDD0876369DA", "4.5.0 net461"), - IGNORED_ASSEMBLY (0x420963C4, SYS_NET_HTTP, "084B071E-1637-4B3F-B7CD-6CEF28A6E4AE", "4.3.4 net46"), - IGNORED_ASSEMBLY (0x450A096A, SYS_GLOBALIZATION_EXT, "E9FCFF5B-4DE1-4BDC-9CE8-08C640FC78CC", "4.3.0 net46"), - IGNORED_ASSEMBLY (0x46A4A1C5, SYS_RT_INTEROP_RUNTIME_INFO, "F13660F8-9D0D-419F-BA4E-315693DD26EA", "4.0.0 net45"), - IGNORED_ASSEMBLY (0x472FA630, SYS_NET_HTTP, "09D4A140-061C-4884-9B63-22067E841931", "4.3.2 net46"), - IGNORED_ASSEMBLY (0x4CC79B26, SYS_GLOBALIZATION_EXT, "28006E9A-74DB-45AC-8A8D-030CEBAA272A", "2.0.0-preview3-20170622-1 net461"), - IGNORED_ASSEMBLY (0x4E906129, SYS_NET_HTTP, "27BBDD4C-EAF0-4A95-B172-EE502D76A725", "2.1.100-preview-62617-01 net461"), - IGNORED_ASSEMBLY (0x5E393C29, SYS_IO_COMPRESSION, "3A58A219-266B-47C3-8BE8-4E4F394147AB", "4.3.0 net46"), - IGNORED_ASSEMBLY (0x662BC58F, SYS_IO_COMPRESSION, "C786B28D-0850-4D4C-AED9-FE6B86EE7C31", "2.1.0-preview1-62414-02 net471"), - IGNORED_ASSEMBLY (0x66CEDA9, SYS_THREADING_OVERLAPPED, "A0439CB6-A5E6-4813-A76C-13F92ADDDED5", "2.1.100-preview-62617-01 net461"), - IGNORED_ASSEMBLY (0x6AE7C015, SYS_IO_COMPRESSION, "35DD20B5-8766-476B-B5D2-0EA16EF0A946", "2.1.100-preview-62617-01 net461"), - IGNORED_ASSEMBLY (0x6FE03EE2, SYS_THREADING_OVERLAPPED, "87697E71-D192-4F0B-BAD4-02BBC7793005", "4.3.0 net46"), - IGNORED_ASSEMBLY (0x74EA304F, SYS_RT_INTEROP_RUNTIME_INFO, "E5AE3324-2100-4F77-9E41-AEEF226C9649", "15.5.0-preview-20171027-2 net47"), - IGNORED_ASSEMBLY (0x765A8E04, SYS_RT_INTEROP_RUNTIME_INFO, "E46BA45E-6A63-47CD-AF70-2C3016AFF75A", "2.1.100-preview-62617-01 net461"), - IGNORED_ASSEMBLY (0x786145B9, SYS_RT_INTEROP_RUNTIME_INFO, "0C4BCFB3-F609-4631-93A6-17B19C69D9B6", "2.0.0-preview3-20170622-1 net47"), - IGNORED_ASSEMBLY (0x79F6E37F, SYS_THREADING_OVERLAPPED, "212BEDF2-E3F5-4D59-8C1A-F4D1C58B46CD", "15.5.0-preview-20171027-2 net461"), - IGNORED_ASSEMBLY (0x7D927C2A, SYS_THREADING_OVERLAPPED, "FCBD003B-2BB4-4940-BAEF-63AF520C2336", "4.0.1 net46"), - IGNORED_ASSEMBLY (0x8437178B, SYS_NET_HTTP, "C0E04D9C-70CF-48A6-A179-FBFD8CE69FD0", "4.3.0 net46"), - IGNORED_ASSEMBLY (0x8BFCB05D, SYS_THREADING_OVERLAPPED, "82D565AC-E41C-4E29-9939-C031C88EDBDD", "2.1.100-preview-62617-01 net471"), - IGNORED_ASSEMBLY (0x8CCF2469, SYS_RT_INTEROP_RUNTIME_INFO, "9A3724BF-DF8F-4955-8CFA-41D45F11B586", "2.1.0-preview1-62414-02 net462"), - IGNORED_ASSEMBLY (0x90772EB6, SYS_THREADING_OVERLAPPED, "F4FFC4A6-E694-49D9-81B2-12F2C9A29652", "2.0.0-preview3-20170622-1 net461"), - IGNORED_ASSEMBLY (0x911D9EC3, SYS_TEXT_ENC_CODEPAGES, "C142254F-DEB5-46A7-AE43-6F10320D1D1F", "4.0.1 net46"), - IGNORED_ASSEMBLY (0x96B5F0BA, SYS_NET_HTTP, "DB06A592-E332-44A1-8B85-20CAB3C3C147", "2.1.0-preview1-62414-02 net461"), - IGNORED_ASSEMBLY (0x9DBB28A2, SYS_NET_HTTP, "903A137B-BB3F-464A-94D4-780B89EE5580", "2.1.0-preview1-62414-02 net471"), - IGNORED_ASSEMBLY (0xA2E8EC53, SYS_RT_INTEROP_RUNTIME_INFO, "6D334D4D-0149-4D07-9DEF-CC52213145CE", "2.0.0-preview3-20170622-1 net461"), - IGNORED_ASSEMBLY (0xA3BFE786, SYS_RT_INTEROP_RUNTIME_INFO, "33D296D9-EE6D-404E-BF9F-432A429FF5DA", "15.5.0-preview-20171027-2 net462"), - IGNORED_ASSEMBLY (0xA99E866F, SYS_NET_HTTP, "41ACE450-8F44-455A-97AC-0679E5462071", "2.1.100-preview-62617-01 net471"), - IGNORED_ASSEMBLY (0xAA21986B, SYS_THREADING_OVERLAPPED, "9F5D4F09-787A-458A-BA08-553AA71470F1", "4.0.0 net46"), - IGNORED_ASSEMBLY (0xAF2093B8, SYS_TEXT_ENC_CODEPAGES, "D2B4F262-31A4-4E80-9CFB-26A2249A735E", "4.5.1 net461"), - IGNORED_ASSEMBLY (0xC69BED92, SYS_IO_COMPRESSION, "33AD8174-7781-46FA-A110-33821CCBE810", "15.5.0-preview-20171027-2 net461"), - IGNORED_ASSEMBLY (0xC8D00759, SYS_IO_COMPRESSION, "1332CE2F-1517-4BD7-93FD-7D4BCFBAED66", "2.0.0-preview3-20170622-1 net461"), - IGNORED_ASSEMBLY (0xCA951D5B, SYS_RT_INTEROP_RUNTIME_INFO, "1F37581E-4589-4C71-A465-05C6B9AE966E", "2.1.0-preview1-62414-02 net461"), - IGNORED_ASSEMBLY (0xD00F7419, SYS_THREADING_OVERLAPPED, "3336A2A3-1772-4EF9-A74B-AFDC80A8B21E", "2.1.0-preview1-62414-02 net471"), - IGNORED_ASSEMBLY (0xD07383BB, SYS_RT_INTEROP_RUNTIME_INFO, "DD91439F-3167-478E-BD2C-BF9C036A1395", "4.3.0 net45"), - IGNORED_ASSEMBLY (0xD08A991A, SYS_NET_HTTP, "82C79759-CB3C-4EB6-A17C-BDE85AF00A9B", "15.5.0-preview-20171027-2 net461"), - IGNORED_ASSEMBLY (0xD3ABE53A, SYS_RT_INTEROP_RUNTIME_INFO, "488CE209-4E5D-40E7-BE8C-F81F2B99F13A", "2.1.100-preview-62617-01 net462"), - IGNORED_ASSEMBLY (0xDB9397A9, SYS_NET_HTTP, "56203551-6937-47C1-9246-346A733913EE", "4.3.3 net46"), - IGNORED_ASSEMBLY (0xE16ECCCD, SYS_GLOBALIZATION_EXT, "1A2B9B2A-02F5-4C78-AB0C-7C6D2795CE2B", "2.1.100-preview-62617-01 net471"), - IGNORED_ASSEMBLY (0xE4016B17, SYS_GLOBALIZATION_EXT, "50F4163A-D692-452F-90ED-2F8024BB5319", "15.5.0-preview-20171027-2 net461"), - IGNORED_ASSEMBLY (0xE758DAD4, SYS_IO_COMPRESSION, "8DBD1669-97BC-4190-9BD8-738561193741", "2.1.100-preview-62617-01 net471"), - IGNORED_ASSEMBLY (0xF6D18A2E, SYS_TEXT_ENC_CODEPAGES, "F5CCCBEC-E1AD-4DBB-9B44-9B42C86B94B8", "4.4.0 net461"), - IGNORED_ASSEMBLY (0xF9D06E1E, SYS_GLOBALIZATION_EXT, "FC1439FC-C1B8-4DB1-914D-165CCFA77002", "2.1.0-preview1-62414-02 net461"), - IGNORED_ASSEMBLY (0xFA686A38, SYS_TEXT_ENC_CODEPAGES, "FD178CD4-EF4F-44D5-9C3F-812B1E25126B", "4.3.0 net46"), - IGNORED_ASSEMBLY (0xFAFDA422, SYS_NET_HTTP, "817F01C3-4011-477D-890A-98232B85553D", "4.3.1 net46"), - IGNORED_ASSEMBLY (0xFC67D3A7, SYS_RT_INTEROP_RUNTIME_INFO, "FD6C8616-C1D8-43F9-AC17-A1C48A45FDA2", "2.1.100-preview-62617-01 net47") -}; - - -static const char *ignored_assemblies_names[] = { - "System.Runtime.InteropServices.RuntimeInformation", - "System.Globalization.Extensions", - "System.IO.Compression", - "System.Net.Http", - "System.Text.Encoding.CodePages", - "System.Threading.Overlapped" -}; - -#define IGNORED_ASM_VER(NAME, MAJOR, MINOR, BUILD, REVISION) { NAME, MAJOR, MINOR, BUILD, REVISION } - -static const IgnoredAssemblyVersion ignored_assembly_versions [] = { - IGNORED_ASM_VER (SYS_GLOBALIZATION_EXT, 4, 0, 0, 0), - IGNORED_ASM_VER (SYS_GLOBALIZATION_EXT, 4, 0, 1, 0), - IGNORED_ASM_VER (SYS_GLOBALIZATION_EXT, 4, 0, 2, 0), - IGNORED_ASM_VER (SYS_GLOBALIZATION_EXT, 4, 1, 0, 0), - IGNORED_ASM_VER (SYS_IO_COMPRESSION, 4, 1, 0, 0), - IGNORED_ASM_VER (SYS_IO_COMPRESSION, 4, 1, 2, 0), - IGNORED_ASM_VER (SYS_IO_COMPRESSION, 4, 2, 0, 0), - IGNORED_ASM_VER (SYS_NET_HTTP, 4, 1, 0, 0), - IGNORED_ASM_VER (SYS_NET_HTTP, 4, 1, 0, 1), - IGNORED_ASM_VER (SYS_NET_HTTP, 4, 1, 1, 0), - IGNORED_ASM_VER (SYS_NET_HTTP, 4, 1, 1, 1), - IGNORED_ASM_VER (SYS_NET_HTTP, 4, 1, 1, 2), - IGNORED_ASM_VER (SYS_NET_HTTP, 4, 1, 1, 3), - IGNORED_ASM_VER (SYS_NET_HTTP, 4, 2, 0, 0), - IGNORED_ASM_VER (SYS_RT_INTEROP_RUNTIME_INFO, 4, 0, 0, 0), - IGNORED_ASM_VER (SYS_RT_INTEROP_RUNTIME_INFO, 4, 0, 1, 0), - IGNORED_ASM_VER (SYS_RT_INTEROP_RUNTIME_INFO, 4, 0, 2, 0), - IGNORED_ASM_VER (SYS_TEXT_ENC_CODEPAGES, 4, 0, 1, 0), - IGNORED_ASM_VER (SYS_TEXT_ENC_CODEPAGES, 4, 0, 2, 0), - IGNORED_ASM_VER (SYS_TEXT_ENC_CODEPAGES, 4, 1, 0, 0), - IGNORED_ASM_VER (SYS_TEXT_ENC_CODEPAGES, 4, 1, 1, 0), - IGNORED_ASM_VER (SYS_THREADING_OVERLAPPED, 4, 0, 0, 0), - IGNORED_ASM_VER (SYS_THREADING_OVERLAPPED, 4, 0, 1, 0), - IGNORED_ASM_VER (SYS_THREADING_OVERLAPPED, 4, 0, 2, 0), - IGNORED_ASM_VER (SYS_THREADING_OVERLAPPED, 4, 1, 0, 0) -}; - -#endif /* DISABLE_DESKTOP_LOADER */ - -gboolean -mono_assembly_is_problematic_version (const char *name, guint16 major, guint16 minor, guint16 build, guint16 revision) -{ -#ifndef DISABLE_DESKTOP_LOADER - for (int i = 0; i < G_N_ELEMENTS (ignored_assembly_versions); ++i) { - if (ignored_assembly_versions [i].major != major || - ignored_assembly_versions [i].minor != minor || - ignored_assembly_versions [i].build != build || - ignored_assembly_versions [i].revision != revision) - continue; - if (!strcmp (ignored_assemblies_names [ignored_assembly_versions [i].assembly_name], name)) - return TRUE; - } -#endif - return FALSE; -} - /* Equivalent C# code: static void Main () { @@ -1355,27 +1183,6 @@ hash_guid (const char *str) return h; } -gboolean -mono_is_problematic_image (MonoImage *image) -{ -#ifndef DISABLE_DESKTOP_LOADER - int h = hash_guid (image->guid); - - //TODO make this more cache effiecient. - // Either sort by hash and bseach or use SoA and make the linear search more cache efficient. - for (int i = 0; i < G_N_ELEMENTS (ignored_assemblies); ++i) { - if (ignored_assemblies [i].hash == h && !strcmp (image->guid, ignored_assemblies [i].guid)) { - const char *needle = ignored_assemblies_file_names [ignored_assemblies [i].assembly_name]; - size_t needle_len = strlen (needle); - size_t asm_len = strlen (image->name); - if (asm_len > needle_len && !g_ascii_strcasecmp (image->name + (asm_len - needle_len), needle)) - return TRUE; - } - } -#endif - return FALSE; -} - #ifdef ENABLE_METADATA_UPDATE static void dump_encmap (MonoImage *image) @@ -1446,17 +1253,6 @@ do_mono_image_load (MonoImage *image, MonoImageOpenStatus *status, if (!mono_image_load_cli_data (image)) goto invalid_image; - if (!image->ref_only && mono_is_problematic_image (image)) { - if (image->load_from_context) { - mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_ASSEMBLY, "Loading problematic image %s", image->name); - } else { - mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_ASSEMBLY, "Denying load of problematic image %s", image->name); - if (status) - *status = MONO_IMAGE_IMAGE_INVALID; - goto invalid_image; - } - } - if (image->loader == &pe_loader && !image->metadata_only && !mono_verifier_verify_table_data (image, error)) goto invalid_image; @@ -1848,7 +1644,7 @@ mono_image_get_name_with_culture_if_needed (MonoImage *image) } static MonoImage * -register_image (MonoLoadedImages *li, MonoImage *image, gboolean *problematic) +register_image (MonoLoadedImages *li, MonoImage *image) { MonoImage *image2; char *name = image->name; @@ -1877,11 +1673,6 @@ register_image (MonoLoadedImages *li, MonoImage *image, gboolean *problematic) g_hash_table_insert (loaded_images_by_name, (char *) image->assembly_name, image); mono_images_unlock (); - if (mono_is_problematic_image (image)) { - mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_ASSEMBLY, "Registering %s, problematic image '%s'", image->ref_only ? "REFONLY" : "default", name); - if (problematic) - *problematic = TRUE; - } g_free (name_with_culture); return image; } @@ -1926,7 +1717,7 @@ mono_image_open_from_data_internal (MonoAssemblyLoadContext *alc, char *data, gu if (image == NULL) return NULL; - return register_image (mono_alc_get_loaded_images (alc), image, NULL); + return register_image (mono_alc_get_loaded_images (alc), image); } MonoImage * @@ -2032,7 +1823,7 @@ mono_image_open_from_module_handle (MonoAssemblyLoadContext *alc, HMODULE module if (image == NULL) return NULL; - return register_image (mono_alc_get_loaded_images (alc), image, NULL); + return register_image (mono_alc_get_loaded_images (alc), image); } #endif @@ -2052,7 +1843,7 @@ mono_image_open_full (const char *fname, MonoImageOpenStatus *status, gboolean r * via this API, and then try to load it with another culture we will return the first one. */ static MonoImage * -mono_image_open_a_lot_parameterized (MonoLoadedImages *li, MonoAssemblyLoadContext *alc, const char *fname, MonoImageOpenStatus *status, gboolean refonly, gboolean load_from_context, gboolean *problematic) +mono_image_open_a_lot_parameterized (MonoLoadedImages *li, MonoAssemblyLoadContext *alc, const char *fname, MonoImageOpenStatus *status, gboolean refonly, gboolean load_from_context) { MonoImage *image; GHashTable *loaded_images = mono_loaded_images_get_hash (li, refonly); @@ -2075,22 +1866,6 @@ mono_image_open_a_lot_parameterized (MonoLoadedImages *li, MonoAssemblyLoadConte mono_images_lock (); image = (MonoImage*)g_hash_table_lookup (loaded_images, absfname); if (image) { // Image already loaded - if (!load_from_context && mono_is_problematic_image (image)) { - // If we previously loaded a problematic image, don't - // return it if we're not in LoadFrom context. - // - // Note: this has an interaction with - // mono_problematic_image_reprobe - at that point we - // have a problematic image opened, but we don't want - // to see it again when we go searching for an image - // to load. - mono_images_unlock (); - - if (problematic) - *problematic = TRUE; - - return NULL; - } g_assert (m_image_is_module_handle (image)); if (m_image_has_entry_point (image) && image->ref_count == 0) { /* Increment reference count on images loaded outside of the runtime. */ @@ -2162,21 +1937,6 @@ mono_image_open_a_lot_parameterized (MonoLoadedImages *li, MonoAssemblyLoadConte g_free (absfname); if (image) { // Image already loaded - if (!refonly && !load_from_context && mono_is_problematic_image (image)) { - // If we previously loaded a problematic image, don't - // return it if we're not in LoadFrom context. - // - // Note: this has an interaction with - // mono_problematic_image_reprobe - at that point we - // have a problematic image opened, but we don't want - // to see it again when we go searching for an image - // to load. - mono_images_unlock (); - mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_ASSEMBLY, "Not returning problematic image '%s' refcount=%d", image->name, image->ref_count); - if (problematic) - *problematic = TRUE; - return NULL; - } mono_image_addref (image); mono_images_unlock (); return image; @@ -2188,33 +1948,16 @@ mono_image_open_a_lot_parameterized (MonoLoadedImages *li, MonoAssemblyLoadConte if (image == NULL) return NULL; - return register_image (li, image, problematic); + return register_image (li, image); } MonoImage * mono_image_open_a_lot (MonoAssemblyLoadContext *alc, const char *fname, MonoImageOpenStatus *status, gboolean refonly, gboolean load_from_context) { MonoLoadedImages *li = mono_alc_get_loaded_images (alc); - return mono_image_open_a_lot_parameterized (li, alc, fname, status, refonly, load_from_context, NULL); + return mono_image_open_a_lot_parameterized (li, alc, fname, status, refonly, load_from_context); } -gboolean -mono_is_problematic_file (const char *fname) -{ - MonoImageOpenStatus status; - gboolean problematic = FALSE; - - MonoDomain *domain = mono_domain_get (); - MonoAssemblyLoadContext *alc = mono_domain_default_alc (domain); - MonoLoadedImages *li = mono_alc_get_loaded_images (alc); - MonoImage *opened = mono_image_open_a_lot_parameterized (li, alc, fname, &status, FALSE, FALSE, &problematic); - if (opened) - mono_image_close (opened); - - return problematic; -} - - /** * mono_image_open: * \param fname filename that points to the module we want to open diff --git a/src/mono/mono/metadata/metadata-internals.h b/src/mono/mono/metadata/metadata-internals.h index 32182c2..c17f4ee 100644 --- a/src/mono/mono/metadata/metadata-internals.h +++ b/src/mono/mono/metadata/metadata-internals.h @@ -1226,9 +1226,6 @@ mono_find_image_set_owner (void *ptr); void mono_loader_register_module (const char *name, MonoDl *module); -gboolean -mono_assembly_is_problematic_version (const char *name, guint16 major, guint16 minor, guint16 build, guint16 revision); - void mono_ginst_get_desc (GString *str, MonoGenericInst *ginst); diff --git a/src/mono/mono/mini/driver.c b/src/mono/mono/mini/driver.c index f22d3c6..ce6e7b5 100644 --- a/src/mono/mono/mini/driver.c +++ b/src/mono/mono/mini/driver.c @@ -1427,13 +1427,8 @@ static void main_thread_handler (gpointer user_data) for (i = 0; i < main_args->argc; ++i) { assembly = mono_domain_assembly_open_internal (main_args->domain, mono_domain_default_alc (main_args->domain), main_args->argv [i]); if (!assembly) { - if (mono_is_problematic_file (main_args->argv [i])) { - fprintf (stderr, "Info: AOT of problematic assembly %s skipped. This is expected.\n", main_args->argv [i]); - continue; - } else { - fprintf (stderr, "Can not open image %s\n", main_args->argv [i]); - exit (1); - } + fprintf (stderr, "Can not open image %s\n", main_args->argv [i]); + exit (1); } /* Check that the assembly loaded matches the filename */ { -- 2.7.4