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;
234 /* Maps MonoObjects to a GSList of WeakTrackResurrection GCHandles pointing to them */
235 GHashTable *track_resurrection_objects_hash;
236 /* Maps WeakTrackResurrection GCHandles to the MonoObjects they point to */
237 GHashTable *track_resurrection_handles_hash;
238 /* Protects the three hashes above */
239 CRITICAL_SECTION finalizable_objects_hash_lock;
240 /* Used when accessing 'domain_assemblies' */
241 CRITICAL_SECTION assemblies_lock;
243 GHashTable *method_rgctx_hash;
245 GHashTable *generic_virtual_cases;
246 MonoThunkFreeList **thunk_free_lists;
248 /* Information maintained by the JIT engine */
249 gpointer runtime_info;
251 /*thread pool jobs, used to coordinate shutdown.*/
253 HANDLE cleanup_semaphore;
255 /* Contains the compiled runtime invoke wrapper used by finalizers */
256 gpointer finalize_runtime_invoke;
258 /* Contains the compiled runtime invoke wrapper used by async resylt creation to capture thread context*/
259 gpointer capture_context_runtime_invoke;
261 /* Contains the compiled method used by async resylt creation to capture thread context*/
262 gpointer capture_context_method;
266 guint16 major, minor, build, revision;
267 } AssemblyVersionSet;
269 /* MonoRuntimeInfo: Contains information about versions supported by this runtime */
271 const char runtime_version [12];
272 const char framework_version [4];
273 const AssemblyVersionSet version_sets [2];
276 #define mono_domain_lock(domain) mono_locks_acquire(&(domain)->lock, DomainLock)
277 #define mono_domain_unlock(domain) mono_locks_release(&(domain)->lock, DomainLock)
278 #define mono_domain_assemblies_lock(domain) mono_locks_acquire(&(domain)->assemblies_lock, DomainAssembliesLock)
279 #define mono_domain_assemblies_unlock(domain) mono_locks_release(&(domain)->assemblies_lock, DomainAssembliesLock)
280 #define mono_domain_jit_code_hash_lock(domain) mono_locks_acquire(&(domain)->jit_code_hash_lock, DomainJitCodeHashLock)
281 #define mono_domain_jit_code_hash_unlock(domain) mono_locks_release(&(domain)->jit_code_hash_lock, DomainJitCodeHashLock)
283 typedef MonoDomain* (*MonoLoadFunc) (const char *filename, const char *runtime_version);
286 mono_install_runtime_load (MonoLoadFunc func) MONO_INTERNAL;
289 mono_runtime_load (const char *filename, const char *runtime_version) MONO_INTERNAL;
291 typedef void (*MonoCreateDomainFunc) (MonoDomain *domain);
294 mono_install_create_domain_hook (MonoCreateDomainFunc func) MONO_INTERNAL;
296 typedef void (*MonoFreeDomainFunc) (MonoDomain *domain);
299 mono_install_free_domain_hook (MonoFreeDomainFunc func) MONO_INTERNAL;
302 mono_init_com_types (void) MONO_INTERNAL;
305 mono_cleanup (void) MONO_INTERNAL;
308 mono_close_exe_image (void) MONO_INTERNAL;
311 mono_jit_info_table_add (MonoDomain *domain, MonoJitInfo *ji) MONO_INTERNAL;
314 mono_jit_info_table_remove (MonoDomain *domain, MonoJitInfo *ji) MONO_INTERNAL;
317 mono_jit_info_add_aot_module (MonoImage *image, gpointer start, gpointer end) MONO_INTERNAL;
320 mono_jit_info_get_generic_jit_info (MonoJitInfo *ji) MONO_INTERNAL;
322 MonoGenericSharingContext*
323 mono_jit_info_get_generic_sharing_context (MonoJitInfo *ji) MONO_INTERNAL;
326 mono_jit_info_set_generic_sharing_context (MonoJitInfo *ji, MonoGenericSharingContext *gsctx) MONO_INTERNAL;
329 mono_domain_lookup_shared_generic (MonoDomain *domain, MonoMethod *method) MONO_INTERNAL;
332 mono_make_shadow_copy (const char *filename) MONO_INTERNAL;
335 mono_is_shadow_copy_enabled (MonoDomain *domain, const gchar *dir_name) MONO_INTERNAL;
338 mono_domain_alloc (MonoDomain *domain, guint size) MONO_INTERNAL;
341 mono_domain_alloc0 (MonoDomain *domain, guint size) MONO_INTERNAL;
344 mono_domain_code_reserve (MonoDomain *domain, int size) MONO_INTERNAL;
347 mono_domain_code_reserve_align (MonoDomain *domain, int size, int alignment) MONO_INTERNAL;
350 mono_domain_code_commit (MonoDomain *domain, void *data, int size, int newsize) MONO_INTERNAL;
353 mono_domain_code_foreach (MonoDomain *domain, MonoCodeManagerFunc func, void *user_data) MONO_INTERNAL;
356 * Installs a new function which is used to return a MonoJitInfo for a method inside
359 typedef MonoJitInfo *(*MonoJitInfoFindInAot) (MonoDomain *domain, MonoImage *image, gpointer addr);
360 void mono_install_jit_info_find_in_aot (MonoJitInfoFindInAot func) MONO_INTERNAL;
363 mono_jit_code_hash_init (MonoInternalHashTable *jit_code_hash) MONO_INTERNAL;
366 ves_icall_System_AppDomain_getCurDomain (void) MONO_INTERNAL;
369 ves_icall_System_AppDomain_getRootDomain (void) MONO_INTERNAL;
372 ves_icall_System_AppDomain_createDomain (MonoString *friendly_name,
373 MonoAppDomainSetup *setup) MONO_INTERNAL;
376 ves_icall_System_AppDomain_GetData (MonoAppDomain *ad,
377 MonoString *name) MONO_INTERNAL;
379 MonoReflectionAssembly *
380 ves_icall_System_AppDomain_LoadAssemblyRaw (MonoAppDomain *ad,
381 MonoArray *raw_assembly,
382 MonoArray *raw_symbol_store,
383 MonoObject *evidence,
384 MonoBoolean refonly) MONO_INTERNAL;
387 ves_icall_System_AppDomain_SetData (MonoAppDomain *ad,
389 MonoObject *data) MONO_INTERNAL;
392 ves_icall_System_AppDomain_getSetup (MonoAppDomain *ad) MONO_INTERNAL;
395 ves_icall_System_AppDomain_getFriendlyName (MonoAppDomain *ad) MONO_INTERNAL;
398 ves_icall_System_AppDomain_GetAssemblies (MonoAppDomain *ad,
399 MonoBoolean refonly) MONO_INTERNAL;
401 MonoReflectionAssembly *
402 ves_icall_System_Reflection_Assembly_LoadFrom (MonoString *fname,
403 MonoBoolean refonly) MONO_INTERNAL;
405 MonoReflectionAssembly *
406 ves_icall_System_AppDomain_LoadAssembly (MonoAppDomain *ad,
408 MonoObject *evidence,
409 MonoBoolean refonly) MONO_INTERNAL;
412 ves_icall_System_AppDomain_InternalIsFinalizingForUnload (gint32 domain_id) MONO_INTERNAL;
415 ves_icall_System_AppDomain_InternalUnload (gint32 domain_id) MONO_INTERNAL;
418 ves_icall_System_AppDomain_ExecuteAssembly (MonoAppDomain *ad,
419 MonoReflectionAssembly *refass,
420 MonoArray *args) MONO_INTERNAL;
423 ves_icall_System_AppDomain_InternalSetDomain (MonoAppDomain *ad) MONO_INTERNAL;
426 ves_icall_System_AppDomain_InternalSetDomainByID (gint32 domainid) MONO_INTERNAL;
429 ves_icall_System_AppDomain_InternalPushDomainRef (MonoAppDomain *ad) MONO_INTERNAL;
432 ves_icall_System_AppDomain_InternalPushDomainRefByID (gint32 domain_id) MONO_INTERNAL;
435 ves_icall_System_AppDomain_InternalPopDomainRef (void) MONO_INTERNAL;
438 ves_icall_System_AppDomain_InternalGetContext (void) MONO_INTERNAL;
441 ves_icall_System_AppDomain_InternalGetDefaultContext (void) MONO_INTERNAL;
444 ves_icall_System_AppDomain_InternalSetContext (MonoAppContext *mc) MONO_INTERNAL;
447 ves_icall_System_AppDomain_GetIDFromDomain (MonoAppDomain * ad) MONO_INTERNAL;
450 ves_icall_System_AppDomain_InternalGetProcessGuid (MonoString* newguid) MONO_INTERNAL;
453 mono_assembly_load_corlib (const MonoRuntimeInfo *runtime, MonoImageOpenStatus *status) MONO_INTERNAL;
455 const MonoRuntimeInfo*
456 mono_get_runtime_info (void) MONO_INTERNAL;
459 mono_runtime_set_no_exec (gboolean val) MONO_INTERNAL;
462 mono_runtime_get_no_exec (void) MONO_INTERNAL;
465 mono_assembly_name_parse (const char *name, MonoAssemblyName *aname) MONO_INTERNAL;
468 mono_assembly_name_free (MonoAssemblyName *aname) MONO_INTERNAL;
470 MonoImage *mono_assembly_open_from_bundle (const char *filename,
471 MonoImageOpenStatus *status,
472 gboolean refonly) MONO_INTERNAL;
475 mono_domain_add_class_static_data (MonoDomain *domain, MonoClass *klass, gpointer data, guint32 *bitmap);
477 MonoReflectionAssembly *
478 mono_try_assembly_resolve (MonoDomain *domain, MonoString *fname, gboolean refonly) MONO_INTERNAL;
480 MonoAssembly* mono_assembly_load_full_nosearch (MonoAssemblyName *aname,
482 MonoImageOpenStatus *status,
483 gboolean refonly) MONO_INTERNAL;
485 void mono_set_private_bin_path_from_config (MonoDomain *domain) MONO_INTERNAL;
487 int mono_framework_version (void) MONO_INTERNAL;
489 #endif /* __MONO_METADATA_DOMAIN_INTERNALS_H__ */