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 MONO_APPDOMAIN_CREATED,
135 MONO_APPDOMAIN_UNLOADING,
136 MONO_APPDOMAIN_UNLOADED
137 } MonoAppDomainState;
139 typedef struct _MonoThunkFreeList {
141 int length; /* only valid for the wait list */
142 struct _MonoThunkFreeList *next;
145 typedef struct _MonoJitCodeHash MonoJitCodeHash;
148 CRITICAL_SECTION lock;
150 MonoCodeManager *code_mp;
152 * keep all the managed objects close to each other for the precise GC
153 * For the Boehm GC we additionally keep close also other GC-tracked pointers.
155 #define MONO_DOMAIN_FIRST_OBJECT setup
156 MonoAppDomainSetup *setup;
157 MonoAppDomain *domain;
158 MonoAppContext *default_context;
159 MonoException *out_of_memory_ex;
160 MonoException *null_reference_ex;
161 MonoException *stack_overflow_ex;
162 #define MONO_DOMAIN_FIRST_GC_TRACKED env
164 MonoGHashTable *ldstr_table;
165 /* hashtables for Reflection handles */
166 MonoGHashTable *type_hash;
167 MonoGHashTable *refobject_hash;
168 /* a GC-tracked array to keep references to the static fields of types */
169 gpointer *static_data_array;
170 /* maps class -> type initialization exception object */
171 MonoGHashTable *type_init_exception_hash;
172 /* maps delegate trampoline addr -> delegate object */
173 MonoGHashTable *delegate_hash_table;
175 MonoObject *typeof_void;
176 #define MONO_DOMAIN_LAST_GC_TRACKED delegate_hash_table
178 /* Needed by Thread:GetDomainID() */
180 gint32 shadow_serial;
181 unsigned char inet_family_hint; // used in socket-io.c as a cache
182 GSList *domain_assemblies;
183 MonoAssembly *entry_assembly;
185 GHashTable *class_vtable_hash;
186 /* maps remote class key -> MonoRemoteClass */
187 GHashTable *proxy_vtable_hash;
188 /* Protected by 'jit_code_hash_lock' */
189 MonoInternalHashTable jit_code_hash;
190 CRITICAL_SECTION jit_code_hash_lock;
191 int num_jit_info_tables;
193 volatile jit_info_table;
194 GSList *jit_info_free_queue;
195 /* Used when loading assemblies */
197 gchar *private_bin_path;
199 /* Used by remoting proxies */
200 MonoMethod *create_proxy_for_type_method;
201 MonoMethod *private_invoke_method;
202 /* Used to store offsets of thread and context static fields */
203 GHashTable *special_static_fields;
205 * This must be a GHashTable, since these objects can't be finalized
206 * if the hashtable contains a GC visible reference to them.
208 GHashTable *finalizable_objects_hash;
209 /* Used when accessing 'domain_assemblies' */
210 CRITICAL_SECTION assemblies_lock;
212 GHashTable *shared_generics_hash;
213 GHashTable *method_rgctx_hash;
215 GHashTable *generic_virtual_cases;
216 MonoThunkFreeList **thunk_free_lists;
218 /* Information maintained by the JIT engine */
219 gpointer runtime_info;
221 /*thread pool jobs, used to coordinate shutdown.*/
223 HANDLE cleanup_semaphore;
227 guint16 major, minor, build, revision;
228 } AssemblyVersionSet;
230 /* MonoRuntimeInfo: Contains information about versions supported by this runtime */
232 const char runtime_version [12];
233 const char framework_version [4];
234 const AssemblyVersionSet version_sets [2];
237 #define mono_domain_lock(domain) EnterCriticalSection(&(domain)->lock)
238 #define mono_domain_unlock(domain) LeaveCriticalSection(&(domain)->lock)
239 #define mono_domain_assemblies_lock(domain) EnterCriticalSection(&(domain)->assemblies_lock)
240 #define mono_domain_assemblies_unlock(domain) LeaveCriticalSection(&(domain)->assemblies_lock)
241 #define mono_domain_jit_code_hash_lock(domain) EnterCriticalSection(&(domain)->jit_code_hash_lock)
242 #define mono_domain_jit_code_hash_unlock(domain) LeaveCriticalSection(&(domain)->jit_code_hash_lock)
244 typedef MonoDomain* (*MonoLoadFunc) (const char *filename, const char *runtime_version);
247 mono_install_runtime_load (MonoLoadFunc func) MONO_INTERNAL;
250 mono_runtime_load (const char *filename, const char *runtime_version) MONO_INTERNAL;
252 typedef void (*MonoCreateDomainFunc) (MonoDomain *domain);
255 mono_install_create_domain_hook (MonoCreateDomainFunc func) MONO_INTERNAL;
257 typedef void (*MonoFreeDomainFunc) (MonoDomain *domain);
260 mono_install_free_domain_hook (MonoFreeDomainFunc func) MONO_INTERNAL;
263 mono_init_com_types (void) MONO_INTERNAL;
266 mono_cleanup (void) MONO_INTERNAL;
269 mono_close_exe_image (void) MONO_INTERNAL;
272 mono_jit_info_table_add (MonoDomain *domain, MonoJitInfo *ji) MONO_INTERNAL;
275 mono_jit_info_table_remove (MonoDomain *domain, MonoJitInfo *ji) MONO_INTERNAL;
278 mono_jit_info_add_aot_module (MonoImage *image, gpointer start, gpointer end) MONO_INTERNAL;
281 mono_jit_info_get_generic_jit_info (MonoJitInfo *ji) MONO_INTERNAL;
283 MonoGenericSharingContext*
284 mono_jit_info_get_generic_sharing_context (MonoJitInfo *ji) MONO_INTERNAL;
287 mono_jit_info_set_generic_sharing_context (MonoJitInfo *ji, MonoGenericSharingContext *gsctx) MONO_INTERNAL;
290 mono_domain_lookup_shared_generic (MonoDomain *domain, MonoMethod *method) MONO_INTERNAL;
293 mono_domain_register_shared_generic (MonoDomain *domain, MonoMethod *method, MonoJitInfo *jit_info) MONO_INTERNAL;
296 mono_make_shadow_copy (const char *filename) MONO_INTERNAL;
299 mono_is_shadow_copy_enabled (MonoDomain *domain, const gchar *dir_name) MONO_INTERNAL;
302 mono_domain_alloc (MonoDomain *domain, guint size) MONO_INTERNAL;
305 mono_domain_alloc0 (MonoDomain *domain, guint size) MONO_INTERNAL;
308 * Installs a new function which is used to return a MonoJitInfo for a method inside
311 typedef MonoJitInfo *(*MonoJitInfoFindInAot) (MonoDomain *domain, MonoImage *image, gpointer addr);
312 void mono_install_jit_info_find_in_aot (MonoJitInfoFindInAot func) MONO_INTERNAL;
315 mono_jit_code_hash_init (MonoInternalHashTable *jit_code_hash) MONO_INTERNAL;
318 ves_icall_System_AppDomain_getCurDomain (void) MONO_INTERNAL;
321 ves_icall_System_AppDomain_getRootDomain (void) MONO_INTERNAL;
324 ves_icall_System_AppDomain_createDomain (MonoString *friendly_name,
325 MonoAppDomainSetup *setup) MONO_INTERNAL;
328 ves_icall_System_AppDomain_GetData (MonoAppDomain *ad,
329 MonoString *name) MONO_INTERNAL;
331 MonoReflectionAssembly *
332 ves_icall_System_AppDomain_LoadAssemblyRaw (MonoAppDomain *ad,
333 MonoArray *raw_assembly,
334 MonoArray *raw_symbol_store,
335 MonoObject *evidence,
336 MonoBoolean refonly) MONO_INTERNAL;
339 ves_icall_System_AppDomain_SetData (MonoAppDomain *ad,
341 MonoObject *data) MONO_INTERNAL;
344 ves_icall_System_AppDomain_getSetup (MonoAppDomain *ad) MONO_INTERNAL;
347 ves_icall_System_AppDomain_getFriendlyName (MonoAppDomain *ad) MONO_INTERNAL;
350 ves_icall_System_AppDomain_GetAssemblies (MonoAppDomain *ad,
351 MonoBoolean refonly) MONO_INTERNAL;
353 MonoReflectionAssembly *
354 ves_icall_System_Reflection_Assembly_LoadFrom (MonoString *fname,
355 MonoBoolean refonly) MONO_INTERNAL;
357 MonoReflectionAssembly *
358 ves_icall_System_AppDomain_LoadAssembly (MonoAppDomain *ad,
360 MonoObject *evidence,
361 MonoBoolean refonly) MONO_INTERNAL;
364 ves_icall_System_AppDomain_InternalIsFinalizingForUnload (gint32 domain_id) MONO_INTERNAL;
367 ves_icall_System_AppDomain_InternalUnload (gint32 domain_id) MONO_INTERNAL;
370 ves_icall_System_AppDomain_ExecuteAssembly (MonoAppDomain *ad,
371 MonoReflectionAssembly *refass,
372 MonoArray *args) MONO_INTERNAL;
375 ves_icall_System_AppDomain_InternalSetDomain (MonoAppDomain *ad) MONO_INTERNAL;
378 ves_icall_System_AppDomain_InternalSetDomainByID (gint32 domainid) MONO_INTERNAL;
381 ves_icall_System_AppDomain_InternalPushDomainRef (MonoAppDomain *ad) MONO_INTERNAL;
384 ves_icall_System_AppDomain_InternalPushDomainRefByID (gint32 domain_id) MONO_INTERNAL;
387 ves_icall_System_AppDomain_InternalPopDomainRef (void) MONO_INTERNAL;
390 ves_icall_System_AppDomain_InternalGetContext (void) MONO_INTERNAL;
393 ves_icall_System_AppDomain_InternalGetDefaultContext (void) MONO_INTERNAL;
396 ves_icall_System_AppDomain_InternalSetContext (MonoAppContext *mc) MONO_INTERNAL;
399 ves_icall_System_AppDomain_GetIDFromDomain (MonoAppDomain * ad) MONO_INTERNAL;
402 ves_icall_System_AppDomain_InternalGetProcessGuid (MonoString* newguid) MONO_INTERNAL;
405 mono_assembly_load_corlib (const MonoRuntimeInfo *runtime, MonoImageOpenStatus *status) MONO_INTERNAL;
407 const MonoRuntimeInfo*
408 mono_get_runtime_info (void) MONO_INTERNAL;
411 mono_runtime_set_no_exec (gboolean val) MONO_INTERNAL;
414 mono_runtime_get_no_exec (void) MONO_INTERNAL;
417 mono_assembly_name_parse (const char *name, MonoAssemblyName *aname) MONO_INTERNAL;
420 mono_assembly_name_free (MonoAssemblyName *aname) MONO_INTERNAL;
422 MonoImage *mono_assembly_open_from_bundle (const char *filename,
423 MonoImageOpenStatus *status,
424 gboolean refonly) MONO_INTERNAL;
427 mono_domain_add_class_static_data (MonoDomain *domain, MonoClass *klass, gpointer data, guint32 *bitmap);
429 MonoReflectionAssembly *
430 mono_try_assembly_resolve (MonoDomain *domain, MonoString *fname, gboolean refonly) MONO_INTERNAL;
432 MonoAssembly* mono_assembly_load_full_nosearch (MonoAssemblyName *aname,
434 MonoImageOpenStatus *status,
435 gboolean refonly) MONO_INTERNAL;
437 void mono_set_private_bin_path_from_config (MonoDomain *domain) MONO_INTERNAL;
439 int mono_framework_version (void) MONO_INTERNAL;
441 #endif /* __MONO_METADATA_DOMAIN_INTERNALS_H__ */