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/utils/mono-codeman.h>
9 #include <mono/utils/mono-hash.h>
10 #include <mono/utils/mono-compiler.h>
11 #include <mono/utils/mono-internal-hash.h>
12 #include <mono/io-layer/io-layer.h>
14 extern CRITICAL_SECTION mono_delegate_section;
17 * If this is set, the memory belonging to appdomains is not freed when a domain is
18 * unloaded, and assemblies loaded by the appdomain are not unloaded either. This
19 * allows us to use typed gc in non-default appdomains too, leading to increased
22 extern gboolean mono_dont_free_domains;
24 /* This is a copy of System.AppDomainSetup */
27 MonoString *application_base;
28 MonoString *application_name;
29 MonoString *cache_path;
30 MonoString *configuration_file;
31 MonoString *dynamic_base;
32 MonoString *license_file;
33 MonoString *private_bin_path;
34 MonoString *private_bin_path_probe;
35 MonoString *shadow_copy_directories;
36 MonoString *shadow_copy_files;
37 MonoBoolean publisher_policy;
38 MonoBoolean path_changed;
39 int loader_optimization;
40 MonoBoolean disallow_binding_redirects;
41 MonoBoolean disallow_code_downloads;
42 MonoObject *activation_arguments; /* it is System.Object in 1.x, ActivationArguments in 2.0 */
43 MonoObject *domain_initializer;
44 MonoArray *domain_initializer_args;
45 MonoObject *application_trust; /* it is System.Object in 1.x, ApplicationTrust in 2.0 */
46 MonoBoolean disallow_appbase_probe;
47 MonoArray *configuration_bytes;
50 typedef struct _MonoJitInfoTable MonoJitInfoTable;
51 typedef struct _MonoJitInfoTableChunk MonoJitInfoTableChunk;
53 #define MONO_JIT_INFO_TABLE_CHUNK_SIZE 64
55 struct _MonoJitInfoTableChunk
58 volatile int num_elements;
59 volatile gint8 *last_code_end;
60 MonoJitInfo * volatile data [MONO_JIT_INFO_TABLE_CHUNK_SIZE];
63 struct _MonoJitInfoTable
67 MonoJitInfoTableChunk *chunks [MONO_ZERO_LEN_ARRAY];
70 typedef GArray MonoAotModuleInfoTable;
77 gpointer handler_start;
79 MonoClass *catch_class;
82 } MonoJitExceptionInfo;
85 * Will contain information on the generic type arguments in the
86 * future. For now, all arguments are always reference types.
90 } MonoGenericSharingContext;
94 MonoGenericSharingContext *generic_sharing_context;
98 gboolean this_in_reg:1;
101 struct _MonoJitInfo {
102 /* NOTE: These first two elements (method and
103 next_jit_code_hash) must be in the same order and at the
104 same offset as in RuntimeMethod, because of the jit_code_hash
105 internal hash table in MonoDomain. */
107 struct _MonoJitInfo *next_jit_code_hash;
111 guint32 num_clauses:16;
112 /* Whenever the code is domain neutral or 'shared' */
113 gboolean domain_neutral:1;
114 gboolean cas_inited:1;
115 gboolean cas_class_assert:1;
116 gboolean cas_class_deny:1;
117 gboolean cas_class_permitonly:1;
118 gboolean cas_method_assert:1;
119 gboolean cas_method_deny:1;
120 gboolean cas_method_permitonly:1;
121 gboolean has_generic_jit_info:1;
122 MonoJitExceptionInfo clauses [MONO_ZERO_LEN_ARRAY];
123 /* There is an optional MonoGenericJitInfo after the clauses */
126 struct _MonoAppContext {
130 gpointer *static_data;
134 * We have two unloading states because the domain
135 * must remain fully functional while AppDomain::DomainUnload is
137 * After that unloading began and all domain facilities are teared down
138 * such as execution of new threadpool jobs.
141 MONO_APPDOMAIN_CREATED,
142 MONO_APPDOMAIN_UNLOADING_START,
143 MONO_APPDOMAIN_UNLOADING,
144 MONO_APPDOMAIN_UNLOADED
145 } MonoAppDomainState;
147 typedef struct _MonoThunkFreeList {
149 int length; /* only valid for the wait list */
150 struct _MonoThunkFreeList *next;
153 typedef struct _MonoJitCodeHash MonoJitCodeHash;
157 * This lock must never be taken before the loader lock,
158 * i.e. if both are taken by the same thread, the loader lock
161 CRITICAL_SECTION lock;
163 MonoCodeManager *code_mp;
165 * keep all the managed objects close to each other for the precise GC
166 * For the Boehm GC we additionally keep close also other GC-tracked pointers.
168 #define MONO_DOMAIN_FIRST_OBJECT setup
169 MonoAppDomainSetup *setup;
170 MonoAppDomain *domain;
171 MonoAppContext *default_context;
172 MonoException *out_of_memory_ex;
173 MonoException *null_reference_ex;
174 MonoException *stack_overflow_ex;
175 #define MONO_DOMAIN_FIRST_GC_TRACKED env
177 MonoGHashTable *ldstr_table;
178 /* hashtables for Reflection handles */
179 MonoGHashTable *type_hash;
180 MonoGHashTable *refobject_hash;
181 /* a GC-tracked array to keep references to the static fields of types */
182 gpointer *static_data_array;
183 /* maps class -> type initialization exception object */
184 MonoGHashTable *type_init_exception_hash;
185 /* maps delegate trampoline addr -> delegate object */
186 MonoGHashTable *delegate_hash_table;
187 #define MONO_DOMAIN_LAST_GC_TRACKED delegate_hash_table
189 /* Needed by Thread:GetDomainID() */
191 gint32 shadow_serial;
192 unsigned char inet_family_hint; // used in socket-io.c as a cache
193 GSList *domain_assemblies;
194 MonoAssembly *entry_assembly;
196 GHashTable *class_vtable_hash;
197 /* maps remote class key -> MonoRemoteClass */
198 GHashTable *proxy_vtable_hash;
199 /* Protected by 'jit_code_hash_lock' */
200 MonoInternalHashTable jit_code_hash;
201 CRITICAL_SECTION jit_code_hash_lock;
202 int num_jit_info_tables;
204 volatile jit_info_table;
205 GSList *jit_info_free_queue;
206 /* Used when loading assemblies */
208 gchar *private_bin_path;
210 /* Used by remoting proxies */
211 MonoMethod *create_proxy_for_type_method;
212 MonoMethod *private_invoke_method;
213 /* Used to store offsets of thread and context static fields */
214 GHashTable *special_static_fields;
216 * This must be a GHashTable, since these objects can't be finalized
217 * if the hashtable contains a GC visible reference to them.
219 GHashTable *finalizable_objects_hash;
220 /* Used when accessing 'domain_assemblies' */
221 CRITICAL_SECTION assemblies_lock;
223 GHashTable *shared_generics_hash;
224 GHashTable *method_rgctx_hash;
226 GHashTable *generic_virtual_cases;
227 MonoThunkFreeList **thunk_free_lists;
229 /* Information maintained by the JIT engine */
230 gpointer runtime_info;
232 /*thread pool jobs, used to coordinate shutdown.*/
234 HANDLE cleanup_semaphore;
238 guint16 major, minor, build, revision;
239 } AssemblyVersionSet;
241 /* MonoRuntimeInfo: Contains information about versions supported by this runtime */
243 const char runtime_version [12];
244 const char framework_version [4];
245 const AssemblyVersionSet version_sets [2];
248 #define mono_domain_lock(domain) EnterCriticalSection(&(domain)->lock)
249 #define mono_domain_unlock(domain) LeaveCriticalSection(&(domain)->lock)
250 #define mono_domain_assemblies_lock(domain) EnterCriticalSection(&(domain)->assemblies_lock)
251 #define mono_domain_assemblies_unlock(domain) LeaveCriticalSection(&(domain)->assemblies_lock)
252 #define mono_domain_jit_code_hash_lock(domain) EnterCriticalSection(&(domain)->jit_code_hash_lock)
253 #define mono_domain_jit_code_hash_unlock(domain) LeaveCriticalSection(&(domain)->jit_code_hash_lock)
255 typedef MonoDomain* (*MonoLoadFunc) (const char *filename, const char *runtime_version);
258 mono_install_runtime_load (MonoLoadFunc func) MONO_INTERNAL;
261 mono_runtime_load (const char *filename, const char *runtime_version) MONO_INTERNAL;
263 typedef void (*MonoCreateDomainFunc) (MonoDomain *domain);
266 mono_install_create_domain_hook (MonoCreateDomainFunc func) MONO_INTERNAL;
268 typedef void (*MonoFreeDomainFunc) (MonoDomain *domain);
271 mono_install_free_domain_hook (MonoFreeDomainFunc func) MONO_INTERNAL;
274 mono_init_com_types (void) MONO_INTERNAL;
277 mono_cleanup (void) MONO_INTERNAL;
280 mono_close_exe_image (void) MONO_INTERNAL;
283 mono_jit_info_table_add (MonoDomain *domain, MonoJitInfo *ji) MONO_INTERNAL;
286 mono_jit_info_table_remove (MonoDomain *domain, MonoJitInfo *ji) MONO_INTERNAL;
289 mono_jit_info_add_aot_module (MonoImage *image, gpointer start, gpointer end) MONO_INTERNAL;
292 mono_jit_info_get_generic_jit_info (MonoJitInfo *ji) MONO_INTERNAL;
294 MonoGenericSharingContext*
295 mono_jit_info_get_generic_sharing_context (MonoJitInfo *ji) MONO_INTERNAL;
298 mono_jit_info_set_generic_sharing_context (MonoJitInfo *ji, MonoGenericSharingContext *gsctx) MONO_INTERNAL;
301 mono_domain_lookup_shared_generic (MonoDomain *domain, MonoMethod *method) MONO_INTERNAL;
304 mono_domain_register_shared_generic (MonoDomain *domain, MonoMethod *method, MonoJitInfo *jit_info) MONO_INTERNAL;
307 mono_make_shadow_copy (const char *filename) MONO_INTERNAL;
310 mono_is_shadow_copy_enabled (MonoDomain *domain, const gchar *dir_name) MONO_INTERNAL;
313 mono_domain_alloc (MonoDomain *domain, guint size) MONO_INTERNAL;
316 mono_domain_alloc0 (MonoDomain *domain, guint size) MONO_INTERNAL;
319 * Installs a new function which is used to return a MonoJitInfo for a method inside
322 typedef MonoJitInfo *(*MonoJitInfoFindInAot) (MonoDomain *domain, MonoImage *image, gpointer addr);
323 void mono_install_jit_info_find_in_aot (MonoJitInfoFindInAot func) MONO_INTERNAL;
326 mono_jit_code_hash_init (MonoInternalHashTable *jit_code_hash) MONO_INTERNAL;
329 ves_icall_System_AppDomain_getCurDomain (void) MONO_INTERNAL;
332 ves_icall_System_AppDomain_getRootDomain (void) MONO_INTERNAL;
335 ves_icall_System_AppDomain_createDomain (MonoString *friendly_name,
336 MonoAppDomainSetup *setup) MONO_INTERNAL;
339 ves_icall_System_AppDomain_GetData (MonoAppDomain *ad,
340 MonoString *name) MONO_INTERNAL;
342 MonoReflectionAssembly *
343 ves_icall_System_AppDomain_LoadAssemblyRaw (MonoAppDomain *ad,
344 MonoArray *raw_assembly,
345 MonoArray *raw_symbol_store,
346 MonoObject *evidence,
347 MonoBoolean refonly) MONO_INTERNAL;
350 ves_icall_System_AppDomain_SetData (MonoAppDomain *ad,
352 MonoObject *data) MONO_INTERNAL;
355 ves_icall_System_AppDomain_getSetup (MonoAppDomain *ad) MONO_INTERNAL;
358 ves_icall_System_AppDomain_getFriendlyName (MonoAppDomain *ad) MONO_INTERNAL;
361 ves_icall_System_AppDomain_GetAssemblies (MonoAppDomain *ad,
362 MonoBoolean refonly) MONO_INTERNAL;
364 MonoReflectionAssembly *
365 ves_icall_System_Reflection_Assembly_LoadFrom (MonoString *fname,
366 MonoBoolean refonly) MONO_INTERNAL;
368 MonoReflectionAssembly *
369 ves_icall_System_AppDomain_LoadAssembly (MonoAppDomain *ad,
371 MonoObject *evidence,
372 MonoBoolean refonly) MONO_INTERNAL;
375 ves_icall_System_AppDomain_InternalIsFinalizingForUnload (gint32 domain_id) MONO_INTERNAL;
378 ves_icall_System_AppDomain_InternalUnload (gint32 domain_id) MONO_INTERNAL;
381 ves_icall_System_AppDomain_ExecuteAssembly (MonoAppDomain *ad,
382 MonoReflectionAssembly *refass,
383 MonoArray *args) MONO_INTERNAL;
386 ves_icall_System_AppDomain_InternalSetDomain (MonoAppDomain *ad) MONO_INTERNAL;
389 ves_icall_System_AppDomain_InternalSetDomainByID (gint32 domainid) MONO_INTERNAL;
392 ves_icall_System_AppDomain_InternalPushDomainRef (MonoAppDomain *ad) MONO_INTERNAL;
395 ves_icall_System_AppDomain_InternalPushDomainRefByID (gint32 domain_id) MONO_INTERNAL;
398 ves_icall_System_AppDomain_InternalPopDomainRef (void) MONO_INTERNAL;
401 ves_icall_System_AppDomain_InternalGetContext (void) MONO_INTERNAL;
404 ves_icall_System_AppDomain_InternalGetDefaultContext (void) MONO_INTERNAL;
407 ves_icall_System_AppDomain_InternalSetContext (MonoAppContext *mc) MONO_INTERNAL;
410 ves_icall_System_AppDomain_GetIDFromDomain (MonoAppDomain * ad) MONO_INTERNAL;
413 ves_icall_System_AppDomain_InternalGetProcessGuid (MonoString* newguid) MONO_INTERNAL;
416 mono_assembly_load_corlib (const MonoRuntimeInfo *runtime, MonoImageOpenStatus *status) MONO_INTERNAL;
418 const MonoRuntimeInfo*
419 mono_get_runtime_info (void) MONO_INTERNAL;
422 mono_runtime_set_no_exec (gboolean val) MONO_INTERNAL;
425 mono_runtime_get_no_exec (void) MONO_INTERNAL;
428 mono_assembly_name_parse (const char *name, MonoAssemblyName *aname) MONO_INTERNAL;
431 mono_assembly_name_free (MonoAssemblyName *aname) MONO_INTERNAL;
433 MonoImage *mono_assembly_open_from_bundle (const char *filename,
434 MonoImageOpenStatus *status,
435 gboolean refonly) MONO_INTERNAL;
438 mono_domain_add_class_static_data (MonoDomain *domain, MonoClass *klass, gpointer data, guint32 *bitmap);
440 MonoReflectionAssembly *
441 mono_try_assembly_resolve (MonoDomain *domain, MonoString *fname, gboolean refonly) MONO_INTERNAL;
443 MonoAssembly* mono_assembly_load_full_nosearch (MonoAssemblyName *aname,
445 MonoImageOpenStatus *status,
446 gboolean refonly) MONO_INTERNAL;
448 void mono_set_private_bin_path_from_config (MonoDomain *domain) MONO_INTERNAL;
450 int mono_framework_version (void) MONO_INTERNAL;
452 #endif /* __MONO_METADATA_DOMAIN_INTERNALS_H__ */