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;
174 #define MONO_DOMAIN_LAST_GC_TRACKED delegate_hash_table
176 /* Needed by Thread:GetDomainID() */
178 gint32 shadow_serial;
179 unsigned char inet_family_hint; // used in socket-io.c as a cache
180 GSList *domain_assemblies;
181 MonoAssembly *entry_assembly;
183 GHashTable *class_vtable_hash;
184 /* maps remote class key -> MonoRemoteClass */
185 GHashTable *proxy_vtable_hash;
186 /* Protected by 'jit_code_hash_lock' */
187 MonoInternalHashTable jit_code_hash;
188 CRITICAL_SECTION jit_code_hash_lock;
189 int num_jit_info_tables;
191 volatile jit_info_table;
192 GSList *jit_info_free_queue;
193 /* Used when loading assemblies */
195 gchar *private_bin_path;
197 /* Used by remoting proxies */
198 MonoMethod *create_proxy_for_type_method;
199 MonoMethod *private_invoke_method;
200 /* Used to store offsets of thread and context static fields */
201 GHashTable *special_static_fields;
203 * This must be a GHashTable, since these objects can't be finalized
204 * if the hashtable contains a GC visible reference to them.
206 GHashTable *finalizable_objects_hash;
207 /* Used when accessing 'domain_assemblies' */
208 CRITICAL_SECTION assemblies_lock;
210 GHashTable *shared_generics_hash;
211 GHashTable *method_rgctx_hash;
213 GHashTable *generic_virtual_cases;
214 MonoThunkFreeList **thunk_free_lists;
216 /* Information maintained by the JIT engine */
217 gpointer runtime_info;
221 guint16 major, minor, build, revision;
222 } AssemblyVersionSet;
224 /* MonoRuntimeInfo: Contains information about versions supported by this runtime */
226 const char runtime_version [12];
227 const char framework_version [4];
228 const AssemblyVersionSet version_sets [2];
231 #define mono_domain_lock(domain) EnterCriticalSection(&(domain)->lock)
232 #define mono_domain_unlock(domain) LeaveCriticalSection(&(domain)->lock)
233 #define mono_domain_assemblies_lock(domain) EnterCriticalSection(&(domain)->assemblies_lock)
234 #define mono_domain_assemblies_unlock(domain) LeaveCriticalSection(&(domain)->assemblies_lock)
235 #define mono_domain_jit_code_hash_lock(domain) EnterCriticalSection(&(domain)->jit_code_hash_lock)
236 #define mono_domain_jit_code_hash_unlock(domain) LeaveCriticalSection(&(domain)->jit_code_hash_lock)
238 typedef MonoDomain* (*MonoLoadFunc) (const char *filename, const char *runtime_version);
241 mono_install_runtime_load (MonoLoadFunc func) MONO_INTERNAL;
244 mono_runtime_load (const char *filename, const char *runtime_version) MONO_INTERNAL;
246 typedef void (*MonoCreateDomainFunc) (MonoDomain *domain);
249 mono_install_create_domain_hook (MonoCreateDomainFunc func) MONO_INTERNAL;
251 typedef void (*MonoFreeDomainFunc) (MonoDomain *domain);
254 mono_install_free_domain_hook (MonoFreeDomainFunc func) MONO_INTERNAL;
257 mono_init_com_types (void) MONO_INTERNAL;
260 mono_cleanup (void) MONO_INTERNAL;
263 mono_close_exe_image (void) MONO_INTERNAL;
266 mono_jit_info_table_add (MonoDomain *domain, MonoJitInfo *ji) MONO_INTERNAL;
269 mono_jit_info_table_remove (MonoDomain *domain, MonoJitInfo *ji) MONO_INTERNAL;
272 mono_jit_info_add_aot_module (MonoImage *image, gpointer start, gpointer end) MONO_INTERNAL;
275 mono_jit_info_get_generic_jit_info (MonoJitInfo *ji) MONO_INTERNAL;
277 MonoGenericSharingContext*
278 mono_jit_info_get_generic_sharing_context (MonoJitInfo *ji) MONO_INTERNAL;
281 mono_jit_info_set_generic_sharing_context (MonoJitInfo *ji, MonoGenericSharingContext *gsctx) MONO_INTERNAL;
284 mono_domain_lookup_shared_generic (MonoDomain *domain, MonoMethod *method) MONO_INTERNAL;
287 mono_domain_register_shared_generic (MonoDomain *domain, MonoMethod *method, MonoJitInfo *jit_info) MONO_INTERNAL;
290 mono_make_shadow_copy (const char *filename);
293 mono_domain_alloc (MonoDomain *domain, guint size) MONO_INTERNAL;
296 mono_domain_alloc0 (MonoDomain *domain, guint size) MONO_INTERNAL;
299 * Installs a new function which is used to return a MonoJitInfo for a method inside
302 typedef MonoJitInfo *(*MonoJitInfoFindInAot) (MonoDomain *domain, MonoImage *image, gpointer addr);
303 void mono_install_jit_info_find_in_aot (MonoJitInfoFindInAot func) MONO_INTERNAL;
306 mono_jit_code_hash_init (MonoInternalHashTable *jit_code_hash) MONO_INTERNAL;
309 ves_icall_System_AppDomain_getCurDomain (void) MONO_INTERNAL;
312 ves_icall_System_AppDomain_getRootDomain (void) MONO_INTERNAL;
315 ves_icall_System_AppDomain_createDomain (MonoString *friendly_name,
316 MonoAppDomainSetup *setup) MONO_INTERNAL;
319 ves_icall_System_AppDomain_GetData (MonoAppDomain *ad,
320 MonoString *name) MONO_INTERNAL;
322 MonoReflectionAssembly *
323 ves_icall_System_AppDomain_LoadAssemblyRaw (MonoAppDomain *ad,
324 MonoArray *raw_assembly,
325 MonoArray *raw_symbol_store,
326 MonoObject *evidence,
327 MonoBoolean refonly) MONO_INTERNAL;
330 ves_icall_System_AppDomain_SetData (MonoAppDomain *ad,
332 MonoObject *data) MONO_INTERNAL;
335 ves_icall_System_AppDomain_getSetup (MonoAppDomain *ad) MONO_INTERNAL;
338 ves_icall_System_AppDomain_getFriendlyName (MonoAppDomain *ad) MONO_INTERNAL;
341 ves_icall_System_AppDomain_GetAssemblies (MonoAppDomain *ad,
342 MonoBoolean refonly) MONO_INTERNAL;
344 MonoReflectionAssembly *
345 ves_icall_System_Reflection_Assembly_LoadFrom (MonoString *fname,
346 MonoBoolean refonly) MONO_INTERNAL;
348 MonoReflectionAssembly *
349 ves_icall_System_AppDomain_LoadAssembly (MonoAppDomain *ad,
351 MonoObject *evidence,
352 MonoBoolean refonly) MONO_INTERNAL;
355 ves_icall_System_AppDomain_InternalIsFinalizingForUnload (gint32 domain_id) MONO_INTERNAL;
358 ves_icall_System_AppDomain_InternalUnload (gint32 domain_id) MONO_INTERNAL;
361 ves_icall_System_AppDomain_ExecuteAssembly (MonoAppDomain *ad,
362 MonoReflectionAssembly *refass,
363 MonoArray *args) MONO_INTERNAL;
366 ves_icall_System_AppDomain_InternalSetDomain (MonoAppDomain *ad) MONO_INTERNAL;
369 ves_icall_System_AppDomain_InternalSetDomainByID (gint32 domainid) MONO_INTERNAL;
372 ves_icall_System_AppDomain_InternalPushDomainRef (MonoAppDomain *ad) MONO_INTERNAL;
375 ves_icall_System_AppDomain_InternalPushDomainRefByID (gint32 domain_id) MONO_INTERNAL;
378 ves_icall_System_AppDomain_InternalPopDomainRef (void) MONO_INTERNAL;
381 ves_icall_System_AppDomain_InternalGetContext (void) MONO_INTERNAL;
384 ves_icall_System_AppDomain_InternalGetDefaultContext (void) MONO_INTERNAL;
387 ves_icall_System_AppDomain_InternalSetContext (MonoAppContext *mc) MONO_INTERNAL;
390 ves_icall_System_AppDomain_GetIDFromDomain (MonoAppDomain * ad) MONO_INTERNAL;
393 ves_icall_System_AppDomain_InternalGetProcessGuid (MonoString* newguid) MONO_INTERNAL;
396 mono_assembly_load_corlib (const MonoRuntimeInfo *runtime, MonoImageOpenStatus *status) MONO_INTERNAL;
398 const MonoRuntimeInfo*
399 mono_get_runtime_info (void) MONO_INTERNAL;
402 mono_runtime_set_no_exec (gboolean val) MONO_INTERNAL;
405 mono_runtime_get_no_exec (void) MONO_INTERNAL;
408 mono_assembly_name_parse (const char *name, MonoAssemblyName *aname) MONO_INTERNAL;
411 mono_assembly_name_free (MonoAssemblyName *aname) MONO_INTERNAL;
413 MonoImage *mono_assembly_open_from_bundle (const char *filename,
414 MonoImageOpenStatus *status,
415 gboolean refonly) MONO_INTERNAL;
418 mono_domain_add_class_static_data (MonoDomain *domain, MonoClass *klass, gpointer data, guint32 *bitmap);
420 MonoReflectionAssembly *
421 mono_try_assembly_resolve (MonoDomain *domain, MonoString *fname, gboolean refonly) MONO_INTERNAL;
423 MonoAssembly* mono_assembly_load_full_nosearch (MonoAssemblyName *aname,
425 MonoImageOpenStatus *status,
426 gboolean refonly) MONO_INTERNAL;
428 #endif /* __MONO_METADATA_DOMAIN_INTERNALS_H__ */