@@ -75,7 +75,10 @@ static gint32 signatures_size;
75
75
MonoNativeTlsKey loader_lock_nest_id ;
76
76
77
77
static void dllmap_cleanup (void );
78
- static void cached_module_cleanup (void );
78
+ static void embedded_module_cleanup (void );
79
+
80
+ void mono_image_lock (MonoImage * image );
81
+ void mono_image_unlock (MonoImage * image );
79
82
80
83
/* Class lazy loading functions */
81
84
GENERATE_GET_CLASS_WITH_CACHE (appdomain_unloaded_exception , "System" , "AppDomainUnloadedException" )
122
125
mono_loader_cleanup (void )
123
126
{
124
127
dllmap_cleanup ();
125
- cached_module_cleanup ();
128
+ embedded_module_cleanup ();
126
129
127
130
mono_native_tls_free (loader_lock_nest_id );
128
131
@@ -1109,10 +1112,10 @@ dllmap_cleanup (void)
1109
1112
global_dll_map = NULL ;
1110
1113
}
1111
1114
1112
- static GHashTable * global_module_map ;
1115
+ static GHashTable * embedded_module_map ;
1113
1116
1114
1117
static MonoDl *
1115
- cached_module_load (const char * name , int flags , char * * err )
1118
+ cached_module_load (MonoImage * image , const char * name , int flags , char * * err )
1116
1119
{
1117
1120
MonoDl * res ;
1118
1121
const char * name_remap ;
@@ -1121,46 +1124,63 @@ cached_module_load (const char *name, int flags, char **err)
1121
1124
* err = NULL ;
1122
1125
if (name_remap = mono_unity_remap_path (name ))
1123
1126
name = name_remap ;
1127
+
1124
1128
global_loader_data_lock ();
1125
- if (!global_module_map )
1126
- global_module_map = g_hash_table_new (g_str_hash , g_str_equal );
1127
- res = (MonoDl * )g_hash_table_lookup (global_module_map , name );
1129
+ if (embedded_module_map )
1130
+ {
1131
+ res = (MonoDl * )g_hash_table_lookup (embedded_module_map , name );
1132
+ if (res ) {
1133
+ global_loader_data_unlock ();
1134
+ return res ;
1135
+ }
1136
+ }
1137
+ global_loader_data_unlock ();
1138
+
1139
+ mono_image_lock (image );
1140
+ if (!image -> module_map )
1141
+ image -> module_map = g_hash_table_new (g_str_hash , g_str_equal );
1142
+ res = (MonoDl * )g_hash_table_lookup (image -> module_map , name );
1128
1143
if (res ) {
1129
- global_loader_data_unlock ( );
1144
+ mono_image_unlock ( image );
1130
1145
g_free ((void * )name_remap );
1131
1146
return res ;
1132
1147
}
1133
1148
res = mono_dl_open (name , flags , err );
1134
1149
if (res )
1135
- g_hash_table_insert (global_module_map , g_strdup (name ), res );
1136
- global_loader_data_unlock ();
1150
+ g_hash_table_insert (image -> module_map , g_strdup (name ), res );
1151
+ mono_image_unlock (image );
1152
+
1137
1153
g_free ((void * )name_remap );
1138
1154
return res ;
1139
1155
}
1140
1156
1141
1157
void
1142
- mono_loader_register_module (const char * name , MonoDl * module )
1158
+ mono_loader_register_embedded_module (const char * name , MonoDl * module )
1143
1159
{
1144
- if (!global_module_map )
1145
- global_module_map = g_hash_table_new (g_str_hash , g_str_equal );
1146
- g_hash_table_insert (global_module_map , g_strdup (name ), module );
1160
+ global_loader_data_lock ();
1161
+ if (!embedded_module_map )
1162
+ embedded_module_map = g_hash_table_new (g_str_hash , g_str_equal );
1163
+ g_hash_table_insert (embedded_module_map , g_strdup (name ), module );
1164
+ global_loader_data_unlock ();
1147
1165
}
1148
1166
1149
1167
static void
1150
- remove_cached_module (gpointer key , gpointer value , gpointer user_data )
1168
+ remove_embedded_module (gpointer key , gpointer value , gpointer user_data )
1151
1169
{
1152
1170
mono_dl_close ((MonoDl * )value );
1153
1171
}
1154
1172
1155
1173
static void
1156
- cached_module_cleanup (void )
1174
+ embedded_module_cleanup (void )
1157
1175
{
1158
- if (global_module_map != NULL ) {
1159
- g_hash_table_foreach (global_module_map , remove_cached_module , NULL );
1176
+ global_loader_data_lock ();
1177
+ if (embedded_module_map != NULL ) {
1178
+ g_hash_table_foreach (embedded_module_map , remove_embedded_module , NULL );
1160
1179
1161
- g_hash_table_destroy (global_module_map );
1162
- global_module_map = NULL ;
1180
+ g_hash_table_destroy (embedded_module_map );
1181
+ embedded_module_map = NULL ;
1163
1182
}
1183
+ global_loader_data_unlock ();
1164
1184
}
1165
1185
1166
1186
static MonoDl * internal_module ;
@@ -1347,7 +1367,7 @@ mono_lookup_pinvoke_call (MonoMethod *method, const char **exc_class, const char
1347
1367
}
1348
1368
1349
1369
if (!module && is_absolute ) {
1350
- module = cached_module_load (file_name , MONO_DL_LAZY , & error_msg );
1370
+ module = cached_module_load (image , file_name , MONO_DL_LAZY , & error_msg );
1351
1371
if (!module ) {
1352
1372
mono_trace (G_LOG_LEVEL_INFO , MONO_TRACE_DLLIMPORT ,
1353
1373
"DllImport error loading library '%s': '%s'." ,
@@ -1419,7 +1439,7 @@ mono_lookup_pinvoke_call (MonoMethod *method, const char **exc_class, const char
1419
1439
continue ;
1420
1440
1421
1441
while ((full_name = mono_dl_build_path (mdirname , file_name , & iter ))) {
1422
- module = cached_module_load (full_name , MONO_DL_LAZY , & error_msg );
1442
+ module = cached_module_load (image , full_name , MONO_DL_LAZY , & error_msg );
1423
1443
if (!module ) {
1424
1444
mono_trace (G_LOG_LEVEL_INFO , MONO_TRACE_DLLIMPORT ,
1425
1445
"DllImport error loading library '%s': '%s'." ,
@@ -1444,7 +1464,7 @@ mono_lookup_pinvoke_call (MonoMethod *method, const char **exc_class, const char
1444
1464
void * iter = NULL ;
1445
1465
char * file_or_base = is_absolute ? base_name : file_name ;
1446
1466
while ((full_name = mono_dl_build_path (dir_name , file_or_base , & iter ))) {
1447
- module = cached_module_load (full_name , MONO_DL_LAZY , & error_msg );
1467
+ module = cached_module_load (image , full_name , MONO_DL_LAZY , & error_msg );
1448
1468
if (!module ) {
1449
1469
mono_trace (G_LOG_LEVEL_INFO , MONO_TRACE_DLLIMPORT ,
1450
1470
"DllImport error loading library '%s': '%s'." ,
@@ -1460,7 +1480,7 @@ mono_lookup_pinvoke_call (MonoMethod *method, const char **exc_class, const char
1460
1480
}
1461
1481
1462
1482
if (!module ) {
1463
- module = cached_module_load (file_name , MONO_DL_LAZY , & error_msg );
1483
+ module = cached_module_load (image , file_name , MONO_DL_LAZY , & error_msg );
1464
1484
if (!module ) {
1465
1485
mono_trace (G_LOG_LEVEL_INFO , MONO_TRACE_DLLIMPORT ,
1466
1486
"DllImport error loading library '%s': '%s'." ,
0 commit comments