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 MonoJitExceptionInfo clauses [MONO_ZERO_LEN_ARRAY];
127 /* There is an optional MonoGenericJitInfo after the clauses */
130 struct _MonoAppContext {
134 gpointer *static_data;
138 * We have two unloading states because the domain
139 * must remain fully functional while AppDomain::DomainUnload is
141 * After that unloading began and all domain facilities are teared down
142 * such as execution of new threadpool jobs.
145 MONO_APPDOMAIN_CREATED,
146 MONO_APPDOMAIN_UNLOADING_START,
147 MONO_APPDOMAIN_UNLOADING,
148 MONO_APPDOMAIN_UNLOADED
149 } MonoAppDomainState;
151 typedef struct _MonoThunkFreeList {
153 int length; /* only valid for the wait list */
154 struct _MonoThunkFreeList *next;
157 typedef struct _MonoJitCodeHash MonoJitCodeHash;
161 * This lock must never be taken before the loader lock,
162 * i.e. if both are taken by the same thread, the loader lock
165 CRITICAL_SECTION lock;
167 MonoCodeManager *code_mp;
169 * keep all the managed objects close to each other for the precise GC
170 * For the Boehm GC we additionally keep close also other GC-tracked pointers.
172 #define MONO_DOMAIN_FIRST_OBJECT setup
173 MonoAppDomainSetup *setup;
174 MonoAppDomain *domain;
175 MonoAppContext *default_context;
176 MonoException *out_of_memory_ex;
177 MonoException *null_reference_ex;
178 MonoException *stack_overflow_ex;
180 MonoObject *typeof_void;
182 * The fields between FIRST_GC_TRACKED and LAST_GC_TRACKED are roots, but
183 * not object references.
185 #define MONO_DOMAIN_FIRST_GC_TRACKED env
187 MonoGHashTable *ldstr_table;
188 /* hashtables for Reflection handles */
189 MonoGHashTable *type_hash;
190 MonoGHashTable *refobject_hash;
191 /* a GC-tracked array to keep references to the static fields of types */
192 gpointer *static_data_array;
193 /* maps class -> type initialization exception object */
194 MonoGHashTable *type_init_exception_hash;
195 /* maps delegate trampoline addr -> delegate object */
196 MonoGHashTable *delegate_hash_table;
197 #define MONO_DOMAIN_LAST_GC_TRACKED delegate_hash_table
199 /* Needed by Thread:GetDomainID() */
201 gint32 shadow_serial;
202 unsigned char inet_family_hint; // used in socket-io.c as a cache
203 GSList *domain_assemblies;
204 MonoAssembly *entry_assembly;
206 GHashTable *class_vtable_hash;
207 /* maps remote class key -> MonoRemoteClass */
208 GHashTable *proxy_vtable_hash;
209 /* Protected by 'jit_code_hash_lock' */
210 MonoInternalHashTable jit_code_hash;
211 CRITICAL_SECTION jit_code_hash_lock;
212 int num_jit_info_tables;
214 volatile jit_info_table;
215 GSList *jit_info_free_queue;
216 /* Used when loading assemblies */
218 gchar *private_bin_path;
220 /* Used by remoting proxies */
221 MonoMethod *create_proxy_for_type_method;
222 MonoMethod *private_invoke_method;
223 /* Used to store offsets of thread and context static fields */
224 GHashTable *special_static_fields;
226 * This must be a GHashTable, since these objects can't be finalized
227 * if the hashtable contains a GC visible reference to them.
229 GHashTable *finalizable_objects_hash;
230 /* Maps MonoObjects to a GSList of WeakTrackResurrection GCHandles pointing to them */
231 GHashTable *track_resurrection_objects_hash;
232 /* Maps WeakTrackResurrection GCHandles to the MonoObjects they point to */
233 GHashTable *track_resurrection_handles_hash;
234 /* Protects the three hashes above */
235 CRITICAL_SECTION finalizable_objects_hash_lock;
236 /* Used when accessing 'domain_assemblies' */
237 CRITICAL_SECTION assemblies_lock;
239 GHashTable *method_rgctx_hash;
241 GHashTable *generic_virtual_cases;
242 MonoThunkFreeList **thunk_free_lists;
244 /* Information maintained by the JIT engine */
245 gpointer runtime_info;
247 /*thread pool jobs, used to coordinate shutdown.*/
249 HANDLE cleanup_semaphore;
251 /* Contains the compiled runtime invoke wrapper used by finalizers */
252 gpointer finalize_runtime_invoke;
254 /* Contains the compiled runtime invoke wrapper used by async resylt creation to capture thread context*/
255 gpointer capture_context_runtime_invoke;
257 /* Contains the compiled method used by async resylt creation to capture thread context*/
258 gpointer capture_context_method;
262 guint16 major, minor, build, revision;
263 } AssemblyVersionSet;
265 /* MonoRuntimeInfo: Contains information about versions supported by this runtime */
267 const char runtime_version [12];
268 const char framework_version [4];
269 const AssemblyVersionSet version_sets [2];
272 #define mono_domain_lock(domain) mono_locks_acquire(&(domain)->lock, DomainLock)
273 #define mono_domain_unlock(domain) mono_locks_release(&(domain)->lock, DomainLock)
274 #define mono_domain_assemblies_lock(domain) mono_locks_acquire(&(domain)->assemblies_lock, DomainAssembliesLock)
275 #define mono_domain_assemblies_unlock(domain) mono_locks_release(&(domain)->assemblies_lock, DomainAssembliesLock)
276 #define mono_domain_jit_code_hash_lock(domain) mono_locks_acquire(&(domain)->jit_code_hash_lock, DomainJitCodeHashLock)
277 #define mono_domain_jit_code_hash_unlock(domain) mono_locks_release(&(domain)->jit_code_hash_lock, DomainJitCodeHashLock)
279 typedef MonoDomain* (*MonoLoadFunc) (const char *filename, const char *runtime_version);
282 mono_install_runtime_load (MonoLoadFunc func) MONO_INTERNAL;
285 mono_runtime_load (const char *filename, const char *runtime_version) MONO_INTERNAL;
287 typedef void (*MonoCreateDomainFunc) (MonoDomain *domain);
290 mono_install_create_domain_hook (MonoCreateDomainFunc func) MONO_INTERNAL;
292 typedef void (*MonoFreeDomainFunc) (MonoDomain *domain);
295 mono_install_free_domain_hook (MonoFreeDomainFunc func) MONO_INTERNAL;
298 mono_init_com_types (void) MONO_INTERNAL;
301 mono_cleanup (void) MONO_INTERNAL;
304 mono_close_exe_image (void) MONO_INTERNAL;
307 mono_jit_info_table_add (MonoDomain *domain, MonoJitInfo *ji) MONO_INTERNAL;
310 mono_jit_info_table_remove (MonoDomain *domain, MonoJitInfo *ji) MONO_INTERNAL;
313 mono_jit_info_add_aot_module (MonoImage *image, gpointer start, gpointer end) MONO_INTERNAL;
316 mono_jit_info_get_generic_jit_info (MonoJitInfo *ji) MONO_INTERNAL;
318 MonoGenericSharingContext*
319 mono_jit_info_get_generic_sharing_context (MonoJitInfo *ji) MONO_INTERNAL;
322 mono_jit_info_set_generic_sharing_context (MonoJitInfo *ji, MonoGenericSharingContext *gsctx) MONO_INTERNAL;
325 mono_domain_lookup_shared_generic (MonoDomain *domain, MonoMethod *method) MONO_INTERNAL;
328 mono_make_shadow_copy (const char *filename) MONO_INTERNAL;
331 mono_is_shadow_copy_enabled (MonoDomain *domain, const gchar *dir_name) MONO_INTERNAL;
334 mono_domain_alloc (MonoDomain *domain, guint size) MONO_INTERNAL;
337 mono_domain_alloc0 (MonoDomain *domain, guint size) MONO_INTERNAL;
340 mono_domain_code_reserve (MonoDomain *domain, int size) MONO_INTERNAL;
343 mono_domain_code_reserve_align (MonoDomain *domain, int size, int alignment) MONO_INTERNAL;
346 mono_domain_code_commit (MonoDomain *domain, void *data, int size, int newsize) MONO_INTERNAL;
349 mono_domain_code_foreach (MonoDomain *domain, MonoCodeManagerFunc func, void *user_data) MONO_INTERNAL;
352 * Installs a new function which is used to return a MonoJitInfo for a method inside
355 typedef MonoJitInfo *(*MonoJitInfoFindInAot) (MonoDomain *domain, MonoImage *image, gpointer addr);
356 void mono_install_jit_info_find_in_aot (MonoJitInfoFindInAot func) MONO_INTERNAL;
359 mono_jit_code_hash_init (MonoInternalHashTable *jit_code_hash) MONO_INTERNAL;
362 ves_icall_System_AppDomain_getCurDomain (void) MONO_INTERNAL;
365 ves_icall_System_AppDomain_getRootDomain (void) MONO_INTERNAL;
368 ves_icall_System_AppDomain_createDomain (MonoString *friendly_name,
369 MonoAppDomainSetup *setup) MONO_INTERNAL;
372 ves_icall_System_AppDomain_GetData (MonoAppDomain *ad,
373 MonoString *name) MONO_INTERNAL;
375 MonoReflectionAssembly *
376 ves_icall_System_AppDomain_LoadAssemblyRaw (MonoAppDomain *ad,
377 MonoArray *raw_assembly,
378 MonoArray *raw_symbol_store,
379 MonoObject *evidence,
380 MonoBoolean refonly) MONO_INTERNAL;
383 ves_icall_System_AppDomain_SetData (MonoAppDomain *ad,
385 MonoObject *data) MONO_INTERNAL;
388 ves_icall_System_AppDomain_getSetup (MonoAppDomain *ad) MONO_INTERNAL;
391 ves_icall_System_AppDomain_getFriendlyName (MonoAppDomain *ad) MONO_INTERNAL;
394 ves_icall_System_AppDomain_GetAssemblies (MonoAppDomain *ad,
395 MonoBoolean refonly) MONO_INTERNAL;
397 MonoReflectionAssembly *
398 ves_icall_System_Reflection_Assembly_LoadFrom (MonoString *fname,
399 MonoBoolean refonly) MONO_INTERNAL;
401 MonoReflectionAssembly *
402 ves_icall_System_AppDomain_LoadAssembly (MonoAppDomain *ad,
404 MonoObject *evidence,
405 MonoBoolean refonly) MONO_INTERNAL;
408 ves_icall_System_AppDomain_InternalIsFinalizingForUnload (gint32 domain_id) MONO_INTERNAL;
411 ves_icall_System_AppDomain_InternalUnload (gint32 domain_id) MONO_INTERNAL;
414 ves_icall_System_AppDomain_ExecuteAssembly (MonoAppDomain *ad,
415 MonoReflectionAssembly *refass,
416 MonoArray *args) MONO_INTERNAL;
419 ves_icall_System_AppDomain_InternalSetDomain (MonoAppDomain *ad) MONO_INTERNAL;
422 ves_icall_System_AppDomain_InternalSetDomainByID (gint32 domainid) MONO_INTERNAL;
425 ves_icall_System_AppDomain_InternalPushDomainRef (MonoAppDomain *ad) MONO_INTERNAL;
428 ves_icall_System_AppDomain_InternalPushDomainRefByID (gint32 domain_id) MONO_INTERNAL;
431 ves_icall_System_AppDomain_InternalPopDomainRef (void) MONO_INTERNAL;
434 ves_icall_System_AppDomain_InternalGetContext (void) MONO_INTERNAL;
437 ves_icall_System_AppDomain_InternalGetDefaultContext (void) MONO_INTERNAL;
440 ves_icall_System_AppDomain_InternalSetContext (MonoAppContext *mc) MONO_INTERNAL;
443 ves_icall_System_AppDomain_GetIDFromDomain (MonoAppDomain * ad) MONO_INTERNAL;
446 ves_icall_System_AppDomain_InternalGetProcessGuid (MonoString* newguid) MONO_INTERNAL;
449 mono_assembly_load_corlib (const MonoRuntimeInfo *runtime, MonoImageOpenStatus *status) MONO_INTERNAL;
451 const MonoRuntimeInfo*
452 mono_get_runtime_info (void) MONO_INTERNAL;
455 mono_runtime_set_no_exec (gboolean val) MONO_INTERNAL;
458 mono_runtime_get_no_exec (void) MONO_INTERNAL;
461 mono_assembly_name_parse (const char *name, MonoAssemblyName *aname) MONO_INTERNAL;
464 mono_assembly_name_free (MonoAssemblyName *aname) MONO_INTERNAL;
466 MonoImage *mono_assembly_open_from_bundle (const char *filename,
467 MonoImageOpenStatus *status,
468 gboolean refonly) MONO_INTERNAL;
471 mono_domain_add_class_static_data (MonoDomain *domain, MonoClass *klass, gpointer data, guint32 *bitmap);
473 MonoReflectionAssembly *
474 mono_try_assembly_resolve (MonoDomain *domain, MonoString *fname, gboolean refonly) MONO_INTERNAL;
476 MonoAssembly* mono_assembly_load_full_nosearch (MonoAssemblyName *aname,
478 MonoImageOpenStatus *status,
479 gboolean refonly) MONO_INTERNAL;
481 void mono_set_private_bin_path_from_config (MonoDomain *domain) MONO_INTERNAL;
483 int mono_framework_version (void) MONO_INTERNAL;
485 #endif /* __MONO_METADATA_DOMAIN_INTERNALS_H__ */