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;
126 gboolean from_llvm:1;
128 /* FIXME: Embed this after the structure later */
131 MonoJitExceptionInfo clauses [MONO_ZERO_LEN_ARRAY];
132 /* There is an optional MonoGenericJitInfo after the clauses */
135 struct _MonoAppContext {
139 gpointer *static_data;
143 * We have two unloading states because the domain
144 * must remain fully functional while AppDomain::DomainUnload is
146 * After that unloading began and all domain facilities are teared down
147 * such as execution of new threadpool jobs.
150 MONO_APPDOMAIN_CREATED,
151 MONO_APPDOMAIN_UNLOADING_START,
152 MONO_APPDOMAIN_UNLOADING,
153 MONO_APPDOMAIN_UNLOADED
154 } MonoAppDomainState;
156 typedef struct _MonoThunkFreeList {
158 int length; /* only valid for the wait list */
159 struct _MonoThunkFreeList *next;
162 typedef struct _MonoJitCodeHash MonoJitCodeHash;
166 * This lock must never be taken before the loader lock,
167 * i.e. if both are taken by the same thread, the loader lock
170 CRITICAL_SECTION lock;
172 MonoCodeManager *code_mp;
174 * keep all the managed objects close to each other for the precise GC
175 * For the Boehm GC we additionally keep close also other GC-tracked pointers.
177 #define MONO_DOMAIN_FIRST_OBJECT setup
178 MonoAppDomainSetup *setup;
179 MonoAppDomain *domain;
180 MonoAppContext *default_context;
181 MonoException *out_of_memory_ex;
182 MonoException *null_reference_ex;
183 MonoException *stack_overflow_ex;
185 MonoObject *typeof_void;
187 * The fields between FIRST_GC_TRACKED and LAST_GC_TRACKED are roots, but
188 * not object references.
190 #define MONO_DOMAIN_FIRST_GC_TRACKED env
192 MonoGHashTable *ldstr_table;
193 /* hashtables for Reflection handles */
194 MonoGHashTable *type_hash;
195 MonoGHashTable *refobject_hash;
196 /* a GC-tracked array to keep references to the static fields of types */
197 gpointer *static_data_array;
198 /* maps class -> type initialization exception object */
199 MonoGHashTable *type_init_exception_hash;
200 /* maps delegate trampoline addr -> delegate object */
201 MonoGHashTable *delegate_hash_table;
202 #define MONO_DOMAIN_LAST_GC_TRACKED delegate_hash_table
204 /* Needed by Thread:GetDomainID() */
206 gint32 shadow_serial;
207 unsigned char inet_family_hint; // used in socket-io.c as a cache
208 GSList *domain_assemblies;
209 MonoAssembly *entry_assembly;
211 GHashTable *class_vtable_hash;
212 /* maps remote class key -> MonoRemoteClass */
213 GHashTable *proxy_vtable_hash;
214 /* Protected by 'jit_code_hash_lock' */
215 MonoInternalHashTable jit_code_hash;
216 CRITICAL_SECTION jit_code_hash_lock;
217 int num_jit_info_tables;
219 volatile jit_info_table;
220 GSList *jit_info_free_queue;
221 /* Used when loading assemblies */
223 gchar *private_bin_path;
225 /* Used by remoting proxies */
226 MonoMethod *create_proxy_for_type_method;
227 MonoMethod *private_invoke_method;
228 /* Used to store offsets of thread and context static fields */
229 GHashTable *special_static_fields;
231 * This must be a GHashTable, since these objects can't be finalized
232 * if the hashtable contains a GC visible reference to them.
234 GHashTable *finalizable_objects_hash;
236 /* Maps MonoObjects to a GSList of WeakTrackResurrection GCHandles pointing to them */
237 GHashTable *track_resurrection_objects_hash;
238 /* Maps WeakTrackResurrection GCHandles to the MonoObjects they point to */
239 GHashTable *track_resurrection_handles_hash;
241 /* Protects the three hashes above */
242 CRITICAL_SECTION finalizable_objects_hash_lock;
243 /* Used when accessing 'domain_assemblies' */
244 CRITICAL_SECTION assemblies_lock;
246 GHashTable *method_rgctx_hash;
248 GHashTable *generic_virtual_cases;
249 MonoThunkFreeList **thunk_free_lists;
251 /* Information maintained by the JIT engine */
252 gpointer runtime_info;
254 /*thread pool jobs, used to coordinate shutdown.*/
256 HANDLE cleanup_semaphore;
258 /* Contains the compiled runtime invoke wrapper used by finalizers */
259 gpointer finalize_runtime_invoke;
261 /* Contains the compiled runtime invoke wrapper used by async resylt creation to capture thread context*/
262 gpointer capture_context_runtime_invoke;
264 /* Contains the compiled method used by async resylt creation to capture thread context*/
265 gpointer capture_context_method;
269 guint16 major, minor, build, revision;
270 } AssemblyVersionSet;
272 /* MonoRuntimeInfo: Contains information about versions supported by this runtime */
274 const char runtime_version [12];
275 const char framework_version [4];
276 const AssemblyVersionSet version_sets [2];
279 #define mono_domain_lock(domain) mono_locks_acquire(&(domain)->lock, DomainLock)
280 #define mono_domain_unlock(domain) mono_locks_release(&(domain)->lock, DomainLock)
281 #define mono_domain_assemblies_lock(domain) mono_locks_acquire(&(domain)->assemblies_lock, DomainAssembliesLock)
282 #define mono_domain_assemblies_unlock(domain) mono_locks_release(&(domain)->assemblies_lock, DomainAssembliesLock)
283 #define mono_domain_jit_code_hash_lock(domain) mono_locks_acquire(&(domain)->jit_code_hash_lock, DomainJitCodeHashLock)
284 #define mono_domain_jit_code_hash_unlock(domain) mono_locks_release(&(domain)->jit_code_hash_lock, DomainJitCodeHashLock)
286 typedef MonoDomain* (*MonoLoadFunc) (const char *filename, const char *runtime_version);
289 mono_install_runtime_load (MonoLoadFunc func) MONO_INTERNAL;
292 mono_runtime_load (const char *filename, const char *runtime_version) MONO_INTERNAL;
294 typedef void (*MonoCreateDomainFunc) (MonoDomain *domain);
297 mono_install_create_domain_hook (MonoCreateDomainFunc func) MONO_INTERNAL;
299 typedef void (*MonoFreeDomainFunc) (MonoDomain *domain);
302 mono_install_free_domain_hook (MonoFreeDomainFunc func) MONO_INTERNAL;
305 mono_init_com_types (void) MONO_INTERNAL;
308 mono_cleanup (void) MONO_INTERNAL;
311 mono_close_exe_image (void) MONO_INTERNAL;
314 mono_jit_info_table_add (MonoDomain *domain, MonoJitInfo *ji) MONO_INTERNAL;
317 mono_jit_info_table_remove (MonoDomain *domain, MonoJitInfo *ji) MONO_INTERNAL;
320 mono_jit_info_add_aot_module (MonoImage *image, gpointer start, gpointer end) MONO_INTERNAL;
323 mono_jit_info_get_generic_jit_info (MonoJitInfo *ji) MONO_INTERNAL;
325 MonoGenericSharingContext*
326 mono_jit_info_get_generic_sharing_context (MonoJitInfo *ji) MONO_INTERNAL;
329 mono_jit_info_set_generic_sharing_context (MonoJitInfo *ji, MonoGenericSharingContext *gsctx) MONO_INTERNAL;
332 mono_domain_lookup_shared_generic (MonoDomain *domain, MonoMethod *method) MONO_INTERNAL;
335 mono_make_shadow_copy (const char *filename) MONO_INTERNAL;
338 mono_is_shadow_copy_enabled (MonoDomain *domain, const gchar *dir_name) MONO_INTERNAL;
341 mono_domain_alloc (MonoDomain *domain, guint size) MONO_INTERNAL;
344 mono_domain_alloc0 (MonoDomain *domain, guint size) MONO_INTERNAL;
347 mono_domain_code_reserve (MonoDomain *domain, int size) MONO_INTERNAL;
350 mono_domain_code_reserve_align (MonoDomain *domain, int size, int alignment) MONO_INTERNAL;
353 mono_domain_code_commit (MonoDomain *domain, void *data, int size, int newsize) MONO_INTERNAL;
356 mono_domain_code_foreach (MonoDomain *domain, MonoCodeManagerFunc func, void *user_data) MONO_INTERNAL;
359 mono_domain_set_internal_with_options (MonoDomain *domain, gboolean migrate_exception) MONO_INTERNAL;
362 * Installs a new function which is used to return a MonoJitInfo for a method inside
365 typedef MonoJitInfo *(*MonoJitInfoFindInAot) (MonoDomain *domain, MonoImage *image, gpointer addr);
366 void mono_install_jit_info_find_in_aot (MonoJitInfoFindInAot func) MONO_INTERNAL;
369 mono_jit_code_hash_init (MonoInternalHashTable *jit_code_hash) MONO_INTERNAL;
372 ves_icall_System_AppDomain_getCurDomain (void) MONO_INTERNAL;
375 ves_icall_System_AppDomain_getRootDomain (void) MONO_INTERNAL;
378 ves_icall_System_AppDomain_createDomain (MonoString *friendly_name,
379 MonoAppDomainSetup *setup) MONO_INTERNAL;
382 ves_icall_System_AppDomain_GetData (MonoAppDomain *ad,
383 MonoString *name) MONO_INTERNAL;
385 MonoReflectionAssembly *
386 ves_icall_System_AppDomain_LoadAssemblyRaw (MonoAppDomain *ad,
387 MonoArray *raw_assembly,
388 MonoArray *raw_symbol_store,
389 MonoObject *evidence,
390 MonoBoolean refonly) MONO_INTERNAL;
393 ves_icall_System_AppDomain_SetData (MonoAppDomain *ad,
395 MonoObject *data) MONO_INTERNAL;
398 ves_icall_System_AppDomain_getSetup (MonoAppDomain *ad) MONO_INTERNAL;
401 ves_icall_System_AppDomain_getFriendlyName (MonoAppDomain *ad) MONO_INTERNAL;
404 ves_icall_System_AppDomain_GetAssemblies (MonoAppDomain *ad,
405 MonoBoolean refonly) MONO_INTERNAL;
407 MonoReflectionAssembly *
408 ves_icall_System_Reflection_Assembly_LoadFrom (MonoString *fname,
409 MonoBoolean refonly) MONO_INTERNAL;
411 MonoReflectionAssembly *
412 ves_icall_System_AppDomain_LoadAssembly (MonoAppDomain *ad,
414 MonoObject *evidence,
415 MonoBoolean refonly) MONO_INTERNAL;
418 ves_icall_System_AppDomain_InternalIsFinalizingForUnload (gint32 domain_id) MONO_INTERNAL;
421 ves_icall_System_AppDomain_InternalUnload (gint32 domain_id) MONO_INTERNAL;
424 ves_icall_System_AppDomain_ExecuteAssembly (MonoAppDomain *ad,
425 MonoReflectionAssembly *refass,
426 MonoArray *args) MONO_INTERNAL;
429 ves_icall_System_AppDomain_InternalSetDomain (MonoAppDomain *ad) MONO_INTERNAL;
432 ves_icall_System_AppDomain_InternalSetDomainByID (gint32 domainid) MONO_INTERNAL;
435 ves_icall_System_AppDomain_InternalPushDomainRef (MonoAppDomain *ad) MONO_INTERNAL;
438 ves_icall_System_AppDomain_InternalPushDomainRefByID (gint32 domain_id) MONO_INTERNAL;
441 ves_icall_System_AppDomain_InternalPopDomainRef (void) MONO_INTERNAL;
444 ves_icall_System_AppDomain_InternalGetContext (void) MONO_INTERNAL;
447 ves_icall_System_AppDomain_InternalGetDefaultContext (void) MONO_INTERNAL;
450 ves_icall_System_AppDomain_InternalSetContext (MonoAppContext *mc) MONO_INTERNAL;
453 ves_icall_System_AppDomain_GetIDFromDomain (MonoAppDomain * ad) MONO_INTERNAL;
456 ves_icall_System_AppDomain_InternalGetProcessGuid (MonoString* newguid) MONO_INTERNAL;
459 mono_assembly_load_corlib (const MonoRuntimeInfo *runtime, MonoImageOpenStatus *status) MONO_INTERNAL;
461 const MonoRuntimeInfo*
462 mono_get_runtime_info (void) MONO_INTERNAL;
465 mono_runtime_set_no_exec (gboolean val) MONO_INTERNAL;
468 mono_runtime_get_no_exec (void) MONO_INTERNAL;
471 mono_assembly_name_parse (const char *name, MonoAssemblyName *aname) MONO_INTERNAL;
474 mono_assembly_name_free (MonoAssemblyName *aname) MONO_INTERNAL;
476 MonoImage *mono_assembly_open_from_bundle (const char *filename,
477 MonoImageOpenStatus *status,
478 gboolean refonly) MONO_INTERNAL;
481 mono_domain_add_class_static_data (MonoDomain *domain, MonoClass *klass, gpointer data, guint32 *bitmap);
483 MonoReflectionAssembly *
484 mono_try_assembly_resolve (MonoDomain *domain, MonoString *fname, gboolean refonly) MONO_INTERNAL;
486 MonoAssembly* mono_assembly_load_full_nosearch (MonoAssemblyName *aname,
488 MonoImageOpenStatus *status,
489 gboolean refonly) MONO_INTERNAL;
491 void mono_set_private_bin_path_from_config (MonoDomain *domain) MONO_INTERNAL;
493 int mono_framework_version (void) MONO_INTERNAL;
495 void mono_reflection_cleanup_domain (MonoDomain *domain) MONO_INTERNAL;
497 #endif /* __MONO_METADATA_DOMAIN_INTERNALS_H__ */