3 #include "mono/metadata/loaded-images-internals.h"
4 #include "mono/metadata/metadata-internals.h"
7 /* Global image hashes should not be in netcore Mono */
9 static MonoLoadedImages global_loaded_images
; /* zero initalized is good enough */
12 mono_get_global_loaded_images (void)
14 return &global_loaded_images
;
17 // This is support for the mempool reference tracking feature in checked-build,
18 // but lives in loaded-images-global.c due to use of static variables of this
22 * mono_find_image_owner:
24 * Find the image, if any, which a given pointer is located in the memory of.
27 mono_find_image_owner (void *ptr
)
29 MonoLoadedImages
*li
= mono_get_global_loaded_images ();
32 MonoImage
*owner
= NULL
;
34 // Iterate over both by-path image hashes
35 const int hash_candidates
[] = {MONO_LOADED_IMAGES_HASH_PATH
, MONO_LOADED_IMAGES_HASH_PATH_REFONLY
};
37 for (hash_idx
= 0; !owner
&& hash_idx
< G_N_ELEMENTS (hash_candidates
); hash_idx
++)
39 GHashTable
*target
= li
->loaded_images_hashes
[hash_candidates
[hash_idx
]];
43 // Iterate over images within a hash
44 g_hash_table_iter_init (&iter
, target
);
45 while (!owner
&& g_hash_table_iter_next(&iter
, NULL
, (gpointer
*)&image
))
47 mono_image_lock (image
);
48 if (mono_mempool_contains_addr (image
->mempool
, ptr
))
50 mono_image_unlock (image
);
54 mono_images_unlock ();
60 mono_alc_get_loaded_images (MonoAssemblyLoadContext
*alc
)
62 return mono_get_global_loaded_images ();
65 #endif /* ENABLE_NETCORE */