2 * Appdomain-related internal data structures and functions.
4 #ifndef __MONO_METADATA_DOMAIN_INTERNALS_H__
5 #define __MONO_METADATA_DOMAIN_INTERNALS_H__
7 #include <mono/metadata/appdomain.h>
8 #include <mono/metadata/lock-tracer.h>
9 #include <mono/utils/mono-codeman.h>
10 #include <mono/utils/mono-hash.h>
11 #include <mono/utils/mono-compiler.h>
12 #include <mono/utils/mono-internal-hash.h>
13 #include <mono/io-layer/io-layer.h>
15 extern CRITICAL_SECTION mono_delegate_section;
16 extern CRITICAL_SECTION mono_strtod_mutex;
19 * If this is set, the memory belonging to appdomains is not freed when a domain is
20 * unloaded, and assemblies loaded by the appdomain are not unloaded either. This
21 * allows us to use typed gc in non-default appdomains too, leading to increased
24 extern gboolean mono_dont_free_domains;
26 /* This is a copy of System.AppDomainSetup */
29 MonoString *application_base;
30 MonoString *application_name;
31 MonoString *cache_path;
32 MonoString *configuration_file;
33 MonoString *dynamic_base;
34 MonoString *license_file;
35 MonoString *private_bin_path;
36 MonoString *private_bin_path_probe;
37 MonoString *shadow_copy_directories;
38 MonoString *shadow_copy_files;
39 MonoBoolean publisher_policy;
40 MonoBoolean path_changed;
41 int loader_optimization;
42 MonoBoolean disallow_binding_redirects;
43 MonoBoolean disallow_code_downloads;
44 MonoObject *activation_arguments; /* it is System.Object in 1.x, ActivationArguments in 2.0 */
45 MonoObject *domain_initializer;
46 MonoArray *domain_initializer_args;
47 MonoObject *application_trust; /* it is System.Object in 1.x, ApplicationTrust in 2.0 */
48 MonoBoolean disallow_appbase_probe;
49 MonoArray *configuration_bytes;
52 typedef struct _MonoJitInfoTable MonoJitInfoTable;
53 typedef struct _MonoJitInfoTableChunk MonoJitInfoTableChunk;
55 #define MONO_JIT_INFO_TABLE_CHUNK_SIZE 64
57 struct _MonoJitInfoTableChunk
60 volatile int num_elements;
61 volatile gint8 *last_code_end;
62 MonoJitInfo * volatile data [MONO_JIT_INFO_TABLE_CHUNK_SIZE];
65 struct _MonoJitInfoTable
69 MonoJitInfoTableChunk *chunks [MONO_ZERO_LEN_ARRAY];
72 typedef GArray MonoAotModuleInfoTable;
79 gpointer handler_start;
81 MonoClass *catch_class;
84 } MonoJitExceptionInfo;
87 * Will contain information on the generic type arguments in the
88 * future. For now, all arguments are always reference types.
92 } MonoGenericSharingContext;
96 MonoGenericSharingContext *generic_sharing_context;
100 gboolean this_in_reg:1;
101 } MonoGenericJitInfo;
103 struct _MonoJitInfo {
104 /* NOTE: These first two elements (method and
105 next_jit_code_hash) must be in the same order and at the
106 same offset as in RuntimeMethod, because of the jit_code_hash
107 internal hash table in MonoDomain. */
109 struct _MonoJitInfo *next_jit_code_hash;
111 /* This might contain an id for the unwind info instead of a register mask */
114 guint32 num_clauses:15;
115 /* Whenever the code is domain neutral or 'shared' */
116 gboolean domain_neutral:1;
117 gboolean cas_inited:1;
118 gboolean cas_class_assert:1;
119 gboolean cas_class_deny:1;
120 gboolean cas_class_permitonly:1;
121 gboolean cas_method_assert:1;
122 gboolean cas_method_deny:1;
123 gboolean cas_method_permitonly:1;
124 gboolean has_generic_jit_info:1;
127 /* FIXME: Embed this after the structure later */
130 MonoJitExceptionInfo clauses [MONO_ZERO_LEN_ARRAY];
131 /* There is an optional MonoGenericJitInfo after the clauses */
134 struct _MonoAppContext {
138 gpointer *static_data;
142 * We have two unloading states because the domain
143 * must remain fully functional while AppDomain::DomainUnload is
145 * After that unloading began and all domain facilities are teared down
146 * such as execution of new threadpool jobs.
149 MONO_APPDOMAIN_CREATED,
150 MONO_APPDOMAIN_UNLOADING_START,
151 MONO_APPDOMAIN_UNLOADING,
152 MONO_APPDOMAIN_UNLOADED
153 } MonoAppDomainState;
155 typedef struct _MonoThunkFreeList {
157 int length; /* only valid for the wait list */
158 struct _MonoThunkFreeList *next;
161 typedef struct _MonoJitCodeHash MonoJitCodeHash;
165 * This lock must never be taken before the loader lock,
166 * i.e. if both are taken by the same thread, the loader lock
169 CRITICAL_SECTION lock;
171 MonoCodeManager *code_mp;
173 * keep all the managed objects close to each other for the precise GC
174 * For the Boehm GC we additionally keep close also other GC-tracked pointers.
176 #define MONO_DOMAIN_FIRST_OBJECT setup
177 MonoAppDomainSetup *setup;
178 MonoAppDomain *domain;
179 MonoAppContext *default_context;
180 MonoException *out_of_memory_ex;
181 MonoException *null_reference_ex;
182 MonoException *stack_overflow_ex;
184 MonoObject *typeof_void;
186 * The fields between FIRST_GC_TRACKED and LAST_GC_TRACKED are roots, but
187 * not object references.
189 #define MONO_DOMAIN_FIRST_GC_TRACKED env
191 MonoGHashTable *ldstr_table;
192 /* hashtables for Reflection handles */
193 MonoGHashTable *type_hash;
194 MonoGHashTable *refobject_hash;
195 /* a GC-tracked array to keep references to the static fields of types */
196 gpointer *static_data_array;
197 /* maps class -> type initialization exception object */
198 MonoGHashTable *type_init_exception_hash;
199 /* maps delegate trampoline addr -> delegate object */
200 MonoGHashTable *delegate_hash_table;
201 #define MONO_DOMAIN_LAST_GC_TRACKED delegate_hash_table
203 /* Needed by Thread:GetDomainID() */
205 gint32 shadow_serial;
206 unsigned char inet_family_hint; // used in socket-io.c as a cache
207 GSList *domain_assemblies;
208 MonoAssembly *entry_assembly;
210 GHashTable *class_vtable_hash;
211 /* maps remote class key -> MonoRemoteClass */
212 GHashTable *proxy_vtable_hash;
213 /* Protected by 'jit_code_hash_lock' */
214 MonoInternalHashTable jit_code_hash;
215 CRITICAL_SECTION jit_code_hash_lock;
216 int num_jit_info_tables;
218 volatile jit_info_table;
219 GSList *jit_info_free_queue;
220 /* Used when loading assemblies */
222 gchar *private_bin_path;
224 /* Used by remoting proxies */
225 MonoMethod *create_proxy_for_type_method;
226 MonoMethod *private_invoke_method;
227 /* Used to store offsets of thread and context static fields */
228 GHashTable *special_static_fields;
230 * This must be a GHashTable, since these objects can't be finalized
231 * if the hashtable contains a GC visible reference to them.
233 GHashTable *finalizable_objects_hash;
235 /* Maps MonoObjects to a GSList of WeakTrackResurrection GCHandles pointing to them */
236 GHashTable *track_resurrection_objects_hash;
237 /* Maps WeakTrackResurrection GCHandles to the MonoObjects they point to */
238 GHashTable *track_resurrection_handles_hash;
240 /* Protects the three hashes above */
241 CRITICAL_SECTION finalizable_objects_hash_lock;
242 /* Used when accessing 'domain_assemblies' */
243 CRITICAL_SECTION assemblies_lock;
245 GHashTable *method_rgctx_hash;
247 GHashTable *generic_virtual_cases;
248 MonoThunkFreeList **thunk_free_lists;
250 /* Information maintained by the JIT engine */
251 gpointer runtime_info;
253 /*thread pool jobs, used to coordinate shutdown.*/
255 HANDLE cleanup_semaphore;
257 /* Contains the compiled runtime invoke wrapper used by finalizers */
258 gpointer finalize_runtime_invoke;
260 /* Contains the compiled runtime invoke wrapper used by async resylt creation to capture thread context*/
261 gpointer capture_context_runtime_invoke;
263 /* Contains the compiled method used by async resylt creation to capture thread context*/
264 gpointer capture_context_method;
268 guint16 major, minor, build, revision;
269 } AssemblyVersionSet;
271 /* MonoRuntimeInfo: Contains information about versions supported by this runtime */
273 const char runtime_version [12];
274 const char framework_version [4];
275 const AssemblyVersionSet version_sets [2];
278 #define mono_domain_lock(domain) mono_locks_acquire(&(domain)->lock, DomainLock)
279 #define mono_domain_unlock(domain) mono_locks_release(&(domain)->lock, DomainLock)
280 #define mono_domain_assemblies_lock(domain) mono_locks_acquire(&(domain)->assemblies_lock, DomainAssembliesLock)
281 #define mono_domain_assemblies_unlock(domain) mono_locks_release(&(domain)->assemblies_lock, DomainAssembliesLock)
282 #define mono_domain_jit_code_hash_lock(domain) mono_locks_acquire(&(domain)->jit_code_hash_lock, DomainJitCodeHashLock)
283 #define mono_domain_jit_code_hash_unlock(domain) mono_locks_release(&(domain)->jit_code_hash_lock, DomainJitCodeHashLock)
285 typedef MonoDomain* (*MonoLoadFunc) (const char *filename, const char *runtime_version);
288 mono_install_runtime_load (MonoLoadFunc func) MONO_INTERNAL;
291 mono_runtime_load (const char *filename, const char *runtime_version) MONO_INTERNAL;
293 typedef void (*MonoCreateDomainFunc) (MonoDomain *domain);
296 mono_install_create_domain_hook (MonoCreateDomainFunc func) MONO_INTERNAL;
298 typedef void (*MonoFreeDomainFunc) (MonoDomain *domain);
301 mono_install_free_domain_hook (MonoFreeDomainFunc func) MONO_INTERNAL;
304 mono_init_com_types (void) MONO_INTERNAL;
307 mono_cleanup (void) MONO_INTERNAL;
310 mono_close_exe_image (void) MONO_INTERNAL;
313 mono_jit_info_table_add (MonoDomain *domain, MonoJitInfo *ji) MONO_INTERNAL;
316 mono_jit_info_table_remove (MonoDomain *domain, MonoJitInfo *ji) MONO_INTERNAL;
319 mono_jit_info_add_aot_module (MonoImage *image, gpointer start, gpointer end) MONO_INTERNAL;
322 mono_jit_info_get_generic_jit_info (MonoJitInfo *ji) MONO_INTERNAL;
324 MonoGenericSharingContext*
325 mono_jit_info_get_generic_sharing_context (MonoJitInfo *ji) MONO_INTERNAL;
328 mono_jit_info_set_generic_sharing_context (MonoJitInfo *ji, MonoGenericSharingContext *gsctx) MONO_INTERNAL;
331 mono_domain_lookup_shared_generic (MonoDomain *domain, MonoMethod *method) MONO_INTERNAL;
334 mono_make_shadow_copy (const char *filename) MONO_INTERNAL;
337 mono_is_shadow_copy_enabled (MonoDomain *domain, const gchar *dir_name) MONO_INTERNAL;
340 mono_domain_alloc (MonoDomain *domain, guint size) MONO_INTERNAL;
343 mono_domain_alloc0 (MonoDomain *domain, guint size) MONO_INTERNAL;
346 mono_domain_code_reserve (MonoDomain *domain, int size) MONO_INTERNAL;
349 mono_domain_code_reserve_align (MonoDomain *domain, int size, int alignment) MONO_INTERNAL;
352 mono_domain_code_commit (MonoDomain *domain, void *data, int size, int newsize) MONO_INTERNAL;
355 mono_domain_code_foreach (MonoDomain *domain, MonoCodeManagerFunc func, void *user_data) MONO_INTERNAL;
358 mono_domain_set_internal_with_options (MonoDomain *domain, gboolean migrate_exception) MONO_INTERNAL;
361 * Installs a new function which is used to return a MonoJitInfo for a method inside
364 typedef MonoJitInfo *(*MonoJitInfoFindInAot) (MonoDomain *domain, MonoImage *image, gpointer addr);
365 void mono_install_jit_info_find_in_aot (MonoJitInfoFindInAot func) MONO_INTERNAL;
368 mono_jit_code_hash_init (MonoInternalHashTable *jit_code_hash) MONO_INTERNAL;
371 ves_icall_System_AppDomain_getCurDomain (void) MONO_INTERNAL;
374 ves_icall_System_AppDomain_getRootDomain (void) MONO_INTERNAL;
377 ves_icall_System_AppDomain_createDomain (MonoString *friendly_name,
378 MonoAppDomainSetup *setup) MONO_INTERNAL;
381 ves_icall_System_AppDomain_GetData (MonoAppDomain *ad,
382 MonoString *name) MONO_INTERNAL;
384 MonoReflectionAssembly *
385 ves_icall_System_AppDomain_LoadAssemblyRaw (MonoAppDomain *ad,
386 MonoArray *raw_assembly,
387 MonoArray *raw_symbol_store,
388 MonoObject *evidence,
389 MonoBoolean refonly) MONO_INTERNAL;
392 ves_icall_System_AppDomain_SetData (MonoAppDomain *ad,
394 MonoObject *data) MONO_INTERNAL;
397 ves_icall_System_AppDomain_getSetup (MonoAppDomain *ad) MONO_INTERNAL;
400 ves_icall_System_AppDomain_getFriendlyName (MonoAppDomain *ad) MONO_INTERNAL;
403 ves_icall_System_AppDomain_GetAssemblies (MonoAppDomain *ad,
404 MonoBoolean refonly) MONO_INTERNAL;
406 MonoReflectionAssembly *
407 ves_icall_System_Reflection_Assembly_LoadFrom (MonoString *fname,
408 MonoBoolean refonly) MONO_INTERNAL;
410 MonoReflectionAssembly *
411 ves_icall_System_AppDomain_LoadAssembly (MonoAppDomain *ad,
413 MonoObject *evidence,
414 MonoBoolean refonly) MONO_INTERNAL;
417 ves_icall_System_AppDomain_InternalIsFinalizingForUnload (gint32 domain_id) MONO_INTERNAL;
420 ves_icall_System_AppDomain_InternalUnload (gint32 domain_id) MONO_INTERNAL;
423 ves_icall_System_AppDomain_ExecuteAssembly (MonoAppDomain *ad,
424 MonoReflectionAssembly *refass,
425 MonoArray *args) MONO_INTERNAL;
428 ves_icall_System_AppDomain_InternalSetDomain (MonoAppDomain *ad) MONO_INTERNAL;
431 ves_icall_System_AppDomain_InternalSetDomainByID (gint32 domainid) MONO_INTERNAL;
434 ves_icall_System_AppDomain_InternalPushDomainRef (MonoAppDomain *ad) MONO_INTERNAL;
437 ves_icall_System_AppDomain_InternalPushDomainRefByID (gint32 domain_id) MONO_INTERNAL;
440 ves_icall_System_AppDomain_InternalPopDomainRef (void) MONO_INTERNAL;
443 ves_icall_System_AppDomain_InternalGetContext (void) MONO_INTERNAL;
446 ves_icall_System_AppDomain_InternalGetDefaultContext (void) MONO_INTERNAL;
449 ves_icall_System_AppDomain_InternalSetContext (MonoAppContext *mc) MONO_INTERNAL;
452 ves_icall_System_AppDomain_GetIDFromDomain (MonoAppDomain * ad) MONO_INTERNAL;
455 ves_icall_System_AppDomain_InternalGetProcessGuid (MonoString* newguid) MONO_INTERNAL;
458 mono_assembly_load_corlib (const MonoRuntimeInfo *runtime, MonoImageOpenStatus *status) MONO_INTERNAL;
460 const MonoRuntimeInfo*
461 mono_get_runtime_info (void) MONO_INTERNAL;
464 mono_runtime_set_no_exec (gboolean val) MONO_INTERNAL;
467 mono_runtime_get_no_exec (void) MONO_INTERNAL;
470 mono_assembly_name_parse (const char *name, MonoAssemblyName *aname) MONO_INTERNAL;
473 mono_assembly_name_free (MonoAssemblyName *aname) MONO_INTERNAL;
475 MonoImage *mono_assembly_open_from_bundle (const char *filename,
476 MonoImageOpenStatus *status,
477 gboolean refonly) MONO_INTERNAL;
480 mono_domain_add_class_static_data (MonoDomain *domain, MonoClass *klass, gpointer data, guint32 *bitmap);
482 MonoReflectionAssembly *
483 mono_try_assembly_resolve (MonoDomain *domain, MonoString *fname, gboolean refonly) MONO_INTERNAL;
485 MonoAssembly* mono_assembly_load_full_nosearch (MonoAssemblyName *aname,
487 MonoImageOpenStatus *status,
488 gboolean refonly) MONO_INTERNAL;
490 void mono_set_private_bin_path_from_config (MonoDomain *domain) MONO_INTERNAL;
492 int mono_framework_version (void) MONO_INTERNAL;
494 void mono_reflection_cleanup_domain (MonoDomain *domain) MONO_INTERNAL;
496 #endif /* __MONO_METADATA_DOMAIN_INTERNALS_H__ */