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