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/mempool.h>
9 #include <mono/metadata/lock-tracer.h>
10 #include <mono/utils/mono-codeman.h>
11 #include <mono/utils/mono-hash.h>
12 #include <mono/utils/mono-compiler.h>
13 #include <mono/utils/mono-internal-hash.h>
14 #include <mono/io-layer/io-layer.h>
15 #include <mono/metadata/mempool-internals.h>
17 extern CRITICAL_SECTION mono_delegate_section;
18 extern CRITICAL_SECTION mono_strtod_mutex;
21 * If this is set, the memory belonging to appdomains is not freed when a domain is
22 * unloaded, and assemblies loaded by the appdomain are not unloaded either. This
23 * allows us to use typed gc in non-default appdomains too, leading to increased
26 extern gboolean mono_dont_free_domains;
28 /* This is a copy of System.AppDomainSetup */
31 MonoString *application_base;
32 MonoString *application_name;
33 MonoString *cache_path;
34 MonoString *configuration_file;
35 MonoString *dynamic_base;
36 MonoString *license_file;
37 MonoString *private_bin_path;
38 MonoString *private_bin_path_probe;
39 MonoString *shadow_copy_directories;
40 MonoString *shadow_copy_files;
41 MonoBoolean publisher_policy;
42 MonoBoolean path_changed;
43 int loader_optimization;
44 MonoBoolean disallow_binding_redirects;
45 MonoBoolean disallow_code_downloads;
46 MonoObject *activation_arguments; /* it is System.Object in 1.x, ActivationArguments in 2.0 */
47 MonoObject *domain_initializer;
48 MonoObject *application_trust; /* it is System.Object in 1.x, ApplicationTrust in 2.0 */
49 MonoArray *domain_initializer_args;
50 MonoBoolean disallow_appbase_probe;
51 MonoArray *configuration_bytes;
52 MonoArray *serialized_non_primitives;
55 typedef struct _MonoJitInfoTable MonoJitInfoTable;
56 typedef struct _MonoJitInfoTableChunk MonoJitInfoTableChunk;
58 #define MONO_JIT_INFO_TABLE_CHUNK_SIZE 64
60 struct _MonoJitInfoTableChunk
63 volatile int num_elements;
64 volatile gint8 *last_code_end;
65 MonoJitInfo * volatile data [MONO_JIT_INFO_TABLE_CHUNK_SIZE];
68 struct _MonoJitInfoTable
72 MonoJitInfoTableChunk *chunks [MONO_ZERO_LEN_ARRAY];
75 #define MONO_SIZEOF_JIT_INFO_TABLE (sizeof (struct _MonoJitInfoTable) - MONO_ZERO_LEN_ARRAY * SIZEOF_VOID_P)
77 typedef GArray MonoAotModuleInfoTable;
84 gpointer handler_start;
86 MonoClass *catch_class;
89 } MonoJitExceptionInfo;
92 * Will contain information on the generic type arguments in the
93 * future. For now, all arguments are always reference types.
97 } MonoGenericSharingContext;
101 MonoGenericSharingContext *generic_sharing_context;
105 gboolean this_in_reg:1;
106 } MonoGenericJitInfo;
108 struct _MonoJitInfo {
109 /* NOTE: These first two elements (method and
110 next_jit_code_hash) must be in the same order and at the
111 same offset as in RuntimeMethod, because of the jit_code_hash
112 internal hash table in MonoDomain. */
114 struct _MonoJitInfo *next_jit_code_hash;
116 /* This might contain an id for the unwind info instead of a register mask */
119 guint32 num_clauses:15;
120 /* Whenever the code is domain neutral or 'shared' */
121 gboolean domain_neutral:1;
122 gboolean cas_inited:1;
123 gboolean cas_class_assert:1;
124 gboolean cas_class_deny:1;
125 gboolean cas_class_permitonly:1;
126 gboolean cas_method_assert:1;
127 gboolean cas_method_deny:1;
128 gboolean cas_method_permitonly:1;
129 gboolean has_generic_jit_info:1;
131 gboolean from_llvm:1;
133 /* FIXME: Embed this after the structure later */
136 MonoJitExceptionInfo clauses [MONO_ZERO_LEN_ARRAY];
137 /* There is an optional MonoGenericJitInfo after the clauses */
140 #define MONO_SIZEOF_JIT_INFO (offsetof (struct _MonoJitInfo, clauses))
142 struct _MonoAppContext {
146 gpointer *static_data;
150 * We have two unloading states because the domain
151 * must remain fully functional while AppDomain::DomainUnload is
153 * After that unloading began and all domain facilities are teared down
154 * such as execution of new threadpool jobs.
157 MONO_APPDOMAIN_CREATED,
158 MONO_APPDOMAIN_UNLOADING_START,
159 MONO_APPDOMAIN_UNLOADING,
160 MONO_APPDOMAIN_UNLOADED
161 } MonoAppDomainState;
163 typedef struct _MonoThunkFreeList {
165 int length; /* only valid for the wait list */
166 struct _MonoThunkFreeList *next;
169 typedef struct _MonoJitCodeHash MonoJitCodeHash;
173 * This lock must never be taken before the loader lock,
174 * i.e. if both are taken by the same thread, the loader lock
177 CRITICAL_SECTION lock;
179 MonoCodeManager *code_mp;
181 * keep all the managed objects close to each other for the precise GC
182 * For the Boehm GC we additionally keep close also other GC-tracked pointers.
184 #define MONO_DOMAIN_FIRST_OBJECT setup
185 MonoAppDomainSetup *setup;
186 MonoAppDomain *domain;
187 MonoAppContext *default_context;
188 MonoException *out_of_memory_ex;
189 MonoException *null_reference_ex;
190 MonoException *stack_overflow_ex;
192 MonoObject *typeof_void;
194 * The fields between FIRST_GC_TRACKED and LAST_GC_TRACKED are roots, but
195 * not object references.
197 #define MONO_DOMAIN_FIRST_GC_TRACKED env
199 MonoGHashTable *ldstr_table;
200 /* hashtables for Reflection handles */
201 MonoGHashTable *type_hash;
202 MonoGHashTable *refobject_hash;
203 /* a GC-tracked array to keep references to the static fields of types */
204 gpointer *static_data_array;
205 /* maps class -> type initialization exception object */
206 MonoGHashTable *type_init_exception_hash;
207 /* maps delegate trampoline addr -> delegate object */
208 MonoGHashTable *delegate_hash_table;
209 #define MONO_DOMAIN_LAST_GC_TRACKED delegate_hash_table
211 /* Needed by Thread:GetDomainID() */
213 gint32 shadow_serial;
214 unsigned char inet_family_hint; // used in socket-io.c as a cache
215 GSList *domain_assemblies;
216 MonoAssembly *entry_assembly;
218 GPtrArray *class_vtable_array;
219 /* maps remote class key -> MonoRemoteClass */
220 GHashTable *proxy_vtable_hash;
221 /* Protected by 'jit_code_hash_lock' */
222 MonoInternalHashTable jit_code_hash;
223 CRITICAL_SECTION jit_code_hash_lock;
224 int num_jit_info_tables;
226 volatile jit_info_table;
227 GSList *jit_info_free_queue;
228 /* Used when loading assemblies */
230 gchar *private_bin_path;
232 /* Used by remoting proxies */
233 MonoMethod *create_proxy_for_type_method;
234 MonoMethod *private_invoke_method;
235 /* Used to store offsets of thread and context static fields */
236 GHashTable *special_static_fields;
238 * This must be a GHashTable, since these objects can't be finalized
239 * if the hashtable contains a GC visible reference to them.
241 GHashTable *finalizable_objects_hash;
243 /* Maps MonoObjects to a GSList of WeakTrackResurrection GCHandles pointing to them */
244 GHashTable *track_resurrection_objects_hash;
245 /* Maps WeakTrackResurrection GCHandles to the MonoObjects they point to */
246 GHashTable *track_resurrection_handles_hash;
248 /* Protects the three hashes above */
249 CRITICAL_SECTION finalizable_objects_hash_lock;
250 /* Used when accessing 'domain_assemblies' */
251 CRITICAL_SECTION assemblies_lock;
253 GHashTable *method_rgctx_hash;
255 GHashTable *generic_virtual_cases;
256 MonoThunkFreeList **thunk_free_lists;
258 /* Information maintained by the JIT engine */
259 gpointer runtime_info;
261 /*thread pool jobs, used to coordinate shutdown.*/
263 HANDLE cleanup_semaphore;
265 /* Contains the compiled runtime invoke wrapper used by finalizers */
266 gpointer finalize_runtime_invoke;
268 /* Contains the compiled runtime invoke wrapper used by async resylt creation to capture thread context*/
269 gpointer capture_context_runtime_invoke;
271 /* Contains the compiled method used by async resylt creation to capture thread context*/
272 gpointer capture_context_method;
274 /* Assembly bindings, the per-domain part */
275 GSList *assembly_bindings;
276 gboolean assembly_bindings_parsed;
280 guint16 major, minor, build, revision;
281 } AssemblyVersionSet;
283 /* MonoRuntimeInfo: Contains information about versions supported by this runtime */
285 const char runtime_version [12];
286 const char framework_version [4];
287 const AssemblyVersionSet version_sets [2];
290 #define mono_domain_lock(domain) mono_locks_acquire(&(domain)->lock, DomainLock)
291 #define mono_domain_unlock(domain) mono_locks_release(&(domain)->lock, DomainLock)
292 #define mono_domain_assemblies_lock(domain) mono_locks_acquire(&(domain)->assemblies_lock, DomainAssembliesLock)
293 #define mono_domain_assemblies_unlock(domain) mono_locks_release(&(domain)->assemblies_lock, DomainAssembliesLock)
294 #define mono_domain_jit_code_hash_lock(domain) mono_locks_acquire(&(domain)->jit_code_hash_lock, DomainJitCodeHashLock)
295 #define mono_domain_jit_code_hash_unlock(domain) mono_locks_release(&(domain)->jit_code_hash_lock, DomainJitCodeHashLock)
297 typedef MonoDomain* (*MonoLoadFunc) (const char *filename, const char *runtime_version);
300 mono_install_runtime_load (MonoLoadFunc func) MONO_INTERNAL;
303 mono_runtime_load (const char *filename, const char *runtime_version) MONO_INTERNAL;
305 typedef void (*MonoCreateDomainFunc) (MonoDomain *domain);
308 mono_install_create_domain_hook (MonoCreateDomainFunc func) MONO_INTERNAL;
310 typedef void (*MonoFreeDomainFunc) (MonoDomain *domain);
313 mono_install_free_domain_hook (MonoFreeDomainFunc func) MONO_INTERNAL;
316 mono_init_com_types (void) MONO_INTERNAL;
319 mono_cleanup (void) MONO_INTERNAL;
322 mono_close_exe_image (void) MONO_INTERNAL;
325 mono_jit_info_table_add (MonoDomain *domain, MonoJitInfo *ji) MONO_INTERNAL;
328 mono_jit_info_table_remove (MonoDomain *domain, MonoJitInfo *ji) MONO_INTERNAL;
331 mono_jit_info_add_aot_module (MonoImage *image, gpointer start, gpointer end) MONO_INTERNAL;
334 mono_jit_info_get_generic_jit_info (MonoJitInfo *ji) MONO_INTERNAL;
336 MonoGenericSharingContext*
337 mono_jit_info_get_generic_sharing_context (MonoJitInfo *ji) MONO_INTERNAL;
340 mono_jit_info_set_generic_sharing_context (MonoJitInfo *ji, MonoGenericSharingContext *gsctx) MONO_INTERNAL;
343 mono_domain_lookup_shared_generic (MonoDomain *domain, MonoMethod *method) MONO_INTERNAL;
346 mono_make_shadow_copy (const char *filename) MONO_INTERNAL;
349 mono_is_shadow_copy_enabled (MonoDomain *domain, const gchar *dir_name) MONO_INTERNAL;
352 mono_domain_alloc (MonoDomain *domain, guint size) MONO_INTERNAL;
355 mono_domain_alloc0 (MonoDomain *domain, guint size) MONO_INTERNAL;
358 mono_domain_code_reserve (MonoDomain *domain, int size) MONO_INTERNAL;
361 mono_domain_code_reserve_align (MonoDomain *domain, int size, int alignment) MONO_INTERNAL;
364 mono_domain_code_commit (MonoDomain *domain, void *data, int size, int newsize) MONO_INTERNAL;
367 mono_domain_code_foreach (MonoDomain *domain, MonoCodeManagerFunc func, void *user_data) MONO_INTERNAL;
370 mono_domain_unset (void) MONO_INTERNAL;
373 mono_domain_set_internal_with_options (MonoDomain *domain, gboolean migrate_exception) MONO_INTERNAL;
376 * Installs a new function which is used to return a MonoJitInfo for a method inside
379 typedef MonoJitInfo *(*MonoJitInfoFindInAot) (MonoDomain *domain, MonoImage *image, gpointer addr);
380 void mono_install_jit_info_find_in_aot (MonoJitInfoFindInAot func) MONO_INTERNAL;
383 mono_jit_code_hash_init (MonoInternalHashTable *jit_code_hash) MONO_INTERNAL;
386 ves_icall_System_AppDomain_getCurDomain (void) MONO_INTERNAL;
389 ves_icall_System_AppDomain_getRootDomain (void) MONO_INTERNAL;
392 ves_icall_System_AppDomain_createDomain (MonoString *friendly_name,
393 MonoAppDomainSetup *setup) MONO_INTERNAL;
396 ves_icall_System_AppDomain_GetData (MonoAppDomain *ad,
397 MonoString *name) MONO_INTERNAL;
399 MonoReflectionAssembly *
400 ves_icall_System_AppDomain_LoadAssemblyRaw (MonoAppDomain *ad,
401 MonoArray *raw_assembly,
402 MonoArray *raw_symbol_store,
403 MonoObject *evidence,
404 MonoBoolean refonly) MONO_INTERNAL;
407 ves_icall_System_AppDomain_SetData (MonoAppDomain *ad,
409 MonoObject *data) MONO_INTERNAL;
412 ves_icall_System_AppDomain_getSetup (MonoAppDomain *ad) MONO_INTERNAL;
415 ves_icall_System_AppDomain_getFriendlyName (MonoAppDomain *ad) MONO_INTERNAL;
418 ves_icall_System_AppDomain_GetAssemblies (MonoAppDomain *ad,
419 MonoBoolean refonly) MONO_INTERNAL;
421 MonoReflectionAssembly *
422 ves_icall_System_Reflection_Assembly_LoadFrom (MonoString *fname,
423 MonoBoolean refonly) MONO_INTERNAL;
425 MonoReflectionAssembly *
426 ves_icall_System_AppDomain_LoadAssembly (MonoAppDomain *ad,
428 MonoObject *evidence,
429 MonoBoolean refonly) MONO_INTERNAL;
432 ves_icall_System_AppDomain_InternalIsFinalizingForUnload (gint32 domain_id) MONO_INTERNAL;
435 ves_icall_System_AppDomain_InternalUnload (gint32 domain_id) MONO_INTERNAL;
438 ves_icall_System_AppDomain_ExecuteAssembly (MonoAppDomain *ad,
439 MonoReflectionAssembly *refass,
440 MonoArray *args) MONO_INTERNAL;
443 ves_icall_System_AppDomain_InternalSetDomain (MonoAppDomain *ad) MONO_INTERNAL;
446 ves_icall_System_AppDomain_InternalSetDomainByID (gint32 domainid) MONO_INTERNAL;
449 ves_icall_System_AppDomain_InternalPushDomainRef (MonoAppDomain *ad) MONO_INTERNAL;
452 ves_icall_System_AppDomain_InternalPushDomainRefByID (gint32 domain_id) MONO_INTERNAL;
455 ves_icall_System_AppDomain_InternalPopDomainRef (void) MONO_INTERNAL;
458 ves_icall_System_AppDomain_InternalGetContext (void) MONO_INTERNAL;
461 ves_icall_System_AppDomain_InternalGetDefaultContext (void) MONO_INTERNAL;
464 ves_icall_System_AppDomain_InternalSetContext (MonoAppContext *mc) MONO_INTERNAL;
467 ves_icall_System_AppDomain_GetIDFromDomain (MonoAppDomain * ad) MONO_INTERNAL;
470 ves_icall_System_AppDomain_InternalGetProcessGuid (MonoString* newguid) MONO_INTERNAL;
473 mono_assembly_load_corlib (const MonoRuntimeInfo *runtime, MonoImageOpenStatus *status) MONO_INTERNAL;
475 const MonoRuntimeInfo*
476 mono_get_runtime_info (void) MONO_INTERNAL;
479 mono_runtime_set_no_exec (gboolean val) MONO_INTERNAL;
482 mono_runtime_get_no_exec (void) MONO_INTERNAL;
485 mono_assembly_name_parse (const char *name, MonoAssemblyName *aname) MONO_INTERNAL;
487 MonoImage *mono_assembly_open_from_bundle (const char *filename,
488 MonoImageOpenStatus *status,
489 gboolean refonly) MONO_INTERNAL;
492 mono_domain_add_class_static_data (MonoDomain *domain, MonoClass *klass, gpointer data, guint32 *bitmap);
494 MonoReflectionAssembly *
495 mono_try_assembly_resolve (MonoDomain *domain, MonoString *fname, gboolean refonly) MONO_INTERNAL;
497 MonoAssembly* mono_assembly_load_full_nosearch (MonoAssemblyName *aname,
499 MonoImageOpenStatus *status,
500 gboolean refonly) MONO_INTERNAL;
502 void mono_set_private_bin_path_from_config (MonoDomain *domain) MONO_INTERNAL;
504 int mono_framework_version (void) MONO_INTERNAL;
506 void mono_reflection_cleanup_domain (MonoDomain *domain) MONO_INTERNAL;
508 #endif /* __MONO_METADATA_DOMAIN_INTERNALS_H__ */