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;
15 extern CRITICAL_SECTION mono_strtod_mutex;
18 * If this is set, the memory belonging to appdomains is not freed when a domain is
19 * unloaded, and assemblies loaded by the appdomain are not unloaded either. This
20 * allows us to use typed gc in non-default appdomains too, leading to increased
23 extern gboolean mono_dont_free_domains;
25 /* This is a copy of System.AppDomainSetup */
28 MonoString *application_base;
29 MonoString *application_name;
30 MonoString *cache_path;
31 MonoString *configuration_file;
32 MonoString *dynamic_base;
33 MonoString *license_file;
34 MonoString *private_bin_path;
35 MonoString *private_bin_path_probe;
36 MonoString *shadow_copy_directories;
37 MonoString *shadow_copy_files;
38 MonoBoolean publisher_policy;
39 MonoBoolean path_changed;
40 int loader_optimization;
41 MonoBoolean disallow_binding_redirects;
42 MonoBoolean disallow_code_downloads;
43 MonoObject *activation_arguments; /* it is System.Object in 1.x, ActivationArguments in 2.0 */
44 MonoObject *domain_initializer;
45 MonoArray *domain_initializer_args;
46 MonoObject *application_trust; /* it is System.Object in 1.x, ApplicationTrust in 2.0 */
47 MonoBoolean disallow_appbase_probe;
48 MonoArray *configuration_bytes;
51 typedef struct _MonoJitInfoTable MonoJitInfoTable;
52 typedef struct _MonoJitInfoTableChunk MonoJitInfoTableChunk;
54 #define MONO_JIT_INFO_TABLE_CHUNK_SIZE 64
56 struct _MonoJitInfoTableChunk
59 volatile int num_elements;
60 volatile gint8 *last_code_end;
61 MonoJitInfo * volatile data [MONO_JIT_INFO_TABLE_CHUNK_SIZE];
64 struct _MonoJitInfoTable
68 MonoJitInfoTableChunk *chunks [MONO_ZERO_LEN_ARRAY];
71 typedef GArray MonoAotModuleInfoTable;
78 gpointer handler_start;
80 MonoClass *catch_class;
83 } MonoJitExceptionInfo;
86 * Will contain information on the generic type arguments in the
87 * future. For now, all arguments are always reference types.
91 } MonoGenericSharingContext;
95 MonoGenericSharingContext *generic_sharing_context;
99 gboolean this_in_reg:1;
100 } MonoGenericJitInfo;
102 struct _MonoJitInfo {
103 /* NOTE: These first two elements (method and
104 next_jit_code_hash) must be in the same order and at the
105 same offset as in RuntimeMethod, because of the jit_code_hash
106 internal hash table in MonoDomain. */
108 struct _MonoJitInfo *next_jit_code_hash;
112 guint32 num_clauses:16;
113 /* Whenever the code is domain neutral or 'shared' */
114 gboolean domain_neutral:1;
115 gboolean cas_inited:1;
116 gboolean cas_class_assert:1;
117 gboolean cas_class_deny:1;
118 gboolean cas_class_permitonly:1;
119 gboolean cas_method_assert:1;
120 gboolean cas_method_deny:1;
121 gboolean cas_method_permitonly:1;
122 gboolean has_generic_jit_info:1;
123 MonoJitExceptionInfo clauses [MONO_ZERO_LEN_ARRAY];
124 /* There is an optional MonoGenericJitInfo after the clauses */
127 struct _MonoAppContext {
131 gpointer *static_data;
135 MONO_APPDOMAIN_CREATED,
136 MONO_APPDOMAIN_UNLOADING,
137 MONO_APPDOMAIN_UNLOADED
138 } MonoAppDomainState;
140 typedef struct _MonoThunkFreeList {
142 int length; /* only valid for the wait list */
143 struct _MonoThunkFreeList *next;
146 typedef struct _MonoJitCodeHash MonoJitCodeHash;
149 CRITICAL_SECTION lock;
151 MonoCodeManager *code_mp;
153 * keep all the managed objects close to each other for the precise GC
154 * For the Boehm GC we additionally keep close also other GC-tracked pointers.
156 #define MONO_DOMAIN_FIRST_OBJECT setup
157 MonoAppDomainSetup *setup;
158 MonoAppDomain *domain;
159 MonoAppContext *default_context;
160 MonoException *out_of_memory_ex;
161 MonoException *null_reference_ex;
162 MonoException *stack_overflow_ex;
163 #define MONO_DOMAIN_FIRST_GC_TRACKED env
165 MonoGHashTable *ldstr_table;
166 /* hashtables for Reflection handles */
167 MonoGHashTable *type_hash;
168 MonoGHashTable *refobject_hash;
169 /* a GC-tracked array to keep references to the static fields of types */
170 gpointer *static_data_array;
171 /* maps class -> type initialization exception object */
172 MonoGHashTable *type_init_exception_hash;
173 /* maps delegate trampoline addr -> delegate object */
174 MonoGHashTable *delegate_hash_table;
176 MonoObject *typeof_void;
177 #define MONO_DOMAIN_LAST_GC_TRACKED typeof_void
179 /* Needed by Thread:GetDomainID() */
181 gint32 shadow_serial;
182 unsigned char inet_family_hint; // used in socket-io.c as a cache
183 GSList *domain_assemblies;
184 MonoAssembly *entry_assembly;
186 GHashTable *class_vtable_hash;
187 /* maps remote class key -> MonoRemoteClass */
188 GHashTable *proxy_vtable_hash;
189 /* Protected by 'jit_code_hash_lock' */
190 MonoInternalHashTable jit_code_hash;
191 CRITICAL_SECTION jit_code_hash_lock;
192 int num_jit_info_tables;
194 volatile jit_info_table;
195 GSList *jit_info_free_queue;
196 /* Used when loading assemblies */
198 gchar *private_bin_path;
200 /* Used by remoting proxies */
201 MonoMethod *create_proxy_for_type_method;
202 MonoMethod *private_invoke_method;
203 /* Used to store offsets of thread and context static fields */
204 GHashTable *special_static_fields;
206 * This must be a GHashTable, since these objects can't be finalized
207 * if the hashtable contains a GC visible reference to them.
209 GHashTable *finalizable_objects_hash;
210 /* Used when accessing 'domain_assemblies' */
211 CRITICAL_SECTION assemblies_lock;
213 GHashTable *shared_generics_hash;
214 GHashTable *method_rgctx_hash;
216 GHashTable *generic_virtual_cases;
217 MonoThunkFreeList **thunk_free_lists;
219 /* Information maintained by the JIT engine */
220 gpointer runtime_info;
222 /*thread pool jobs, used to coordinate shutdown.*/
224 HANDLE cleanup_semaphore;
228 guint16 major, minor, build, revision;
229 } AssemblyVersionSet;
231 /* MonoRuntimeInfo: Contains information about versions supported by this runtime */
233 const char runtime_version [12];
234 const char framework_version [4];
235 const AssemblyVersionSet version_sets [2];
238 #define mono_domain_lock(domain) EnterCriticalSection(&(domain)->lock)
239 #define mono_domain_unlock(domain) LeaveCriticalSection(&(domain)->lock)
240 #define mono_domain_assemblies_lock(domain) EnterCriticalSection(&(domain)->assemblies_lock)
241 #define mono_domain_assemblies_unlock(domain) LeaveCriticalSection(&(domain)->assemblies_lock)
242 #define mono_domain_jit_code_hash_lock(domain) EnterCriticalSection(&(domain)->jit_code_hash_lock)
243 #define mono_domain_jit_code_hash_unlock(domain) LeaveCriticalSection(&(domain)->jit_code_hash_lock)
245 typedef MonoDomain* (*MonoLoadFunc) (const char *filename, const char *runtime_version);
248 mono_install_runtime_load (MonoLoadFunc func) MONO_INTERNAL;
251 mono_runtime_load (const char *filename, const char *runtime_version) MONO_INTERNAL;
253 typedef void (*MonoCreateDomainFunc) (MonoDomain *domain);
256 mono_install_create_domain_hook (MonoCreateDomainFunc func) MONO_INTERNAL;
258 typedef void (*MonoFreeDomainFunc) (MonoDomain *domain);
261 mono_install_free_domain_hook (MonoFreeDomainFunc func) MONO_INTERNAL;
264 mono_init_com_types (void) MONO_INTERNAL;
267 mono_cleanup (void) MONO_INTERNAL;
270 mono_close_exe_image (void) MONO_INTERNAL;
273 mono_jit_info_table_add (MonoDomain *domain, MonoJitInfo *ji) MONO_INTERNAL;
276 mono_jit_info_table_remove (MonoDomain *domain, MonoJitInfo *ji) MONO_INTERNAL;
279 mono_jit_info_add_aot_module (MonoImage *image, gpointer start, gpointer end) MONO_INTERNAL;
282 mono_jit_info_get_generic_jit_info (MonoJitInfo *ji) MONO_INTERNAL;
284 MonoGenericSharingContext*
285 mono_jit_info_get_generic_sharing_context (MonoJitInfo *ji) MONO_INTERNAL;
288 mono_jit_info_set_generic_sharing_context (MonoJitInfo *ji, MonoGenericSharingContext *gsctx) MONO_INTERNAL;
291 mono_domain_lookup_shared_generic (MonoDomain *domain, MonoMethod *method) MONO_INTERNAL;
294 mono_domain_register_shared_generic (MonoDomain *domain, MonoMethod *method, MonoJitInfo *jit_info) MONO_INTERNAL;
297 mono_make_shadow_copy (const char *filename) MONO_INTERNAL;
300 mono_is_shadow_copy_enabled (MonoDomain *domain, const gchar *dir_name) MONO_INTERNAL;
303 mono_domain_alloc (MonoDomain *domain, guint size) MONO_INTERNAL;
306 mono_domain_alloc0 (MonoDomain *domain, guint size) MONO_INTERNAL;
309 * Installs a new function which is used to return a MonoJitInfo for a method inside
312 typedef MonoJitInfo *(*MonoJitInfoFindInAot) (MonoDomain *domain, MonoImage *image, gpointer addr);
313 void mono_install_jit_info_find_in_aot (MonoJitInfoFindInAot func) MONO_INTERNAL;
316 mono_jit_code_hash_init (MonoInternalHashTable *jit_code_hash) MONO_INTERNAL;
319 ves_icall_System_AppDomain_getCurDomain (void) MONO_INTERNAL;
322 ves_icall_System_AppDomain_getRootDomain (void) MONO_INTERNAL;
325 ves_icall_System_AppDomain_createDomain (MonoString *friendly_name,
326 MonoAppDomainSetup *setup) MONO_INTERNAL;
329 ves_icall_System_AppDomain_GetData (MonoAppDomain *ad,
330 MonoString *name) MONO_INTERNAL;
332 MonoReflectionAssembly *
333 ves_icall_System_AppDomain_LoadAssemblyRaw (MonoAppDomain *ad,
334 MonoArray *raw_assembly,
335 MonoArray *raw_symbol_store,
336 MonoObject *evidence,
337 MonoBoolean refonly) MONO_INTERNAL;
340 ves_icall_System_AppDomain_SetData (MonoAppDomain *ad,
342 MonoObject *data) MONO_INTERNAL;
345 ves_icall_System_AppDomain_getSetup (MonoAppDomain *ad) MONO_INTERNAL;
348 ves_icall_System_AppDomain_getFriendlyName (MonoAppDomain *ad) MONO_INTERNAL;
351 ves_icall_System_AppDomain_GetAssemblies (MonoAppDomain *ad,
352 MonoBoolean refonly) MONO_INTERNAL;
354 MonoReflectionAssembly *
355 ves_icall_System_Reflection_Assembly_LoadFrom (MonoString *fname,
356 MonoBoolean refonly) MONO_INTERNAL;
358 MonoReflectionAssembly *
359 ves_icall_System_AppDomain_LoadAssembly (MonoAppDomain *ad,
361 MonoObject *evidence,
362 MonoBoolean refonly) MONO_INTERNAL;
365 ves_icall_System_AppDomain_InternalIsFinalizingForUnload (gint32 domain_id) MONO_INTERNAL;
368 ves_icall_System_AppDomain_InternalUnload (gint32 domain_id) MONO_INTERNAL;
371 ves_icall_System_AppDomain_ExecuteAssembly (MonoAppDomain *ad,
372 MonoReflectionAssembly *refass,
373 MonoArray *args) MONO_INTERNAL;
376 ves_icall_System_AppDomain_InternalSetDomain (MonoAppDomain *ad) MONO_INTERNAL;
379 ves_icall_System_AppDomain_InternalSetDomainByID (gint32 domainid) MONO_INTERNAL;
382 ves_icall_System_AppDomain_InternalPushDomainRef (MonoAppDomain *ad) MONO_INTERNAL;
385 ves_icall_System_AppDomain_InternalPushDomainRefByID (gint32 domain_id) MONO_INTERNAL;
388 ves_icall_System_AppDomain_InternalPopDomainRef (void) MONO_INTERNAL;
391 ves_icall_System_AppDomain_InternalGetContext (void) MONO_INTERNAL;
394 ves_icall_System_AppDomain_InternalGetDefaultContext (void) MONO_INTERNAL;
397 ves_icall_System_AppDomain_InternalSetContext (MonoAppContext *mc) MONO_INTERNAL;
400 ves_icall_System_AppDomain_GetIDFromDomain (MonoAppDomain * ad) MONO_INTERNAL;
403 ves_icall_System_AppDomain_InternalGetProcessGuid (MonoString* newguid) MONO_INTERNAL;
406 mono_assembly_load_corlib (const MonoRuntimeInfo *runtime, MonoImageOpenStatus *status) MONO_INTERNAL;
408 const MonoRuntimeInfo*
409 mono_get_runtime_info (void) MONO_INTERNAL;
412 mono_runtime_set_no_exec (gboolean val) MONO_INTERNAL;
415 mono_runtime_get_no_exec (void) MONO_INTERNAL;
418 mono_assembly_name_parse (const char *name, MonoAssemblyName *aname) MONO_INTERNAL;
421 mono_assembly_name_free (MonoAssemblyName *aname) MONO_INTERNAL;
423 MonoImage *mono_assembly_open_from_bundle (const char *filename,
424 MonoImageOpenStatus *status,
425 gboolean refonly) MONO_INTERNAL;
428 mono_domain_add_class_static_data (MonoDomain *domain, MonoClass *klass, gpointer data, guint32 *bitmap);
430 MonoReflectionAssembly *
431 mono_try_assembly_resolve (MonoDomain *domain, MonoString *fname, gboolean refonly) MONO_INTERNAL;
433 MonoAssembly* mono_assembly_load_full_nosearch (MonoAssemblyName *aname,
435 MonoImageOpenStatus *status,
436 gboolean refonly) MONO_INTERNAL;
438 void mono_set_private_bin_path_from_config (MonoDomain *domain) MONO_INTERNAL;
440 int mono_framework_version (void) MONO_INTERNAL;
442 #endif /* __MONO_METADATA_DOMAIN_INTERNALS_H__ */