2006-04-24 Zoltan Varga <vargaz@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/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         MonoAppDomain      *domain;
87         CRITICAL_SECTION    lock;
88         MonoMemPool        *mp;
89         MonoCodeManager    *code_mp;
90         MonoGHashTable     *env;
91         GSList             *domain_assemblies;
92         MonoAssembly       *entry_assembly;
93         MonoAppDomainSetup *setup;
94         char               *friendly_name;
95         guint32            state;
96         MonoGHashTable     *ldstr_table;
97         GHashTable         *class_vtable_hash;
98         /* maps remote class key -> MonoRemoteClass */
99         GHashTable         *proxy_vtable_hash;
100         /* a GC-tracked array to keep references to the static fields of types */
101         gpointer           *static_data_array;
102         GHashTable         *jit_code_hash;
103         /* maps MonoMethod -> MonoJitDynamicMethodInfo */
104         GHashTable         *dynamic_code_hash;
105         /* maps delegate trampoline addr -> delegate object */
106         MonoGHashTable     *delegate_hash_table;
107         MonoJitInfoTable   *jit_info_table;
108         /* hashtables for Reflection handles */
109         MonoGHashTable     *type_hash;
110         MonoGHashTable     *refobject_hash;
111         /* Needed by Thread:GetDomainID() */
112         gint32             domain_id;
113         /* Used when loading assemblies */
114         gchar **search_path;
115         /* Used by remoting proxies */
116         MonoMethod         *create_proxy_for_type_method;
117         MonoMethod         *private_invoke_method;
118         MonoAppContext     *default_context;
119         MonoException      *out_of_memory_ex;
120         MonoException      *null_reference_ex;
121         MonoException      *stack_overflow_ex;
122         /* Used to store offsets of thread and context static fields */
123         GHashTable         *special_static_fields;
124         GHashTable         *jump_target_hash;
125         GHashTable         *class_init_trampoline_hash;
126         GHashTable         *jump_trampoline_hash;
127         GHashTable         *jit_trampoline_hash;
128         GHashTable         *delegate_trampoline_hash;
129         /* 
130          * This must be a GHashTable, since these objects can't be finalized
131          * if the hashtable contains a GC visible reference to them.
132          */
133         GHashTable         *finalizable_objects_hash;
134         /* Used when accessing 'domain_assemblies' */
135         CRITICAL_SECTION    assemblies_lock;
136 };
137
138 typedef struct  {
139         guint16 major, minor, build, revision;
140 } AssemblyVersionSet;
141
142 /* MonoRuntimeInfo: Contains information about versions supported by this runtime */
143 typedef struct  {
144         const char runtime_version [12];
145         const char framework_version [4];
146         const AssemblyVersionSet version_sets [2];
147 } MonoRuntimeInfo;
148
149 #define mono_domain_lock(domain)   EnterCriticalSection(&(domain)->lock)
150 #define mono_domain_unlock(domain) LeaveCriticalSection(&(domain)->lock)
151 #define mono_domain_assemblies_lock(domain)   EnterCriticalSection(&(domain)->assemblies_lock)
152 #define mono_domain_assemblies_unlock(domain) LeaveCriticalSection(&(domain)->assemblies_lock)
153
154 void
155 mono_jit_info_table_add    (MonoDomain *domain, MonoJitInfo *ji) MONO_INTERNAL;
156
157 void
158 mono_jit_info_table_remove (MonoDomain *domain, MonoJitInfo *ji) MONO_INTERNAL;
159
160 void
161 mono_jit_info_add_aot_module (MonoImage *image, gpointer start, gpointer end) MONO_INTERNAL;
162
163 /* 
164  * Installs a new function which is used to return a MonoJitInfo for a method inside
165  * an AOT module.
166  */
167 typedef MonoJitInfo *(*MonoJitInfoFindInAot)         (MonoDomain *domain, MonoImage *image, gpointer addr);
168 void          mono_install_jit_info_find_in_aot (MonoJitInfoFindInAot func) MONO_INTERNAL;
169
170 MonoAppDomain *
171 ves_icall_System_AppDomain_getCurDomain            (void) MONO_INTERNAL;
172
173 MonoAppDomain *
174 ves_icall_System_AppDomain_getRootDomain           (void) MONO_INTERNAL;
175
176 MonoAppDomain *
177 ves_icall_System_AppDomain_createDomain            (MonoString         *friendly_name,
178                                                     MonoAppDomainSetup *setup) MONO_INTERNAL;
179
180 MonoObject *
181 ves_icall_System_AppDomain_GetData                 (MonoAppDomain *ad, 
182                                                     MonoString    *name) MONO_INTERNAL;
183
184 MonoReflectionAssembly *
185 ves_icall_System_AppDomain_LoadAssemblyRaw         (MonoAppDomain *ad,
186                                                     MonoArray *raw_assembly, 
187                                                     MonoArray *raw_symbol_store,
188                                                     MonoObject *evidence,
189                                                     MonoBoolean refonly) MONO_INTERNAL;
190
191 void
192 ves_icall_System_AppDomain_SetData                 (MonoAppDomain *ad, 
193                                                     MonoString    *name, 
194                                                     MonoObject    *data) MONO_INTERNAL;
195
196 MonoAppDomainSetup *
197 ves_icall_System_AppDomain_getSetup                (MonoAppDomain *ad) MONO_INTERNAL;
198
199 MonoString *
200 ves_icall_System_AppDomain_getFriendlyName         (MonoAppDomain *ad) MONO_INTERNAL;
201
202 MonoArray *
203 ves_icall_System_AppDomain_GetAssemblies           (MonoAppDomain *ad,
204                                                     MonoBoolean refonly) MONO_INTERNAL;
205
206 MonoReflectionAssembly *
207 ves_icall_System_Reflection_Assembly_LoadFrom      (MonoString *fname,
208                                                     MonoBoolean refonly) MONO_INTERNAL;
209
210 MonoReflectionAssembly *
211 ves_icall_System_AppDomain_LoadAssembly            (MonoAppDomain *ad, 
212                                                     MonoString *assRef,
213                                                     MonoObject    *evidence,
214                                                     MonoBoolean refonly) MONO_INTERNAL;
215
216 gboolean
217 ves_icall_System_AppDomain_InternalIsFinalizingForUnload (gint32 domain_id) MONO_INTERNAL;
218
219 void
220 ves_icall_System_AppDomain_InternalUnload          (gint32 domain_id) MONO_INTERNAL;
221
222 gint32
223 ves_icall_System_AppDomain_ExecuteAssembly         (MonoAppDomain *ad, 
224                                                     MonoString    *file, 
225                                                     MonoObject    *evidence,
226                                                     MonoArray     *args) MONO_INTERNAL;
227
228 MonoAppDomain * 
229 ves_icall_System_AppDomain_InternalSetDomain       (MonoAppDomain *ad) MONO_INTERNAL;
230
231 MonoAppDomain * 
232 ves_icall_System_AppDomain_InternalSetDomainByID   (gint32 domainid) MONO_INTERNAL;
233
234 void
235 ves_icall_System_AppDomain_InternalPushDomainRef (MonoAppDomain *ad) MONO_INTERNAL;
236
237 void
238 ves_icall_System_AppDomain_InternalPushDomainRefByID (gint32 domain_id) MONO_INTERNAL;
239
240 void
241 ves_icall_System_AppDomain_InternalPopDomainRef (void) MONO_INTERNAL;
242
243 MonoAppContext * 
244 ves_icall_System_AppDomain_InternalGetContext      (void) MONO_INTERNAL;
245
246 MonoAppContext * 
247 ves_icall_System_AppDomain_InternalGetDefaultContext      (void) MONO_INTERNAL;
248
249 MonoAppContext * 
250 ves_icall_System_AppDomain_InternalSetContext      (MonoAppContext *mc) MONO_INTERNAL;
251
252 gint32 
253 ves_icall_System_AppDomain_GetIDFromDomain (MonoAppDomain * ad) MONO_INTERNAL;
254
255 MonoString *
256 ves_icall_System_AppDomain_InternalGetProcessGuid (MonoString* newguid) MONO_INTERNAL;
257
258 MonoAssembly *
259 mono_assembly_load_corlib (const MonoRuntimeInfo *runtime, MonoImageOpenStatus *status) MONO_INTERNAL;
260
261 const MonoRuntimeInfo*
262 mono_get_runtime_info (void) MONO_INTERNAL;
263
264 gboolean
265 mono_assembly_name_parse (const char *name, MonoAssemblyName *aname) MONO_INTERNAL;
266
267 void
268 mono_assembly_name_free (MonoAssemblyName *aname) MONO_INTERNAL;
269
270 void
271 mono_domain_add_class_static_data (MonoDomain *domain, MonoClass *klass, gpointer data, guint32 *bitmap);
272
273 #endif /* __MONO_METADATA_DOMAIN_INTERNALS_H__ */