From 3fa5f6c66e5d87e25425f2ced2c21d546aaf3cfe Mon Sep 17 00:00:00 2001 From: Ryan Lucia Date: Tue, 15 Oct 2019 19:40:24 -0400 Subject: [PATCH] [loader] Add an explicit define DISABLE_DLLMAP to control dllmap usage (#17315) * [loader] Add an explicit define ENABLE_DLLMAP to control dllmap usage * Update configure.ac * Update configure.ac * Add dllmap to enable-minimal * Change to DISABLE_DLLMAP * Grab some missing MonoDllMap uses --- configure.ac | 8 +++++++- mono/metadata/loader-internals.h | 4 ++++ mono/metadata/loader.c | 2 ++ mono/metadata/metadata-internals.h | 2 ++ mono/metadata/mono-config.c | 4 ++++ mono/metadata/native-library.c | 34 +++++++++++++++++++--------------- 6 files changed, 38 insertions(+), 16 deletions(-) diff --git a/configure.ac b/configure.ac index d10ca5b5af7..5612dad2e8d 100644 --- a/configure.ac +++ b/configure.ac @@ -1368,6 +1368,7 @@ elif test x$with_runtime_preset = xnetcore; then mono_feature_disable_gac='yes' mono_feature_disable_perfcounters='yes' mono_feature_disable_attach='yes' + mono_feature_disable_dllmap='yes' disable_mono_native=yes support_boehm=no elif test x$with_runtime_preset = xnet_4_x; then @@ -1741,7 +1742,7 @@ fi AM_CONDITIONAL(ENABLE_STATIC_GCC_LIBS, test "x$enable_static_gcc_libs" = "xyes") AC_ARG_ENABLE(minimal, [ --enable-minimal=LIST drop support for LIST subsystems. - LIST is a comma-separated list from: aot, profiler, decimal, pinvoke, debug, appdomains, verifier, + LIST is a comma-separated list from: aot, profiler, decimal, pinvoke, debug, appdomains, verifier, dllmap, reflection_emit, reflection_emit_save, large_code, logging, com, ssa, generics, attach, jit, interpreter, simd, soft_debug, perfcounters, normalization, desktop_loader, shared_perfcounters, remoting, security, lldb, mdb, assert_messages, cleanup, sgen_marksweep_conc, sgen_split_nursery, sgen_gc_bridge, sgen_debug_helpers, sockets, gac.], [ @@ -1955,6 +1956,11 @@ if test "x$mono_feature_disable_gac" = "xyes"; then AC_MSG_NOTICE([Disabled GAC support]) fi +if test "x$mono_feature_disable_dllmap" = "xyes"; then + AC_DEFINE(DISABLE_DLLMAP,1,[Disables use of DllMaps in MonoVM]) + AC_MSG_NOTICE([Disabled DllMap in the loader.]) +fi + AC_ARG_ENABLE(executables, [ --disable-executables disable the build of the runtime executables], enable_executables=$enableval, enable_executables=yes) AM_CONDITIONAL(DISABLE_EXECUTABLES, test x$enable_executables = xno) diff --git a/mono/metadata/loader-internals.h b/mono/metadata/loader-internals.h index 48370402d6d..c6ae0683bf3 100644 --- a/mono/metadata/loader-internals.h +++ b/mono/metadata/loader-internals.h @@ -16,6 +16,7 @@ typedef struct _MonoLoadedImages MonoLoadedImages; typedef struct _MonoAssemblyLoadContext MonoAssemblyLoadContext; +#ifndef DISABLE_DLLMAP typedef struct _MonoDllMap MonoDllMap; struct _MonoDllMap { char *dll; @@ -24,6 +25,7 @@ struct _MonoDllMap { char *target_func; MonoDllMap *next; }; +#endif #ifdef ENABLE_NETCORE /* FIXME: this probably belongs somewhere else */ @@ -48,11 +50,13 @@ mono_global_loader_data_unlock (void); gpointer mono_lookup_pinvoke_call_internal (MonoMethod *method, MonoError *error); +#ifndef DISABLE_DLLMAP void mono_dllmap_insert_internal (MonoImage *assembly, const char *dll, const char *func, const char *tdll, const char *tfunc); void mono_global_dllmap_cleanup (void); +#endif void mono_cached_module_cleanup (void); diff --git a/mono/metadata/loader.c b/mono/metadata/loader.c index 56f1a7c962d..499fa7eec4a 100644 --- a/mono/metadata/loader.c +++ b/mono/metadata/loader.c @@ -107,7 +107,9 @@ mono_loader_init () void mono_loader_cleanup (void) { +#ifndef DISABLE_DLLMAP mono_global_dllmap_cleanup (); +#endif mono_cached_module_cleanup (); mono_native_tls_free (loader_lock_nest_id); diff --git a/mono/metadata/metadata-internals.h b/mono/metadata/metadata-internals.h index eb2b4f80723..15f66bf33e7 100644 --- a/mono/metadata/metadata-internals.h +++ b/mono/metadata/metadata-internals.h @@ -533,8 +533,10 @@ struct _MonoImage { */ void *user_info; +#ifndef DISABLE_DLLMAP /* dll map entries */ MonoDllMap *dll_map; +#endif /* interfaces IDs from this image */ /* protected by the classes lock */ diff --git a/mono/metadata/mono-config.c b/mono/metadata/mono-config.c index 29590ade16b..30c289b2917 100644 --- a/mono/metadata/mono-config.c +++ b/mono/metadata/mono-config.c @@ -289,6 +289,7 @@ arch_matches (const char* arch, const char *value) return found; } +#ifndef DISABLE_DLLMAP typedef struct { char *dll; char *target; @@ -387,6 +388,7 @@ dllmap_handler = { NULL, /* end */ dllmap_finish }; +#endif static void legacyUEP_start (gpointer user_data, @@ -469,7 +471,9 @@ mono_config_init (void) { inited = 1; config_handlers = g_hash_table_new (g_str_hash, g_str_equal); +#ifndef DISABLE_DLLMAP g_hash_table_insert (config_handlers, (gpointer) dllmap_handler.element_name, (gpointer) &dllmap_handler); +#endif g_hash_table_insert (config_handlers, (gpointer) legacyUEP_handler.element_name, (gpointer) &legacyUEP_handler); g_hash_table_insert (config_handlers, (gpointer) aot_cache_handler.element_name, (gpointer) &aot_cache_handler); } diff --git a/mono/metadata/native-library.c b/mono/metadata/native-library.c index 40bce91d313..4f8924c5b1a 100644 --- a/mono/metadata/native-library.c +++ b/mono/metadata/native-library.c @@ -12,7 +12,9 @@ static int pinvoke_search_directories_count; static char **pinvoke_search_directories; #endif +#ifndef DISABLE_DLLMAP static MonoDllMap *global_dll_map; +#endif static GHashTable *global_module_map; static MonoDl *internal_module; @@ -40,7 +42,7 @@ typedef struct MonoLookupPInvokeStatus { GENERATE_GET_CLASS_WITH_CACHE (appdomain_unloaded_exception, "System", "AppDomainUnloadedException") GENERATE_TRY_GET_CLASS_WITH_CACHE (appdomain_unloaded_exception, "System", "AppDomainUnloadedException") -#ifndef ENABLE_NETCORE +#ifndef DISABLE_DLLMAP /* * LOCKING: Assumes the relevant lock is held. * For the global DllMap, this is `global_loader_data_mutex`, and for images it's their internal lock. @@ -116,7 +118,6 @@ mono_dllmap_lookup (MonoImage *assembly, const char *dll, const char* func, cons return res; } -#endif static void dllmap_insert_global (const char *dll, const char *func, const char *tdll, const char *tfunc) @@ -191,6 +192,19 @@ mono_dllmap_insert_internal (MonoImage *assembly, const char *dll, const char *f dllmap_insert_image (assembly, dll, func, tdll, tfunc); } +void +mono_global_dllmap_cleanup (void) +{ + // No need for a transition here since the thread is already detached from the runtime + mono_global_loader_data_lock (); + + free_dllmap (global_dll_map); + global_dll_map = NULL; + + mono_global_loader_data_unlock (); +} +#endif + /** * mono_dllmap_insert: * \param assembly if NULL, this is a global mapping, otherwise the remapping of the dynamic library will only apply to the specified assembly @@ -224,19 +238,9 @@ mono_dllmap_insert_internal (MonoImage *assembly, const char *dll, const char *f void mono_dllmap_insert (MonoImage *assembly, const char *dll, const char *func, const char *tdll, const char *tfunc) { +#ifndef DISABLE_DLLMAP mono_dllmap_insert_internal (assembly, dll, func, tdll, tfunc); -} - -void -mono_global_dllmap_cleanup (void) -{ - // No need for a transition here since the thread is already detached from the runtime - mono_global_loader_data_lock (); - - free_dllmap (global_dll_map); - global_dll_map = NULL; - - mono_global_loader_data_unlock (); +#endif } static MonoDl* @@ -456,7 +460,7 @@ lookup_pinvoke_call_impl (MonoMethod *method, MonoLookupPInvokeStatus *status_ou orig_scope = mono_metadata_string_heap (image, scope_token); } -#ifndef ENABLE_NETCORE +#ifndef DISABLE_DLLMAP // FIXME: The dllmap remaps System.Native to mono-native mono_dllmap_lookup (image, orig_scope, orig_import, &new_scope, &new_import); #else -- 2.11.4.GIT