3 * Copyright 2002-2003 Ximian Inc
4 * Copyright 2003-2011 Novell Inc
5 * Copyright 2011 Xamarin Inc
6 * Licensed under the MIT license. See LICENSE file in the project root for full license information.
8 #ifndef __MONO_AOT_RUNTIME_H__
9 #define __MONO_AOT_RUNTIME_H__
13 /* Version number of the AOT file format */
14 #define MONO_AOT_FILE_VERSION 168
16 #define MONO_AOT_TRAMP_PAGE_SIZE 16384
18 /* Constants used to encode different types of methods in AOT */
20 MONO_AOT_METHODREF_MIN
= 240,
21 /* Image index bigger than METHODREF_MIN */
22 MONO_AOT_METHODREF_LARGE_IMAGE_INDEX
= 249,
23 /* Runtime provided methods on arrays */
24 MONO_AOT_METHODREF_ARRAY
= 250,
25 MONO_AOT_METHODREF_NO_AOT_TRAMPOLINE
= 251,
27 MONO_AOT_METHODREF_WRAPPER
= 252,
28 /* Methods on generic instances */
29 MONO_AOT_METHODREF_GINST
= 253,
30 /* Methods resolve using a METHODSPEC token */
31 MONO_AOT_METHODREF_METHODSPEC
= 254,
32 /* Blob index of the method encoding */
33 MONO_AOT_METHODREF_BLOB_INDEX
= 255
36 /* Constants used to encode different types of types in AOT */
39 MONO_AOT_TYPEREF_TYPEDEF_INDEX
= 1,
40 /* typedef index + image index */
41 MONO_AOT_TYPEREF_TYPEDEF_INDEX_IMAGE
= 2,
43 MONO_AOT_TYPEREF_TYPESPEC_TOKEN
= 3,
45 MONO_AOT_TYPEREF_GINST
= 4,
46 /* type/method variable */
47 MONO_AOT_TYPEREF_VAR
= 5,
49 MONO_AOT_TYPEREF_ARRAY
= 6,
50 /* blob index of the type encoding */
51 MONO_AOT_TYPEREF_BLOB_INDEX
= 7,
53 MONO_AOT_TYPEREF_PTR
= 8
56 /* Trampolines which we have a lot of */
58 MONO_AOT_TRAMP_SPECIFIC
= 0,
59 MONO_AOT_TRAMP_STATIC_RGCTX
= 1,
60 MONO_AOT_TRAMP_IMT
= 2,
61 MONO_AOT_TRAMP_GSHAREDVT_ARG
= 3,
62 MONO_AOT_TRAMP_FTNPTR_ARG
= 4,
63 MONO_AOT_TRAMP_UNBOX_ARBITRARY
= 5,
64 MONO_AOT_TRAMP_NUM
= 6
68 MONO_AOT_FILE_FLAG_WITH_LLVM
= 1,
69 MONO_AOT_FILE_FLAG_FULL_AOT
= 2,
70 MONO_AOT_FILE_FLAG_DEBUG
= 4,
71 MONO_AOT_FILE_FLAG_LLVM_THUMB
= 8,
72 MONO_AOT_FILE_FLAG_LLVM_ONLY
= 16,
73 MONO_AOT_FILE_FLAG_SAFEPOINTS
= 32,
74 MONO_AOT_FILE_FLAG_SEPARATE_DATA
= 64,
75 MONO_AOT_FILE_FLAG_EAGER_LOAD
= 128,
76 MONO_AOT_FILE_FLAG_INTERP
= 256,
80 MONO_AOT_METHOD_FLAG_NONE
= 0,
81 MONO_AOT_METHOD_FLAG_HAS_CCTOR
= 1,
82 MONO_AOT_METHOD_FLAG_GSHAREDVT_VARIABLE
= 2,
83 MONO_AOT_METHOD_FLAG_HAS_PATCHES
= 4,
84 MONO_AOT_METHOD_FLAG_HAS_CTX
= 8
89 MONO_AOT_TABLE_IMAGE_TABLE
,
90 MONO_AOT_TABLE_CLASS_NAME
,
91 MONO_AOT_TABLE_METHOD_INFO_OFFSETS
,
92 MONO_AOT_TABLE_EX_INFO_OFFSETS
,
93 MONO_AOT_TABLE_CLASS_INFO_OFFSETS
,
94 MONO_AOT_TABLE_GOT_INFO_OFFSETS
,
95 MONO_AOT_TABLE_LLVM_GOT_INFO_OFFSETS
,
96 MONO_AOT_TABLE_EXTRA_METHOD_INFO_OFFSETS
,
97 MONO_AOT_TABLE_EXTRA_METHOD_TABLE
,
98 MONO_AOT_TABLE_WEAK_FIELD_INDEXES
,
102 /* This structure is stored in the AOT file */
103 typedef struct MonoAotFileInfo
105 /* The version number of the AOT file format, should match MONO_AOT_FILE_VERSION */
110 /* All the pointers should be at the start to avoid alignment problems */
112 #define MONO_AOT_FILE_INFO_FIRST_SYMBOL jit_got
113 /* Global Offset Table for JITted code */
115 /* Global Offset Table for LLVM code */
117 /* Mono EH Frame created by llc when using LLVM */
118 gpointer mono_eh_frame
;
119 /* Points to the get_method () function in the LLVM image or NULL */
120 gpointer llvm_get_method
;
121 /* Points to the get_unbox_tramp () function in the LLVM image or NULL */
122 gpointer llvm_get_unbox_tramp
;
123 gpointer jit_code_start
;
124 gpointer jit_code_end
;
125 gpointer method_addresses
;
126 gpointer llvm_unbox_tramp_indexes
;
127 gpointer llvm_unbox_trampolines
;
131 * One pointer for each entry in MonoAotFileTable.
135 gpointer class_name_table
;
136 gpointer class_info_offsets
;
137 gpointer method_info_offsets
;
138 gpointer ex_info_offsets
;
139 gpointer extra_method_info_offsets
;
140 gpointer extra_method_table
;
141 gpointer got_info_offsets
;
142 gpointer llvm_got_info_offsets
;
143 gpointer image_table
;
144 /* Points to an array of weak field indexes */
145 gpointer weak_field_indexes
;
148 /* The GUID of the assembly which the AOT image was generated from */
149 gpointer assembly_guid
;
151 * The runtime version string for AOT images generated using 'bind-to-runtime-version',
154 char *runtime_version
;
155 /* Blocks of various kinds of trampolines */
156 gpointer specific_trampolines
;
157 gpointer static_rgctx_trampolines
;
158 gpointer imt_trampolines
;
159 gpointer gsharedvt_arg_trampolines
;
160 gpointer ftnptr_arg_trampolines
;
161 gpointer unbox_arbitrary_trampolines
;
162 /* In static mode, points to a table of global symbols for trampolines etc */
164 /* Points to a string containing the assembly name*/
165 gpointer assembly_name
;
166 /* Start of Mono's Program Linkage Table */
168 /* End of Mono's Program Linkage Table */
170 gpointer unwind_info
;
171 /* Points to a table mapping methods to their unbox trampolines */
172 gpointer unbox_trampolines
;
173 /* Points to the end of the previous table */
174 gpointer unbox_trampolines_end
;
175 /* Points to a table of unbox trampoline addresses/offsets */
176 gpointer unbox_trampoline_addresses
;
177 #define MONO_AOT_FILE_INFO_LAST_SYMBOL unbox_trampoline_addresses
180 /* The index of the first GOT slot used by the PLT */
181 guint32 plt_got_offset_base
;
182 /* Number of entries in the GOT */
184 /* Number of entries in the PLT */
186 /* Number of methods */
188 /* Number of extra methods */
189 guint32 nextra_methods
;
190 /* A union of MonoAotFileFlags */
192 /* Optimization flags used to compile the module */
194 /* SIMD flags used to compile the module */
196 /* Index of the blob entry holding the GC used by this module */
197 gint32 gc_name_index
;
198 guint32 num_rgctx_fetch_trampolines
;
199 /* These are used for sanity checking when cross-compiling */
200 guint32 double_align
, long_align
, generic_tramp_num
, card_table_shift_bits
, card_table_mask
;
201 /* The page size used by trampoline pages */
202 guint32 tramp_page_size
;
204 * The number of GOT entries which need to be preinitialized when the
207 guint32 nshared_got_entries
;
208 /* The size of the data file, if MONO_AOT_FILE_FLAG_SEPARATE_DATA is set */
209 guint32 datafile_size
;
210 /* Number of entries in llvm_unbox_tramp_indexes */
211 guint32 llvm_unbox_tramp_num
;
212 /* Size of entries in llvm_unbox_tramp_indexes (2/4) */
213 guint32 llvm_unbox_tramp_elemsize
;
216 /* Offsets for tables inside the data file if MONO_AOT_FILE_FLAG_SEPARATE_DATA is set */
217 // FIXME: Sync with AOT
218 guint32 table_offsets
[MONO_AOT_TABLE_NUM
];
219 /* Number of trampolines */
220 guint32 num_trampolines
[MONO_AOT_TRAMP_NUM
];
221 /* The indexes of the first GOT slots used by the trampolines */
222 guint32 trampoline_got_offset_base
[MONO_AOT_TRAMP_NUM
];
223 /* The size of one trampoline */
224 guint32 trampoline_size
[MONO_AOT_TRAMP_NUM
];
225 /* The offset where the trampolines begin on a trampoline page */
226 guint32 tramp_page_code_offsets
[MONO_AOT_TRAMP_NUM
];
227 /* GUID of aot compilation */
231 /* Number of symbols in the MonoAotFileInfo structure */
232 #define MONO_AOT_FILE_INFO_NUM_SYMBOLS (((G_STRUCT_OFFSET (MonoAotFileInfo, MONO_AOT_FILE_INFO_LAST_SYMBOL) - G_STRUCT_OFFSET (MonoAotFileInfo, MONO_AOT_FILE_INFO_FIRST_SYMBOL)) / sizeof (gpointer)) + 1)
234 void mono_aot_init (void);
235 void mono_aot_cleanup (void);
236 gpointer
mono_aot_get_method (MonoDomain
*domain
,
237 MonoMethod
*method
, MonoError
*error
);
238 gpointer
mono_aot_get_method_from_token (MonoDomain
*domain
, MonoImage
*image
, guint32 token
, MonoError
*error
);
239 gboolean
mono_aot_is_got_entry (guint8
*code
, guint8
*addr
);
240 guint8
* mono_aot_get_plt_entry (guint8
*code
);
241 guint32
mono_aot_get_plt_info_offset (host_mgreg_t
*regs
, guint8
*code
);
242 gboolean
mono_aot_get_cached_class_info (MonoClass
*klass
, MonoCachedClassInfo
*res
);
243 gboolean
mono_aot_get_class_from_name (MonoImage
*image
, const char *name_space
, const char *name
, MonoClass
**klass
);
244 MonoJitInfo
* mono_aot_find_jit_info (MonoDomain
*domain
, MonoImage
*image
, gpointer addr
);
245 gpointer
mono_aot_plt_resolve (gpointer aot_module
, guint32 plt_info_offset
, guint8
*code
, MonoError
*error
);
246 void mono_aot_patch_plt_entry (guint8
*code
, guint8
*plt_entry
, gpointer
*got
, host_mgreg_t
*regs
, guint8
*addr
);
247 gpointer
mono_aot_get_method_from_vt_slot (MonoDomain
*domain
, MonoVTable
*vtable
, int slot
, MonoError
*error
);
248 gpointer
mono_aot_create_specific_trampoline (MonoImage
*image
, gpointer arg1
, MonoTrampolineType tramp_type
, MonoDomain
*domain
, guint32
*code_len
);
249 gpointer
mono_aot_get_trampoline (const char *name
);
250 gpointer
mono_aot_get_trampoline_full (const char *name
, MonoTrampInfo
**out_tinfo
);
251 gpointer
mono_aot_get_unbox_trampoline (MonoMethod
*method
, gpointer addr
);
252 gpointer
mono_aot_get_lazy_fetch_trampoline (guint32 slot
);
253 gpointer
mono_aot_get_static_rgctx_trampoline (gpointer ctx
, gpointer addr
);
254 gpointer
mono_aot_get_imt_trampoline (MonoVTable
*vtable
, MonoDomain
*domain
, MonoIMTCheckItem
**imt_entries
, int count
, gpointer fail_tramp
);
255 gpointer
mono_aot_get_gsharedvt_arg_trampoline(gpointer arg
, gpointer addr
);
256 gpointer
mono_aot_get_ftnptr_arg_trampoline (gpointer arg
, gpointer addr
);
257 gpointer
mono_aot_get_unbox_arbitrary_trampoline (gpointer addr
);
258 guint8
* mono_aot_get_unwind_info (MonoJitInfo
*ji
, guint32
*unwind_info_len
);
259 guint32
mono_aot_method_hash (MonoMethod
*method
);
260 gboolean
mono_aot_can_dedup (MonoMethod
*method
);
261 MonoMethod
* mono_aot_get_array_helper_from_wrapper (MonoMethod
*method
);
262 void mono_aot_set_make_unreadable (gboolean unreadable
);
263 gboolean
mono_aot_is_pagefault (void *ptr
);
264 void mono_aot_handle_pagefault (void *ptr
);
266 guint32
mono_aot_find_method_index (MonoMethod
*method
);
267 gboolean
mono_aot_init_llvmonly_method (gpointer amodule
, guint32 method_index
, MonoClass
*init_class
, MonoError
*error
);
268 GHashTable
*mono_aot_get_weak_field_indexes (MonoImage
*image
);
269 MonoAotMethodFlags
mono_aot_get_method_flags (guint8
*code
);
271 /* These are used to load the AOT data for aot images compiled with MONO_AOT_FILE_FLAG_SEPARATE_DATA */
273 * Return the AOT data for ASSEMBLY. SIZE is the size of the data. OUT_HANDLE should be set to a handle which is later
274 * passed to the free function.
276 typedef unsigned char* (*MonoLoadAotDataFunc
) (MonoAssembly
*assembly
, int size
, gpointer user_data
, void **out_handle
);
278 typedef void (*MonoFreeAotDataFunc
) (MonoAssembly
*assembly
, int size
, gpointer user_data
, void *handle
);
279 MONO_API
void mono_install_load_aot_data_hook (MonoLoadAotDataFunc load_func
, MonoFreeAotDataFunc free_func
, gpointer user_data
);
281 #endif /* __MONO_AOT_RUNTIME_H__ */