@@ -130,21 +130,45 @@ EmbeddedAssemblies::get_assembly_data (const MonoBundledAssembly *e, char*& asse
130
130
}
131
131
}
132
132
133
+ #if defined (NET6)
133
134
MonoAssembly*
134
- #if defined (NET6) && defined (NET6_ALC_WORKS)
135
- EmbeddedAssemblies::open_from_bundles (MonoAssemblyName* aname, MonoAssemblyLoadContextGCHandle alc_gchandle, MonoError *error)
136
- #else // !(def NET6 && def NET6_ALC_WORKS)
137
- EmbeddedAssemblies::open_from_bundles (MonoAssemblyName* aname, bool ref_only)
138
- #endif // def NET6 && def NET6_ALC_WORKS
135
+ EmbeddedAssemblies::open_from_bundles (MonoAssemblyName* aname, MonoAssemblyLoadContextGCHandle alc_gchandle, [[maybe_unused]] MonoError *error)
139
136
{
140
- #if defined (NET6)
141
- // NET6 doesn't support reference-only loads, define the variable here to minimize ifdefs in the code below
142
- #if defined (NET6_ALC_WORKS)
143
- constexpr bool ref_only = false ;
144
- #else // def NET6_ALC_WORKS
145
- ref_only = false ;
146
- #endif // ndef NET6_ALC_WORKS
137
+ auto loader = [&] (char *assembly_data, uint32_t assembly_data_size, const char *name) -> MonoImage* {
138
+ return mono_image_open_from_data_alc (
139
+ alc_gchandle,
140
+ assembly_data,
141
+ assembly_data_size,
142
+ 0 /* need_copy */ ,
143
+ nullptr /* status */ ,
144
+ name
145
+ );
146
+ };
147
+
148
+ return open_from_bundles (aname, loader, false /* ref_only */ );
149
+ }
147
150
#endif // def NET6
151
+
152
+ MonoAssembly*
153
+ EmbeddedAssemblies::open_from_bundles (MonoAssemblyName* aname, bool ref_only)
154
+ {
155
+ auto loader = [&] (char *assembly_data, uint32_t assembly_data_size, const char *name) -> MonoImage* {
156
+ return mono_image_open_from_data_with_name (
157
+ assembly_data,
158
+ assembly_data_size,
159
+ 0 ,
160
+ nullptr ,
161
+ ref_only,
162
+ name
163
+ );
164
+ };
165
+
166
+ return open_from_bundles (aname, loader, ref_only);
167
+ }
168
+
169
+ MonoAssembly*
170
+ EmbeddedAssemblies::open_from_bundles (MonoAssemblyName* aname, std::function<MonoImage*(char *, uint32_t , const char *)> loader, bool ref_only)
171
+ {
148
172
const char *culture = mono_assembly_name_get_culture (aname);
149
173
const char *asmname = mono_assembly_name_get_name (aname);
150
174
@@ -185,19 +209,7 @@ EmbeddedAssemblies::open_from_bundles (MonoAssemblyName* aname, bool ref_only)
185
209
}
186
210
187
211
get_assembly_data (e, assembly_data, assembly_data_size);
188
-
189
- #if defined (NET6) && defined (NET6_ALC_WORKS)
190
- image = mono_image_open_from_data_alc (
191
- alc_gchandle,
192
- assembly_data,
193
- assembly_data_size,
194
- 0 /* need_copy */ ,
195
- nullptr /* status */ ,
196
- name.get ()
197
- );
198
- #else // (def NET6 && def NET6_ALC_WORKS)
199
- image = mono_image_open_from_data_with_name (assembly_data, assembly_data_size, 0 , nullptr , ref_only, name.get ());
200
- #endif // !(def NET6 && def NET6_ALC_WORKS)
212
+ image = loader (assembly_data, assembly_data_size, name.get ());
201
213
if (image == nullptr ) {
202
214
continue ;
203
215
}
@@ -215,51 +227,49 @@ EmbeddedAssemblies::open_from_bundles (MonoAssemblyName* aname, bool ref_only)
215
227
log_info_nocheck (LOG_ASSEMBLY, " open_from_bundles: loaded assembly: %p\n " , a);
216
228
}
217
229
218
- #if defined (NET6) && defined (NET6_ALC_WORKS)
219
- if (error != nullptr ) {
220
- error->error_code = a == nullptr ? MONO_ERROR_NONE : MONO_ERROR_FILE_NOT_FOUND;
221
- }
222
- #endif // def NET6 && def NET6_ALC_WORKS
223
230
return a;
224
231
}
225
232
226
- #if defined (NET6) && defined (NET6_ALC_WORKS)
233
+ #if defined (NET6)
227
234
MonoAssembly*
228
235
EmbeddedAssemblies::open_from_bundles (MonoAssemblyLoadContextGCHandle alc_gchandle, MonoAssemblyName *aname, [[maybe_unused]] char **assemblies_path, [[maybe_unused]] void *user_data, MonoError *error)
229
236
{
230
- log_warn (LOG_DEFAULT, __PRETTY_FUNCTION__);
231
237
return embeddedAssemblies.open_from_bundles (aname, alc_gchandle, error);
232
238
}
233
- #else // def NET6 && def NET6_ALC_WORKS
239
+ #else // def NET6
240
+ MonoAssembly*
241
+ EmbeddedAssemblies::open_from_bundles_refonly (MonoAssemblyName *aname, [[maybe_unused]] char **assemblies_path, [[maybe_unused]] void *user_data)
242
+ {
243
+ return embeddedAssemblies.open_from_bundles (aname, true );
244
+ }
245
+ #endif // ndef NET6
246
+
234
247
MonoAssembly*
235
248
EmbeddedAssemblies::open_from_bundles_full (MonoAssemblyName *aname, [[maybe_unused]] char **assemblies_path, [[maybe_unused]] void *user_data)
236
249
{
237
250
return embeddedAssemblies.open_from_bundles (aname, false );
238
251
}
239
252
240
- MonoAssembly*
241
- EmbeddedAssemblies::open_from_bundles_refonly (MonoAssemblyName *aname, [[maybe_unused]] char **assemblies_path, [[maybe_unused]] void *user_data )
253
+ void
254
+ EmbeddedAssemblies::install_preload_hooks_for_appdomains ( )
242
255
{
243
- return embeddedAssemblies.open_from_bundles (aname, true );
256
+ mono_install_assembly_preload_hook (open_from_bundles_full, nullptr );
257
+ #if !defined (NET6)
258
+ mono_install_assembly_refonly_preload_hook (open_from_bundles_refonly, nullptr );
259
+ #endif // ndef NET6
244
260
}
245
- #endif // !(def NET6 && def NET6_ALC_WORKS)
246
261
262
+ #if defined (NET6)
247
263
void
248
- EmbeddedAssemblies::install_preload_hooks ()
264
+ EmbeddedAssemblies::install_preload_hooks_for_alc ()
249
265
{
250
- #if defined (NET6) && defined (NET6_ALC_WORKS)
251
266
mono_install_assembly_preload_hook_v3 (
252
267
open_from_bundles,
253
268
nullptr /* user_data */ ,
254
269
0 /* append */
255
270
);
256
- #else // def NET6 && def NET6_ALC_WORKS
257
- mono_install_assembly_preload_hook (open_from_bundles_full, nullptr );
258
- #if !defined (NET6) // Reference-only loads don't exist in NET6
259
- mono_install_assembly_refonly_preload_hook (open_from_bundles_refonly, nullptr );
260
- #endif // !def NET6
261
- #endif // !(def NET6 && def NET6_ALC_WORKS)
262
271
}
272
+ #endif // def NET6
263
273
264
274
template <typename Key, typename Entry, int (*compare)(const Key*, const Entry*), bool use_extra_size>
265
275
const Entry*
0 commit comments