Skip to content

Commit 12c7abd

Browse files
authored
Revert "Allow interop resolvers to return self handle (#78018)" (#78313)
This reverts commit 6ab036f.
1 parent 86226c5 commit 12c7abd

File tree

1 file changed

+25
-38
lines changed

1 file changed

+25
-38
lines changed

Diff for: src/mono/mono/metadata/native-library.c

+25-38
Original file line numberDiff line numberDiff line change
@@ -584,41 +584,6 @@ netcore_probe_for_module_nofail (MonoImage *image, const char *file_name, int fl
584584
return result;
585585
}
586586

587-
static MonoDl*
588-
netcore_lookup_self_native_handle (void)
589-
{
590-
ERROR_DECL (load_error);
591-
if (!internal_module)
592-
internal_module = mono_dl_open_self (load_error);
593-
594-
if (!internal_module)
595-
mono_trace (G_LOG_LEVEL_INFO, MONO_TRACE_DLLIMPORT, "DllImport error loading library '__Internal': '%s'.", mono_error_get_message_without_fields (load_error));
596-
597-
mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_DLLIMPORT, "Native library found via __Internal.");
598-
mono_error_cleanup (load_error);
599-
600-
return internal_module;
601-
}
602-
603-
static MonoDl* native_handle_lookup_wrapper (gpointer handle)
604-
{
605-
MonoDl *result = NULL;
606-
607-
if (!internal_module)
608-
netcore_lookup_self_native_handle ();
609-
610-
if (internal_module->handle == handle) {
611-
result = internal_module;
612-
}
613-
else {
614-
native_library_lock ();
615-
result = netcore_handle_lookup (handle);
616-
native_library_unlock ();
617-
}
618-
619-
return result;
620-
}
621-
622587
static MonoDl *
623588
netcore_resolve_with_dll_import_resolver (MonoAssemblyLoadContext *alc, MonoAssembly *assembly, const char *scope, guint32 flags, MonoError *error)
624589
{
@@ -666,7 +631,9 @@ netcore_resolve_with_dll_import_resolver (MonoAssemblyLoadContext *alc, MonoAsse
666631
mono_runtime_invoke_checked (resolve, NULL, args, error);
667632
goto_if_nok (error, leave);
668633

669-
result = native_handle_lookup_wrapper (lib);
634+
native_library_lock ();
635+
result = netcore_handle_lookup (lib);
636+
native_library_unlock ();
670637

671638
leave:
672639
HANDLE_FUNCTION_RETURN_VAL (result);
@@ -721,7 +688,9 @@ netcore_resolve_with_load (MonoAssemblyLoadContext *alc, const char *scope, Mono
721688
mono_runtime_invoke_checked (resolve, NULL, args, error);
722689
goto_if_nok (error, leave);
723690

724-
result = native_handle_lookup_wrapper (lib);
691+
native_library_lock ();
692+
result = netcore_handle_lookup (lib);
693+
native_library_unlock ();
725694

726695
leave:
727696
HANDLE_FUNCTION_RETURN_VAL (result);
@@ -786,7 +755,9 @@ netcore_resolve_with_resolving_event (MonoAssemblyLoadContext *alc, MonoAssembly
786755
mono_runtime_invoke_checked (resolve, NULL, args, error);
787756
goto_if_nok (error, leave);
788757

789-
result = native_handle_lookup_wrapper (lib);
758+
native_library_lock ();
759+
result = netcore_handle_lookup (lib);
760+
native_library_unlock ();
790761

791762
leave:
792763
HANDLE_FUNCTION_RETURN_VAL (result);
@@ -831,6 +802,22 @@ netcore_check_alc_cache (MonoAssemblyLoadContext *alc, const char *scope)
831802
return result;
832803
}
833804

805+
static MonoDl*
806+
netcore_lookup_self_native_handle (void)
807+
{
808+
ERROR_DECL (load_error);
809+
if (!internal_module)
810+
internal_module = mono_dl_open_self (load_error);
811+
812+
if (!internal_module)
813+
mono_trace (G_LOG_LEVEL_INFO, MONO_TRACE_DLLIMPORT, "DllImport error loading library '__Internal': '%s'.", mono_error_get_message_without_fields (load_error));
814+
815+
mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_DLLIMPORT, "Native library found via __Internal.");
816+
mono_error_cleanup (load_error);
817+
818+
return internal_module;
819+
}
820+
834821
static MonoDl *
835822
netcore_lookup_native_library (MonoAssemblyLoadContext *alc, MonoImage *image, const char *scope, guint32 flags)
836823
{

0 commit comments

Comments
 (0)