Welcome to mirror list, hosted at ThFree Co, Russian Federation.

loaded-images-global.c « metadata « mono - github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: dbcf79dc51bb081f12c2b2ed2fc88485ec5782a7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include <config.h>

#include "mono/metadata/loaded-images-internals.h"
#include "mono/metadata/metadata-internals.h"

/* Global image hashes should not be in netcore Mono */

static MonoLoadedImages global_loaded_images; /* zero initalized is good enough */

MonoLoadedImages*
mono_get_global_loaded_images (void)
{
	return &global_loaded_images;
}

// This is support for the mempool reference tracking feature in checked-build,
// but lives in loaded-images-global.c due to use of static variables of this
// file.

/**
 * mono_find_image_owner:
 *
 * Find the image, if any, which a given pointer is located in the memory of.
 */
MonoImage *
mono_find_image_owner (void *ptr)
{
	MonoLoadedImages *li = mono_get_global_loaded_images ();
	mono_images_lock ();

	MonoImage *owner = NULL;

	// Iterate over both by-path image hashes
	const int hash_candidates[] = {MONO_LOADED_IMAGES_HASH_PATH, MONO_LOADED_IMAGES_HASH_PATH_REFONLY};
	int hash_idx;
	for (hash_idx = 0; !owner && hash_idx < G_N_ELEMENTS (hash_candidates); hash_idx++)
	{
		GHashTable *target = li->loaded_images_hashes [hash_candidates [hash_idx]];
		GHashTableIter iter;
		MonoImage *image;

		// Iterate over images within a hash
		g_hash_table_iter_init (&iter, target);
		while (!owner && g_hash_table_iter_next(&iter, NULL, (gpointer *)&image))
		{
			mono_image_lock (image);
			if (mono_mempool_contains_addr (image->mempool, ptr))
				owner = image;
			mono_image_unlock (image);
		}
	}

	mono_images_unlock ();

	return owner;
}

MonoLoadedImages *
mono_alc_get_loaded_images (MonoAssemblyLoadContext *alc)
{
	return mono_get_global_loaded_images ();
}