remove genxs2 (no 2.0 profile assembly is built)
[mono-project/dkf.git] / mono / metadata / domain-internals.h
blobdc2ab2eb0f871205a8169c0b54999eefa0ff056c
1 /*
2 * Appdomain-related internal data structures and functions.
3 */
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
21 * performance.
22 */
23 extern gboolean mono_dont_free_domains;
25 /* This is a copy of System.AppDomainSetup */
26 typedef struct {
27 MonoObject object;
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;
49 } MonoAppDomainSetup;
51 typedef struct _MonoJitInfoTable MonoJitInfoTable;
52 typedef struct _MonoJitInfoTableChunk MonoJitInfoTableChunk;
54 #define MONO_JIT_INFO_TABLE_CHUNK_SIZE 64
56 struct _MonoJitInfoTableChunk
58 int refcount;
59 volatile int num_elements;
60 volatile gint8 *last_code_end;
61 MonoJitInfo * volatile data [MONO_JIT_INFO_TABLE_CHUNK_SIZE];
64 struct _MonoJitInfoTable
66 MonoDomain *domain;
67 int num_chunks;
68 MonoJitInfoTableChunk *chunks [MONO_ZERO_LEN_ARRAY];
71 typedef GArray MonoAotModuleInfoTable;
73 typedef struct {
74 guint32 flags;
75 gint32 exvar_offset;
76 gpointer try_start;
77 gpointer try_end;
78 gpointer handler_start;
79 union {
80 MonoClass *catch_class;
81 gpointer filter;
82 } data;
83 } MonoJitExceptionInfo;
86 * Will contain information on the generic type arguments in the
87 * future. For now, all arguments are always reference types.
89 typedef struct {
90 int dummy;
91 } MonoGenericSharingContext;
93 typedef struct
95 MonoGenericSharingContext *generic_sharing_context;
96 gint32 this_offset;
97 guint8 this_reg;
98 gboolean has_this:1;
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. */
107 MonoMethod *method;
108 struct _MonoJitInfo *next_jit_code_hash;
109 gpointer code_start;
110 /* This might contain an id for the unwind info instead of a register mask */
111 guint32 used_regs;
112 int code_size;
113 guint32 num_clauses:15;
114 /* Whenever the code is domain neutral or 'shared' */
115 gboolean domain_neutral:1;
116 gboolean cas_inited:1;
117 gboolean cas_class_assert:1;
118 gboolean cas_class_deny:1;
119 gboolean cas_class_permitonly:1;
120 gboolean cas_method_assert:1;
121 gboolean cas_method_deny:1;
122 gboolean cas_method_permitonly:1;
123 gboolean has_generic_jit_info:1;
124 gboolean from_aot:1;
125 MonoJitExceptionInfo clauses [MONO_ZERO_LEN_ARRAY];
126 /* There is an optional MonoGenericJitInfo after the clauses */
129 struct _MonoAppContext {
130 MonoObject obj;
131 gint32 domain_id;
132 gint32 context_id;
133 gpointer *static_data;
137 * We have two unloading states because the domain
138 * must remain fully functional while AppDomain::DomainUnload is
139 * processed.
140 * After that unloading began and all domain facilities are teared down
141 * such as execution of new threadpool jobs.
143 typedef enum {
144 MONO_APPDOMAIN_CREATED,
145 MONO_APPDOMAIN_UNLOADING_START,
146 MONO_APPDOMAIN_UNLOADING,
147 MONO_APPDOMAIN_UNLOADED
148 } MonoAppDomainState;
150 typedef struct _MonoThunkFreeList {
151 guint32 size;
152 int length; /* only valid for the wait list */
153 struct _MonoThunkFreeList *next;
154 } MonoThunkFreeList;
156 typedef struct _MonoJitCodeHash MonoJitCodeHash;
158 struct _MonoDomain {
160 * This lock must never be taken before the loader lock,
161 * i.e. if both are taken by the same thread, the loader lock
162 * must taken first.
164 CRITICAL_SECTION lock;
165 MonoMemPool *mp;
166 MonoCodeManager *code_mp;
168 * keep all the managed objects close to each other for the precise GC
169 * For the Boehm GC we additionally keep close also other GC-tracked pointers.
171 #define MONO_DOMAIN_FIRST_OBJECT setup
172 MonoAppDomainSetup *setup;
173 MonoAppDomain *domain;
174 MonoAppContext *default_context;
175 MonoException *out_of_memory_ex;
176 MonoException *null_reference_ex;
177 MonoException *stack_overflow_ex;
178 #define MONO_DOMAIN_FIRST_GC_TRACKED env
179 MonoGHashTable *env;
180 MonoGHashTable *ldstr_table;
181 /* hashtables for Reflection handles */
182 MonoGHashTable *type_hash;
183 MonoGHashTable *refobject_hash;
184 /* a GC-tracked array to keep references to the static fields of types */
185 gpointer *static_data_array;
186 /* maps class -> type initialization exception object */
187 MonoGHashTable *type_init_exception_hash;
188 /* maps delegate trampoline addr -> delegate object */
189 MonoGHashTable *delegate_hash_table;
190 /* typeof (void) */
191 MonoObject *typeof_void;
192 #define MONO_DOMAIN_LAST_GC_TRACKED typeof_void
193 guint32 state;
194 /* Needed by Thread:GetDomainID() */
195 gint32 domain_id;
196 gint32 shadow_serial;
197 unsigned char inet_family_hint; // used in socket-io.c as a cache
198 GSList *domain_assemblies;
199 MonoAssembly *entry_assembly;
200 char *friendly_name;
201 GHashTable *class_vtable_hash;
202 /* maps remote class key -> MonoRemoteClass */
203 GHashTable *proxy_vtable_hash;
204 /* Protected by 'jit_code_hash_lock' */
205 MonoInternalHashTable jit_code_hash;
206 CRITICAL_SECTION jit_code_hash_lock;
207 int num_jit_info_tables;
208 MonoJitInfoTable *
209 volatile jit_info_table;
210 GSList *jit_info_free_queue;
211 /* Used when loading assemblies */
212 gchar **search_path;
213 gchar *private_bin_path;
215 /* Used by remoting proxies */
216 MonoMethod *create_proxy_for_type_method;
217 MonoMethod *private_invoke_method;
218 /* Used to store offsets of thread and context static fields */
219 GHashTable *special_static_fields;
221 * This must be a GHashTable, since these objects can't be finalized
222 * if the hashtable contains a GC visible reference to them.
224 GHashTable *finalizable_objects_hash;
225 /* Used when accessing 'domain_assemblies' */
226 CRITICAL_SECTION assemblies_lock;
228 GHashTable *method_rgctx_hash;
230 GHashTable *generic_virtual_cases;
231 MonoThunkFreeList **thunk_free_lists;
233 /* Information maintained by the JIT engine */
234 gpointer runtime_info;
236 /*thread pool jobs, used to coordinate shutdown.*/
237 int threadpool_jobs;
238 HANDLE cleanup_semaphore;
241 typedef struct {
242 guint16 major, minor, build, revision;
243 } AssemblyVersionSet;
245 /* MonoRuntimeInfo: Contains information about versions supported by this runtime */
246 typedef struct {
247 const char runtime_version [12];
248 const char framework_version [4];
249 const AssemblyVersionSet version_sets [2];
250 } MonoRuntimeInfo;
252 #define mono_domain_lock(domain) EnterCriticalSection(&(domain)->lock)
253 #define mono_domain_unlock(domain) LeaveCriticalSection(&(domain)->lock)
254 #define mono_domain_assemblies_lock(domain) EnterCriticalSection(&(domain)->assemblies_lock)
255 #define mono_domain_assemblies_unlock(domain) LeaveCriticalSection(&(domain)->assemblies_lock)
256 #define mono_domain_jit_code_hash_lock(domain) EnterCriticalSection(&(domain)->jit_code_hash_lock)
257 #define mono_domain_jit_code_hash_unlock(domain) LeaveCriticalSection(&(domain)->jit_code_hash_lock)
259 typedef MonoDomain* (*MonoLoadFunc) (const char *filename, const char *runtime_version);
261 void
262 mono_install_runtime_load (MonoLoadFunc func) MONO_INTERNAL;
264 MonoDomain*
265 mono_runtime_load (const char *filename, const char *runtime_version) MONO_INTERNAL;
267 typedef void (*MonoCreateDomainFunc) (MonoDomain *domain);
269 void
270 mono_install_create_domain_hook (MonoCreateDomainFunc func) MONO_INTERNAL;
272 typedef void (*MonoFreeDomainFunc) (MonoDomain *domain);
274 void
275 mono_install_free_domain_hook (MonoFreeDomainFunc func) MONO_INTERNAL;
277 void
278 mono_init_com_types (void) MONO_INTERNAL;
280 void
281 mono_cleanup (void) MONO_INTERNAL;
283 void
284 mono_close_exe_image (void) MONO_INTERNAL;
286 void
287 mono_jit_info_table_add (MonoDomain *domain, MonoJitInfo *ji) MONO_INTERNAL;
289 void
290 mono_jit_info_table_remove (MonoDomain *domain, MonoJitInfo *ji) MONO_INTERNAL;
292 void
293 mono_jit_info_add_aot_module (MonoImage *image, gpointer start, gpointer end) MONO_INTERNAL;
295 MonoGenericJitInfo*
296 mono_jit_info_get_generic_jit_info (MonoJitInfo *ji) MONO_INTERNAL;
298 MonoGenericSharingContext*
299 mono_jit_info_get_generic_sharing_context (MonoJitInfo *ji) MONO_INTERNAL;
301 void
302 mono_jit_info_set_generic_sharing_context (MonoJitInfo *ji, MonoGenericSharingContext *gsctx) MONO_INTERNAL;
304 char *
305 mono_make_shadow_copy (const char *filename) MONO_INTERNAL;
307 gboolean
308 mono_is_shadow_copy_enabled (MonoDomain *domain, const gchar *dir_name) MONO_INTERNAL;
310 gpointer
311 mono_domain_alloc (MonoDomain *domain, guint size) MONO_INTERNAL;
313 gpointer
314 mono_domain_alloc0 (MonoDomain *domain, guint size) MONO_INTERNAL;
317 * Installs a new function which is used to return a MonoJitInfo for a method inside
318 * an AOT module.
320 typedef MonoJitInfo *(*MonoJitInfoFindInAot) (MonoDomain *domain, MonoImage *image, gpointer addr);
321 void mono_install_jit_info_find_in_aot (MonoJitInfoFindInAot func) MONO_INTERNAL;
323 void
324 mono_jit_code_hash_init (MonoInternalHashTable *jit_code_hash) MONO_INTERNAL;
326 MonoAppDomain *
327 ves_icall_System_AppDomain_getCurDomain (void) MONO_INTERNAL;
329 MonoAppDomain *
330 ves_icall_System_AppDomain_getRootDomain (void) MONO_INTERNAL;
332 MonoAppDomain *
333 ves_icall_System_AppDomain_createDomain (MonoString *friendly_name,
334 MonoAppDomainSetup *setup) MONO_INTERNAL;
336 MonoObject *
337 ves_icall_System_AppDomain_GetData (MonoAppDomain *ad,
338 MonoString *name) MONO_INTERNAL;
340 MonoReflectionAssembly *
341 ves_icall_System_AppDomain_LoadAssemblyRaw (MonoAppDomain *ad,
342 MonoArray *raw_assembly,
343 MonoArray *raw_symbol_store,
344 MonoObject *evidence,
345 MonoBoolean refonly) MONO_INTERNAL;
347 void
348 ves_icall_System_AppDomain_SetData (MonoAppDomain *ad,
349 MonoString *name,
350 MonoObject *data) MONO_INTERNAL;
352 MonoAppDomainSetup *
353 ves_icall_System_AppDomain_getSetup (MonoAppDomain *ad) MONO_INTERNAL;
355 MonoString *
356 ves_icall_System_AppDomain_getFriendlyName (MonoAppDomain *ad) MONO_INTERNAL;
358 MonoArray *
359 ves_icall_System_AppDomain_GetAssemblies (MonoAppDomain *ad,
360 MonoBoolean refonly) MONO_INTERNAL;
362 MonoReflectionAssembly *
363 ves_icall_System_Reflection_Assembly_LoadFrom (MonoString *fname,
364 MonoBoolean refonly) MONO_INTERNAL;
366 MonoReflectionAssembly *
367 ves_icall_System_AppDomain_LoadAssembly (MonoAppDomain *ad,
368 MonoString *assRef,
369 MonoObject *evidence,
370 MonoBoolean refonly) MONO_INTERNAL;
372 gboolean
373 ves_icall_System_AppDomain_InternalIsFinalizingForUnload (gint32 domain_id) MONO_INTERNAL;
375 void
376 ves_icall_System_AppDomain_InternalUnload (gint32 domain_id) MONO_INTERNAL;
378 gint32
379 ves_icall_System_AppDomain_ExecuteAssembly (MonoAppDomain *ad,
380 MonoReflectionAssembly *refass,
381 MonoArray *args) MONO_INTERNAL;
383 MonoAppDomain *
384 ves_icall_System_AppDomain_InternalSetDomain (MonoAppDomain *ad) MONO_INTERNAL;
386 MonoAppDomain *
387 ves_icall_System_AppDomain_InternalSetDomainByID (gint32 domainid) MONO_INTERNAL;
389 void
390 ves_icall_System_AppDomain_InternalPushDomainRef (MonoAppDomain *ad) MONO_INTERNAL;
392 void
393 ves_icall_System_AppDomain_InternalPushDomainRefByID (gint32 domain_id) MONO_INTERNAL;
395 void
396 ves_icall_System_AppDomain_InternalPopDomainRef (void) MONO_INTERNAL;
398 MonoAppContext *
399 ves_icall_System_AppDomain_InternalGetContext (void) MONO_INTERNAL;
401 MonoAppContext *
402 ves_icall_System_AppDomain_InternalGetDefaultContext (void) MONO_INTERNAL;
404 MonoAppContext *
405 ves_icall_System_AppDomain_InternalSetContext (MonoAppContext *mc) MONO_INTERNAL;
407 gint32
408 ves_icall_System_AppDomain_GetIDFromDomain (MonoAppDomain * ad) MONO_INTERNAL;
410 MonoString *
411 ves_icall_System_AppDomain_InternalGetProcessGuid (MonoString* newguid) MONO_INTERNAL;
413 MonoAssembly *
414 mono_assembly_load_corlib (const MonoRuntimeInfo *runtime, MonoImageOpenStatus *status) MONO_INTERNAL;
416 const MonoRuntimeInfo*
417 mono_get_runtime_info (void) MONO_INTERNAL;
419 void
420 mono_runtime_set_no_exec (gboolean val) MONO_INTERNAL;
422 gboolean
423 mono_runtime_get_no_exec (void) MONO_INTERNAL;
425 gboolean
426 mono_assembly_name_parse (const char *name, MonoAssemblyName *aname) MONO_INTERNAL;
428 void
429 mono_assembly_name_free (MonoAssemblyName *aname) MONO_INTERNAL;
431 MonoImage *mono_assembly_open_from_bundle (const char *filename,
432 MonoImageOpenStatus *status,
433 gboolean refonly) MONO_INTERNAL;
435 void
436 mono_domain_add_class_static_data (MonoDomain *domain, MonoClass *klass, gpointer data, guint32 *bitmap);
438 MonoReflectionAssembly *
439 mono_try_assembly_resolve (MonoDomain *domain, MonoString *fname, gboolean refonly) MONO_INTERNAL;
441 MonoAssembly* mono_assembly_load_full_nosearch (MonoAssemblyName *aname,
442 const char *basedir,
443 MonoImageOpenStatus *status,
444 gboolean refonly) MONO_INTERNAL;
446 void mono_set_private_bin_path_from_config (MonoDomain *domain) MONO_INTERNAL;
448 int mono_framework_version (void) MONO_INTERNAL;
450 #endif /* __MONO_METADATA_DOMAIN_INTERNALS_H__ */