typedef struct ImageUnloadHook ImageUnloadHook;
struct ImageUnloadHook {
- ImageUnloadHook *next;
MonoImageUnloadFunc func;
gpointer user_data;
};
-ImageUnloadHook *image_unload_hook = NULL;
+GSList *image_unload_hooks;
void
mono_install_image_unload_hook (MonoImageUnloadFunc func, gpointer user_data)
hook = g_new0 (ImageUnloadHook, 1);
hook->func = func;
hook->user_data = user_data;
- hook->next = image_unload_hook;
- image_unload_hook = hook;
+ image_unload_hooks = g_slist_prepend (image_unload_hooks, hook);
+}
+
+void
+mono_remove_image_unload_hook (MonoImageUnloadFunc func, gpointer user_data)
+{
+ GSList *l;
+ ImageUnloadHook *hook;
+
+ for (l = image_unload_hooks; l; l = l->next) {
+ hook = l->data;
+
+ if (hook->func == func && hook->user_data == user_data) {
+ g_free (hook);
+ image_unload_hooks = g_slist_delete_link (image_unload_hooks, l);
+ break;
+ }
+ }
}
static void
mono_image_invoke_unload_hook (MonoImage *image)
{
+ GSList *l;
ImageUnloadHook *hook;
- for (hook = image_unload_hook; hook; hook = hook->next) {
+ for (l = image_unload_hooks; l; l = l->next) {
+ hook = l->data;
+
hook->func (image, hook->user_data);
}
}
void
mono_images_cleanup (void)
{
+ GHashTableIter iter;
+ MonoImage *image;
+
DeleteCriticalSection (&images_mutex);
+ g_hash_table_iter_init (&iter, loaded_images_hash);
+ while (g_hash_table_iter_next (&iter, NULL, (void**)&image))
+ mono_trace (G_LOG_LEVEL_INFO, MONO_TRACE_ASSEMBLY, "Assembly image '%s' still loaded at shutdown.", image->name);
+
g_hash_table_destroy (loaded_images_hash);
g_hash_table_destroy (loaded_images_refonly_hash);
image->raw_buffer_used = TRUE;
image->raw_data_len = mono_file_map_size (filed);
image->raw_data = mono_file_map (image->raw_data_len, MONO_MMAP_READ|MONO_MMAP_PRIVATE, mono_file_map_fd (filed), 0, &image->raw_data_handle);
+#if defined(HAVE_MMAP) && !defined (HOST_WIN32)
+ if (!image->raw_data) {
+ image->fileio_used = TRUE;
+ image->raw_data = mono_file_map_fileio (image->raw_data_len, MONO_MMAP_READ|MONO_MMAP_PRIVATE, mono_file_map_fd (filed), 0, &image->raw_data_handle);
+ }
+#endif
if (!image->raw_data) {
mono_file_map_close (filed);
g_free (image);
if (status) {
if (last_error == ERROR_BAD_EXE_FORMAT || last_error == STATUS_INVALID_IMAGE_FORMAT)
*status = MONO_IMAGE_IMAGE_INVALID;
- else
- *status = MONO_IMAGE_ERROR_ERRNO;
+ else {
+ if (last_error == ERROR_FILE_NOT_FOUND || last_error == ERROR_PATH_NOT_FOUND)
+ errno = ENOENT;
+ else
+ errno = 0;
+ }
}
return NULL;
}
}
*/
-static void
-free_remoting_wrappers (gpointer key, gpointer val, gpointer user_data)
-{
- g_free (val);
-}
-
static void
free_array_cache_entry (gpointer key, gpointer val, gpointer user_data)
{
int i;
for (i = 0; i < t->rows; i++) {
- if (image->references [i]) {
+ if (image->references [i] && image->references [i] != REFERENCE_MISSING) {
if (!mono_assembly_close_except_image_pools (image->references [i]))
image->references [i] = NULL;
}
#endif
if (image->raw_buffer_used) {
- if (image->raw_data != NULL)
- mono_file_unmap (image->raw_data, image->raw_data_handle);
+ if (image->raw_data != NULL) {
+#ifndef HOST_WIN32
+ if (image->fileio_used)
+ mono_file_unmap_fileio (image->raw_data, image->raw_data_handle);
+ else
+#endif
+ mono_file_unmap (image->raw_data, image->raw_data_handle);
+ }
}
if (image->raw_data_allocated) {
free_hash (image->delegate_end_invoke_cache);
free_hash (image->delegate_invoke_cache);
free_hash (image->delegate_abstract_invoke_cache);
- if (image->remoting_invoke_cache)
- g_hash_table_foreach (image->remoting_invoke_cache, free_remoting_wrappers, NULL);
+ free_hash (image->delegate_bound_static_invoke_cache);
free_hash (image->remoting_invoke_cache);
free_hash (image->runtime_invoke_cache);
free_hash (image->runtime_invoke_direct_cache);
free_hash (image->castclass_cache);
free_hash (image->proxy_isinst_cache);
free_hash (image->thunk_invoke_cache);
+ free_hash (image->var_cache_slow);
+ free_hash (image->mvar_cache_slow);
+ free_hash (image->wrapper_param_names);
+ free_hash (image->native_wrapper_aot_cache);
+ free_hash (image->pinvoke_scopes);
+ free_hash (image->pinvoke_scope_filenames);
/* The ownership of signatures is not well defined */
//g_hash_table_foreach (image->memberref_signatures, free_mr_signatures, NULL);
int i;
for (i = 0; i < t->rows; i++) {
- if (image->references [i])
+ if (image->references [i] && image->references [i] != REFERENCE_MISSING)
mono_assembly_close_finish (image->references [i]);
}