9554636c4fb225d829f9bda5261b50db352453c3
[mono.git] / mono / metadata / domain-internals.h
1 /*
2  * Appdomain-related internal data structures and functions.
3  */
4 #ifndef __MONO_METADATA_DOMAIN_INTERNALS_H__
5 #define __MONO_METADATA_DOMAIN_INTERNALS_H__
6
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/io-layer/io-layer.h>
12
13 extern CRITICAL_SECTION mono_delegate_section;
14
15 /* This is a copy of System.AppDomainSetup */
16 typedef struct {
17         MonoObject object;
18         MonoString *application_base;
19         MonoString *application_name;
20         MonoString *cache_path;
21         MonoString *configuration_file;
22         MonoString *dynamic_base;
23         MonoString *license_file;
24         MonoString *private_bin_path;
25         MonoString *private_bin_path_probe;
26         MonoString *shadow_copy_directories;
27         MonoString *shadow_copy_files;
28         MonoBoolean publisher_policy;
29         MonoBoolean path_changed;
30         int loader_optimization;
31         MonoBoolean disallow_binding_redirects;
32         MonoBoolean disallow_code_downloads;
33 } MonoAppDomainSetup;
34
35 typedef GArray MonoJitInfoTable;
36
37 typedef struct {
38         guint32  flags;
39         gint32   exvar_offset;
40         gpointer try_start;
41         gpointer try_end;
42         gpointer handler_start;
43         union {
44                 MonoClass *catch_class;
45                 gpointer filter;
46         } data;
47 } MonoJitExceptionInfo;
48
49 struct _MonoJitInfo {
50         MonoMethod *method;
51         gpointer    code_start;
52         guint32     used_regs;
53         int         code_size;
54         guint32     num_clauses:24;
55         /* Whenever the code is domain neutral or 'shared' */
56         gboolean    domain_neutral:1;
57         gboolean    cas_inited:1;
58         gboolean    cas_class_assert:1;
59         gboolean    cas_class_deny:1;
60         gboolean    cas_class_permitonly:1;
61         gboolean    cas_method_assert:1;
62         gboolean    cas_method_deny:1;
63         gboolean    cas_method_permitonly:1;
64         MonoJitExceptionInfo clauses [MONO_ZERO_LEN_ARRAY];
65 };
66
67 typedef struct {
68         MonoJitInfo *ji;
69         MonoCodeManager *code_mp;
70 } MonoJitDynamicMethodInfo;
71
72 struct _MonoAppContext {
73         MonoObject obj;
74         gint32 domain_id;
75         gint32 context_id;
76         gpointer *static_data;
77 };
78
79 typedef enum {
80         MONO_APPDOMAIN_CREATED,
81         MONO_APPDOMAIN_UNLOADING,
82         MONO_APPDOMAIN_UNLOADED
83 } MonoAppDomainState;
84
85 struct _MonoDomain {
86         CRITICAL_SECTION    lock;
87         MonoMemPool        *mp;
88         MonoCodeManager    *code_mp;
89         /*
90          * keep all the managed objects close to each other for the precise GC
91          * For the Boehm GC we additionally keep close also other GC-tracked pointers.
92          */
93 #define MONO_DOMAIN_FIRST_OBJECT setup
94         MonoAppDomainSetup *setup;
95         MonoAppDomain      *domain;
96         MonoAppContext     *default_context;
97         MonoException      *out_of_memory_ex;
98         MonoException      *null_reference_ex;
99         MonoException      *stack_overflow_ex;
100 #define MONO_DOMAIN_FIRST_GC_TRACKED env
101         MonoGHashTable     *env;
102         MonoGHashTable     *ldstr_table;
103         /* hashtables for Reflection handles */
104         MonoGHashTable     *type_hash;
105         MonoGHashTable     *refobject_hash;
106         /* a GC-tracked array to keep references to the static fields of types */
107         gpointer           *static_data_array;
108         /* maps class -> type initialization exception object */
109         MonoGHashTable    *type_init_exception_hash;
110         /* maps delegate trampoline addr -> delegate object */
111         MonoGHashTable     *delegate_hash_table;
112 #define MONO_DOMAIN_LAST_GC_TRACKED delegate_hash_table
113         guint32            state;
114         /* Needed by Thread:GetDomainID() */
115         gint32             domain_id;
116         GSList             *domain_assemblies;
117         MonoAssembly       *entry_assembly;
118         char               *friendly_name;
119         GHashTable         *class_vtable_hash;
120         /* maps remote class key -> MonoRemoteClass */
121         GHashTable         *proxy_vtable_hash;
122         GHashTable         *jit_code_hash;
123         /* maps MonoMethod -> MonoJitDynamicMethodInfo */
124         GHashTable         *dynamic_code_hash;
125         MonoJitInfoTable   *jit_info_table;
126         /* Used when loading assemblies */
127         gchar **search_path;
128         /* Used by remoting proxies */
129         MonoMethod         *create_proxy_for_type_method;
130         MonoMethod         *private_invoke_method;
131         /* Used to store offsets of thread and context static fields */
132         GHashTable         *special_static_fields;
133         GHashTable         *jump_target_hash;
134         GHashTable         *class_init_trampoline_hash;
135         GHashTable         *jump_trampoline_hash;
136         GHashTable         *jit_trampoline_hash;
137         GHashTable         *delegate_trampoline_hash;
138         GHashTable         *delegate_invoke_impl_with_target_hash;
139         GHashTable         *delegate_invoke_impl_no_target_hash;
140         /* 
141          * This must be a GHashTable, since these objects can't be finalized
142          * if the hashtable contains a GC visible reference to them.
143          */
144         GHashTable         *finalizable_objects_hash;
145         /* Used when accessing 'domain_assemblies' */
146         CRITICAL_SECTION    assemblies_lock;
147 };
148
149 typedef struct  {
150         guint16 major, minor, build, revision;
151 } AssemblyVersionSet;
152
153 /* MonoRuntimeInfo: Contains information about versions supported by this runtime */
154 typedef struct  {
155         const char runtime_version [12];
156         const char framework_version [4];
157         const AssemblyVersionSet version_sets [2];
158 } MonoRuntimeInfo;
159
160 #define mono_domain_lock(domain)   EnterCriticalSection(&(domain)->lock)
161 #define mono_domain_unlock(domain) LeaveCriticalSection(&(domain)->lock)
162 #define mono_domain_assemblies_lock(domain)   EnterCriticalSection(&(domain)->assemblies_lock)
163 #define mono_domain_assemblies_unlock(domain) LeaveCriticalSection(&(domain)->assemblies_lock)
164
165 void 
166 mono_init_com_types (void) MONO_INTERNAL;
167
168 void 
169 mono_cleanup (void) MONO_INTERNAL;
170
171 void
172 mono_jit_info_table_add    (MonoDomain *domain, MonoJitInfo *ji) MONO_INTERNAL;
173
174 void
175 mono_jit_info_table_remove (MonoDomain *domain, MonoJitInfo *ji) MONO_INTERNAL;
176
177 void
178 mono_jit_info_add_aot_module (MonoImage *image, gpointer start, gpointer end) MONO_INTERNAL;
179
180 /* 
181  * Installs a new function which is used to return a MonoJitInfo for a method inside
182  * an AOT module.
183  */
184 typedef MonoJitInfo *(*MonoJitInfoFindInAot)         (MonoDomain *domain, MonoImage *image, gpointer addr);
185 void          mono_install_jit_info_find_in_aot (MonoJitInfoFindInAot func) MONO_INTERNAL;
186
187 MonoAppDomain *
188 ves_icall_System_AppDomain_getCurDomain            (void) MONO_INTERNAL;
189
190 MonoAppDomain *
191 ves_icall_System_AppDomain_getRootDomain           (void) MONO_INTERNAL;
192
193 MonoAppDomain *
194 ves_icall_System_AppDomain_createDomain            (MonoString         *friendly_name,
195                                                     MonoAppDomainSetup *setup) MONO_INTERNAL;
196
197 MonoObject *
198 ves_icall_System_AppDomain_GetData                 (MonoAppDomain *ad, 
199                                                     MonoString    *name) MONO_INTERNAL;
200
201 MonoReflectionAssembly *
202 ves_icall_System_AppDomain_LoadAssemblyRaw         (MonoAppDomain *ad,
203                                                     MonoArray *raw_assembly, 
204                                                     MonoArray *raw_symbol_store,
205                                                     MonoObject *evidence,
206                                                     MonoBoolean refonly) MONO_INTERNAL;
207
208 void
209 ves_icall_System_AppDomain_SetData                 (MonoAppDomain *ad, 
210                                                     MonoString    *name, 
211                                                     MonoObject    *data) MONO_INTERNAL;
212
213 MonoAppDomainSetup *
214 ves_icall_System_AppDomain_getSetup                (MonoAppDomain *ad) MONO_INTERNAL;
215
216 MonoString *
217 ves_icall_System_AppDomain_getFriendlyName         (MonoAppDomain *ad) MONO_INTERNAL;
218
219 MonoArray *
220 ves_icall_System_AppDomain_GetAssemblies           (MonoAppDomain *ad,
221                                                     MonoBoolean refonly) MONO_INTERNAL;
222
223 MonoReflectionAssembly *
224 ves_icall_System_Reflection_Assembly_LoadFrom      (MonoString *fname,
225                                                     MonoBoolean refonly) MONO_INTERNAL;
226
227 MonoReflectionAssembly *
228 ves_icall_System_AppDomain_LoadAssembly            (MonoAppDomain *ad, 
229                                                     MonoString *assRef,
230                                                     MonoObject    *evidence,
231                                                     MonoBoolean refonly) MONO_INTERNAL;
232
233 gboolean
234 ves_icall_System_AppDomain_InternalIsFinalizingForUnload (gint32 domain_id) MONO_INTERNAL;
235
236 void
237 ves_icall_System_AppDomain_InternalUnload          (gint32 domain_id) MONO_INTERNAL;
238
239 gint32
240 ves_icall_System_AppDomain_ExecuteAssembly         (MonoAppDomain *ad, 
241                                                     MonoString    *file, 
242                                                     MonoObject    *evidence,
243                                                     MonoArray     *args) MONO_INTERNAL;
244
245 MonoAppDomain * 
246 ves_icall_System_AppDomain_InternalSetDomain       (MonoAppDomain *ad) MONO_INTERNAL;
247
248 MonoAppDomain * 
249 ves_icall_System_AppDomain_InternalSetDomainByID   (gint32 domainid) MONO_INTERNAL;
250
251 void
252 ves_icall_System_AppDomain_InternalPushDomainRef (MonoAppDomain *ad) MONO_INTERNAL;
253
254 void
255 ves_icall_System_AppDomain_InternalPushDomainRefByID (gint32 domain_id) MONO_INTERNAL;
256
257 void
258 ves_icall_System_AppDomain_InternalPopDomainRef (void) MONO_INTERNAL;
259
260 MonoAppContext * 
261 ves_icall_System_AppDomain_InternalGetContext      (void) MONO_INTERNAL;
262
263 MonoAppContext * 
264 ves_icall_System_AppDomain_InternalGetDefaultContext      (void) MONO_INTERNAL;
265
266 MonoAppContext * 
267 ves_icall_System_AppDomain_InternalSetContext      (MonoAppContext *mc) MONO_INTERNAL;
268
269 gint32 
270 ves_icall_System_AppDomain_GetIDFromDomain (MonoAppDomain * ad) MONO_INTERNAL;
271
272 MonoString *
273 ves_icall_System_AppDomain_InternalGetProcessGuid (MonoString* newguid) MONO_INTERNAL;
274
275 MonoAssembly *
276 mono_assembly_load_corlib (const MonoRuntimeInfo *runtime, MonoImageOpenStatus *status) MONO_INTERNAL;
277
278 const MonoRuntimeInfo*
279 mono_get_runtime_info (void) MONO_INTERNAL;
280
281 gboolean
282 mono_assembly_name_parse (const char *name, MonoAssemblyName *aname) MONO_INTERNAL;
283
284 void
285 mono_assembly_name_free (MonoAssemblyName *aname) MONO_INTERNAL;
286
287 MonoImage *mono_assembly_open_from_bundle (const char *filename,
288                                            MonoImageOpenStatus *status,
289                                            gboolean refonly) MONO_INTERNAL;
290
291 void
292 mono_domain_add_class_static_data (MonoDomain *domain, MonoClass *klass, gpointer data, guint32 *bitmap);
293
294 #endif /* __MONO_METADATA_DOMAIN_INTERNALS_H__ */