Implemeneted imprecise.
[mono-project.git] / mono / metadata / loaded-images-global.c
blob645b0cd271c4bd42f3faefc344503968ca8d0b53
1 #include <config.h>
3 #include "mono/metadata/loaded-images-internals.h"
4 #include "mono/metadata/metadata-internals.h"
6 #ifndef ENABLE_NETCORE
7 /* Global image hashes should not be in netcore Mono */
9 static MonoLoadedImages global_loaded_images; /* zero initalized is good enough */
11 MonoLoadedImages*
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
19 // file.
21 /**
22 * mono_find_image_owner:
24 * Find the image, if any, which a given pointer is located in the memory of.
26 MonoImage *
27 mono_find_image_owner (void *ptr)
29 MonoLoadedImages *li = mono_get_global_loaded_images ();
30 mono_images_lock ();
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};
36 int hash_idx;
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]];
40 GHashTableIter iter;
41 MonoImage *image;
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))
49 owner = image;
50 mono_image_unlock (image);
54 mono_images_unlock ();
56 return owner;
59 MonoLoadedImages *
60 mono_alc_get_loaded_images (MonoAssemblyLoadContext *alc)
62 return mono_get_global_loaded_images ();
65 #endif /* ENABLE_NETCORE */