@@ -584,6 +584,41 @@ netcore_probe_for_module_nofail (MonoImage *image, const char *file_name, int fl
584
584
return result ;
585
585
}
586
586
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
+
587
622
static MonoDl *
588
623
netcore_resolve_with_dll_import_resolver (MonoAssemblyLoadContext * alc , MonoAssembly * assembly , const char * scope , guint32 flags , MonoError * error )
589
624
{
@@ -631,9 +666,7 @@ netcore_resolve_with_dll_import_resolver (MonoAssemblyLoadContext *alc, MonoAsse
631
666
mono_runtime_invoke_checked (resolve , NULL , args , error );
632
667
goto_if_nok (error , leave );
633
668
634
- native_library_lock ();
635
- result = netcore_handle_lookup (lib );
636
- native_library_unlock ();
669
+ result = native_handle_lookup_wrapper (lib );
637
670
638
671
leave :
639
672
HANDLE_FUNCTION_RETURN_VAL (result );
@@ -688,9 +721,7 @@ netcore_resolve_with_load (MonoAssemblyLoadContext *alc, const char *scope, Mono
688
721
mono_runtime_invoke_checked (resolve , NULL , args , error );
689
722
goto_if_nok (error , leave );
690
723
691
- native_library_lock ();
692
- result = netcore_handle_lookup (lib );
693
- native_library_unlock ();
724
+ result = native_handle_lookup_wrapper (lib );
694
725
695
726
leave :
696
727
HANDLE_FUNCTION_RETURN_VAL (result );
@@ -755,9 +786,7 @@ netcore_resolve_with_resolving_event (MonoAssemblyLoadContext *alc, MonoAssembly
755
786
mono_runtime_invoke_checked (resolve , NULL , args , error );
756
787
goto_if_nok (error , leave );
757
788
758
- native_library_lock ();
759
- result = netcore_handle_lookup (lib );
760
- native_library_unlock ();
789
+ result = native_handle_lookup_wrapper (lib );
761
790
762
791
leave :
763
792
HANDLE_FUNCTION_RETURN_VAL (result );
@@ -802,22 +831,6 @@ netcore_check_alc_cache (MonoAssemblyLoadContext *alc, const char *scope)
802
831
return result ;
803
832
}
804
833
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
-
821
834
static MonoDl *
822
835
netcore_lookup_native_library (MonoAssemblyLoadContext * alc , MonoImage * image , const char * scope , guint32 flags )
823
836
{
0 commit comments