From e750ecd1f252ee93959edbe1464feaf20d5ffa9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20K=C3=B6plinger?= Date: Mon, 14 Nov 2022 13:44:39 +0100 Subject: [PATCH] Revert "Allow interop resolvers to return self handle (#78018)" This reverts commit 6ab036f1ea75684ae8a600416efbb527bfd589a4. --- src/mono/mono/metadata/native-library.c | 63 ++++++++++--------------- 1 file changed, 25 insertions(+), 38 deletions(-) diff --git a/src/mono/mono/metadata/native-library.c b/src/mono/mono/metadata/native-library.c index 1d84b32a054896..b2d85270cd3fc0 100644 --- a/src/mono/mono/metadata/native-library.c +++ b/src/mono/mono/metadata/native-library.c @@ -584,41 +584,6 @@ netcore_probe_for_module_nofail (MonoImage *image, const char *file_name, int fl return result; } -static MonoDl* -netcore_lookup_self_native_handle (void) -{ - ERROR_DECL (load_error); - if (!internal_module) - internal_module = mono_dl_open_self (load_error); - - if (!internal_module) - mono_trace (G_LOG_LEVEL_INFO, MONO_TRACE_DLLIMPORT, "DllImport error loading library '__Internal': '%s'.", mono_error_get_message_without_fields (load_error)); - - mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_DLLIMPORT, "Native library found via __Internal."); - mono_error_cleanup (load_error); - - return internal_module; -} - -static MonoDl* native_handle_lookup_wrapper (gpointer handle) -{ - MonoDl *result = NULL; - - if (!internal_module) - netcore_lookup_self_native_handle (); - - if (internal_module->handle == handle) { - result = internal_module; - } - else { - native_library_lock (); - result = netcore_handle_lookup (handle); - native_library_unlock (); - } - - return result; -} - static MonoDl * netcore_resolve_with_dll_import_resolver (MonoAssemblyLoadContext *alc, MonoAssembly *assembly, const char *scope, guint32 flags, MonoError *error) { @@ -666,7 +631,9 @@ netcore_resolve_with_dll_import_resolver (MonoAssemblyLoadContext *alc, MonoAsse mono_runtime_invoke_checked (resolve, NULL, args, error); goto_if_nok (error, leave); - result = native_handle_lookup_wrapper (lib); + native_library_lock (); + result = netcore_handle_lookup (lib); + native_library_unlock (); leave: HANDLE_FUNCTION_RETURN_VAL (result); @@ -721,7 +688,9 @@ netcore_resolve_with_load (MonoAssemblyLoadContext *alc, const char *scope, Mono mono_runtime_invoke_checked (resolve, NULL, args, error); goto_if_nok (error, leave); - result = native_handle_lookup_wrapper (lib); + native_library_lock (); + result = netcore_handle_lookup (lib); + native_library_unlock (); leave: HANDLE_FUNCTION_RETURN_VAL (result); @@ -786,7 +755,9 @@ netcore_resolve_with_resolving_event (MonoAssemblyLoadContext *alc, MonoAssembly mono_runtime_invoke_checked (resolve, NULL, args, error); goto_if_nok (error, leave); - result = native_handle_lookup_wrapper (lib); + native_library_lock (); + result = netcore_handle_lookup (lib); + native_library_unlock (); leave: HANDLE_FUNCTION_RETURN_VAL (result); @@ -831,6 +802,22 @@ netcore_check_alc_cache (MonoAssemblyLoadContext *alc, const char *scope) return result; } +static MonoDl* +netcore_lookup_self_native_handle (void) +{ + ERROR_DECL (load_error); + if (!internal_module) + internal_module = mono_dl_open_self (load_error); + + if (!internal_module) + mono_trace (G_LOG_LEVEL_INFO, MONO_TRACE_DLLIMPORT, "DllImport error loading library '__Internal': '%s'.", mono_error_get_message_without_fields (load_error)); + + mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_DLLIMPORT, "Native library found via __Internal."); + mono_error_cleanup (load_error); + + return internal_module; +} + static MonoDl * netcore_lookup_native_library (MonoAssemblyLoadContext *alc, MonoImage *image, const char *scope, guint32 flags) {