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