2 #ifndef __MONO_METADATA_H__
3 #define __MONO_METADATA_H__
7 #include <mono/metadata/blob.h>
8 #include <mono/metadata/row-indexes.h>
9 #include <mono/metadata/image.h>
12 #define MONO_ZERO_LEN_ARRAY 0
14 #define MONO_ZERO_LEN_ARRAY 1
17 #define MONO_TYPE_ISSTRUCT(t) (!(t)->byref && (((t)->type == MONO_TYPE_VALUETYPE && !(t)->data.klass->enumtype) || ((t)->type == MONO_TYPE_TYPEDBYREF)))
18 #define MONO_TYPE_IS_VOID(t) ((t) && ((t)->type == MONO_TYPE_VOID) && !(t)->byref)
19 #define MONO_TYPE_IS_POINTER(t) ((t) && (((t)->byref || ((t)->type == MONO_TYPE_I) || (t)->type == MONO_TYPE_STRING) || ((t)->type == MONO_TYPE_SZARRAY) || ((t)->type == MONO_TYPE_CLASS) || ((t)->type == MONO_TYPE_CLASS) || ((t)->type == MONO_TYPE_OBJECT) || ((t)->type == MONO_TYPE_ARRAY) || ((t)->type == MONO_TYPE_PTR)))
20 #define MONO_TYPE_IS_REFERENCE(t) ((t) && (((t)->type == MONO_TYPE_STRING) || ((t)->type == MONO_TYPE_SZARRAY) || ((t)->type == MONO_TYPE_CLASS) || ((t)->type == MONO_TYPE_OBJECT) || ((t)->type == MONO_TYPE_ARRAY)))
22 typedef struct _MonoClass MonoClass;
23 typedef struct _MonoDomain MonoDomain;
35 MONO_TABLE_INTERFACEIMPL,
36 MONO_TABLE_MEMBERREF, /* 0xa */
38 MONO_TABLE_CUSTOMATTRIBUTE,
39 MONO_TABLE_FIELDMARSHAL,
40 MONO_TABLE_DECLSECURITY,
41 MONO_TABLE_CLASSLAYOUT,
42 MONO_TABLE_FIELDLAYOUT, /* 0x10 */
43 MONO_TABLE_STANDALONESIG,
47 MONO_TABLE_PROPERTYMAP,
50 MONO_TABLE_METHODSEMANTICS,
51 MONO_TABLE_METHODIMPL,
52 MONO_TABLE_MODULEREF, /* 0x1a */
58 MONO_TABLE_ASSEMBLY, /* 0x20 */
59 MONO_TABLE_ASSEMBLYPROCESSOR,
60 MONO_TABLE_ASSEMBLYOS,
61 MONO_TABLE_ASSEMBLYREF,
62 MONO_TABLE_ASSEMBLYREFPROCESSOR,
63 MONO_TABLE_ASSEMBLYREFOS,
65 MONO_TABLE_EXPORTEDTYPE,
66 MONO_TABLE_MANIFESTRESOURCE,
67 MONO_TABLE_NESTEDCLASS,
68 MONO_TABLE_GENERICPARAM, /* 0x2a */
69 MONO_TABLE_METHODSPEC,
70 MONO_TABLE_GENERICPARAMCONSTRAINT
72 #define MONO_TABLE_LAST MONO_TABLE_GENERICPARAMCONSTRAINT
76 MONO_EXCEPTION_CLAUSE_NONE,
77 MONO_EXCEPTION_CLAUSE_FILTER,
78 MONO_EXCEPTION_CLAUSE_FINALLY,
79 MONO_EXCEPTION_CLAUSE_FAULT = 4
91 /* ECMA lamespec: the old spec had more info... */
93 MONO_NATIVE_BOOLEAN = 0x02, /* 4 bytes, 0 is false, != 0 is true */
94 MONO_NATIVE_I1 = 0x03,
95 MONO_NATIVE_U1 = 0x04,
96 MONO_NATIVE_I2 = 0x05,
97 MONO_NATIVE_U2 = 0x06,
98 MONO_NATIVE_I4 = 0x07,
99 MONO_NATIVE_U4 = 0x08,
100 MONO_NATIVE_I8 = 0x09,
101 MONO_NATIVE_U8 = 0x0a,
102 MONO_NATIVE_R4 = 0x0b,
103 MONO_NATIVE_R8 = 0x0c,
104 MONO_NATIVE_CURRENCY = 0x0f,
105 MONO_NATIVE_BSTR = 0x13, /* prefixed length, Unicode */
106 MONO_NATIVE_LPSTR = 0x14, /* ANSI, null terminated */
107 MONO_NATIVE_LPWSTR = 0x15, /* UNICODE, null terminated */
108 MONO_NATIVE_LPTSTR = 0x16, /* plattform dep., null terminated */
109 MONO_NATIVE_BYVALTSTR = 0x17,
110 MONO_NATIVE_IUNKNOWN = 0x19,
111 MONO_NATIVE_IDISPATCH = 0x1a,
112 MONO_NATIVE_STRUCT = 0x1b,
113 MONO_NATIVE_INTERFACE = 0x1c,
114 MONO_NATIVE_SAFEARRAY = 0x1d,
115 MONO_NATIVE_BYVALARRAY = 0x1e,
116 MONO_NATIVE_INT = 0x1f,
117 MONO_NATIVE_UINT = 0x20,
118 MONO_NATIVE_VBBYREFSTR = 0x22,
119 MONO_NATIVE_ANSIBSTR = 0x23, /* prefixed length, ANSI */
120 MONO_NATIVE_TBSTR = 0x24, /* prefixed length, plattform dep. */
121 MONO_NATIVE_VARIANTBOOL = 0x25,
122 MONO_NATIVE_FUNC = 0x26,
123 MONO_NATIVE_ASANY = 0x28,
124 MONO_NATIVE_LPARRAY = 0x2a,
125 MONO_NATIVE_LPSTRUCT = 0x2b,
126 MONO_NATIVE_CUSTOM = 0x2c,
127 MONO_NATIVE_ERROR = 0x2d,
128 MONO_NATIVE_MAX = 0x50 /* no info */
132 MONO_MARSHAL_CONV_NONE,
133 MONO_MARSHAL_CONV_BOOL_VARIANTBOOL,
134 MONO_MARSHAL_CONV_BOOL_I4,
135 MONO_MARSHAL_CONV_STR_BSTR,
136 MONO_MARSHAL_CONV_STR_LPSTR,
137 MONO_MARSHAL_CONV_LPSTR_STR,
138 MONO_MARSHAL_CONV_STR_LPWSTR,
139 MONO_MARSHAL_CONV_LPWSTR_STR,
140 MONO_MARSHAL_CONV_STR_LPTSTR,
141 MONO_MARSHAL_CONV_STR_ANSIBSTR,
142 MONO_MARSHAL_CONV_STR_TBSTR,
143 MONO_MARSHAL_CONV_STR_BYVALSTR,
144 MONO_MARSHAL_CONV_STR_BYVALWSTR,
145 MONO_MARSHAL_CONV_SB_LPSTR,
146 MONO_MARSHAL_CONV_SB_LPTSTR,
147 MONO_MARSHAL_CONV_SB_LPWSTR,
148 MONO_MARSHAL_CONV_LPSTR_SB,
149 MONO_MARSHAL_CONV_LPTSTR_SB,
150 MONO_MARSHAL_CONV_LPWSTR_SB,
151 MONO_MARSHAL_CONV_ARRAY_BYVALARRAY,
152 MONO_MARSHAL_CONV_ARRAY_SAVEARRAY,
153 MONO_MARSHAL_CONV_ARRAY_LPARRAY,
154 MONO_MARSHAL_CONV_OBJECT_INTERFACE,
155 MONO_MARSHAL_CONV_OBJECT_IDISPATCH,
156 MONO_MARSHAL_CONV_OBJECT_IUNKNOWN,
157 MONO_MARSHAL_CONV_OBJECT_STRUCT,
158 MONO_MARSHAL_CONV_DEL_FTN,
159 MONO_MARSHAL_CONV_STRARRAY_STRLPARRAY,
160 MONO_MARSHAL_FREE_ARRAY
164 MonoMarshalNative native;
167 MonoMarshalNative elem_type;
178 void mono_metadata_init (void);
180 void mono_metadata_decode_row (MonoTableInfo *t,
185 guint32 mono_metadata_decode_row_col (MonoTableInfo *t,
190 * This macro is used to extract the size of the table encoded in
191 * the size_bitfield of MonoTableInfo.
193 #define mono_metadata_table_size(bitfield,table) ((((bitfield) >> ((table)*2)) & 0x3) + 1)
194 #define mono_metadata_table_count(bitfield) ((bitfield) >> 24)
196 int mono_metadata_compute_size (MonoImage *meta,
198 guint32 *result_bitfield);
203 const char *mono_metadata_locate (MonoImage *meta, int table, int idx);
204 const char *mono_metadata_locate_token (MonoImage *meta, guint32 token);
206 const char *mono_metadata_string_heap (MonoImage *meta, guint32 table_index);
207 const char *mono_metadata_blob_heap (MonoImage *meta, guint32 table_index);
208 const char *mono_metadata_user_string (MonoImage *meta, guint32 table_index);
209 const char *mono_metadata_guid_heap (MonoImage *meta, guint32 table_index);
211 guint32 mono_metadata_typedef_from_field (MonoImage *meta, guint32 table_index);
212 guint32 mono_metadata_typedef_from_method (MonoImage *meta, guint32 table_index);
213 guint32 mono_metadata_nested_in_typedef (MonoImage *meta, guint32 table_index);
214 guint32 mono_metadata_nesting_typedef (MonoImage *meta, guint32 table_index, guint32 start_index);
216 MonoClass** mono_metadata_interfaces_from_typedef (MonoImage *meta, guint32 table_index, guint *count);
218 guint32 mono_metadata_events_from_typedef (MonoImage *meta, guint32 table_index, guint *end_idx);
219 guint32 mono_metadata_methods_from_event (MonoImage *meta, guint32 table_index, guint *end);
220 guint32 mono_metadata_properties_from_typedef (MonoImage *meta, guint32 table_index, guint *end);
221 guint32 mono_metadata_methods_from_property (MonoImage *meta, guint32 table_index, guint *end);
222 guint32 mono_metadata_packing_from_typedef (MonoImage *meta, guint32 table_index, guint32 *packing, guint32 *size);
223 const char* mono_metadata_get_marshal_info (MonoImage *meta, guint32 idx, gboolean is_field);
224 guint32 mono_metadata_custom_attrs_from_index (MonoImage *meta, guint32 index);
226 MonoMarshalSpec *mono_metadata_parse_marshal_spec (MonoImage *image, const char *ptr);
228 guint32 mono_metadata_implmap_from_method (MonoImage *meta, guint32 method_idx);
230 void mono_metadata_field_info (MonoImage *meta,
234 MonoMarshalSpec **marshal_spec);
236 guint32 mono_metadata_get_constant_index (MonoImage *meta, guint32 token, guint32 hint);
239 * Functions to extract information from the Blobs
241 guint32 mono_metadata_decode_value (const char *ptr,
243 guint32 mono_metadata_decode_blob_size (const char *ptr,
246 void mono_metadata_encode_value (guint32 value, char *bug, char **endbuf);
248 #define MONO_OFFSET_IN_CLAUSE(clause,offset) \
249 ((clause)->try_offset <= (offset) && (offset) < ((clause)->try_offset + (clause)->try_len))
250 #define MONO_OFFSET_IN_HANDLER(clause,offset) \
251 ((clause)->handler_offset <= (offset) && (offset) < ((clause)->handler_offset + (clause)->handler_len))
257 guint32 handler_offset;
259 guint32 token_or_filter;
260 } MonoExceptionClause;
262 typedef struct _MonoType MonoType;
263 typedef struct _MonoGenericInst MonoGenericInst;
264 typedef struct _MonoGenericParam MonoGenericParam;
265 typedef struct _MonoArrayType MonoArrayType;
266 typedef struct _MonoMethodSignature MonoMethodSignature;
269 unsigned int required : 1;
270 unsigned int token : 31;
273 struct _MonoArrayType {
284 MonoClass *klass; /* for VALUETYPE and CLASS */
285 MonoType *type; /* for PTR */
286 MonoArrayType *array; /* for ARRAY */
287 MonoMethodSignature *method;
288 MonoGenericParam *generic_param; /* for VAR and MVAR */
289 MonoGenericInst *generic_inst; /* for GENERICINST */
291 unsigned int attrs : 16; /* param attributes or field flags */
292 unsigned int type : 8; /* ElementTypeEnum */
293 unsigned int num_mods : 6; /* max 64 modifiers follow at the end */
294 unsigned int byref : 1;
295 unsigned int pinned : 1; /* valid when included in a local var signature */
296 MonoCustomMod modifiers [MONO_ZERO_LEN_ARRAY]; /* this may grow */
299 struct _MonoMethodSignature {
300 unsigned int hasthis : 1;
301 unsigned int explicit_this : 1;
302 unsigned int call_convention : 6;
303 unsigned int pinvoke : 1;
304 unsigned int ref_count : 23;
307 guint16 generic_param_count;
309 MonoType *params [MONO_ZERO_LEN_ARRAY];
314 const unsigned char *code;
316 unsigned int num_clauses : 15;
317 /* if num_locals != 0, then the following apply: */
318 unsigned int init_locals : 1;
320 MonoExceptionClause *clauses;
321 MonoGenericParam *gen_params;
322 MonoGenericInst *geninst;
323 MonoType *locals [MONO_ZERO_LEN_ARRAY];
335 guint32 mono_metadata_parse_typedef_or_ref (MonoImage *m,
338 int mono_metadata_parse_custom_mod (MonoImage *m,
342 MonoArrayType *mono_metadata_parse_array (MonoImage *m,
345 void mono_metadata_free_array (MonoArrayType *array);
346 MonoType *mono_metadata_parse_type (MonoImage *m,
347 MonoParseTypeMode mode,
351 MonoType *mono_metadata_parse_param (MonoImage *m,
354 MonoType *mono_metadata_parse_ret_type (MonoImage *m,
357 MonoType *mono_metadata_parse_field_type (MonoImage *m,
361 MonoType *mono_type_create_from_typespec (MonoImage *image,
363 void mono_metadata_free_type (MonoType *type);
364 int mono_type_size (MonoType *type,
366 int mono_type_stack_size (MonoType *type,
369 guint mono_metadata_type_hash (MonoType *t1);
370 gboolean mono_metadata_type_equal (MonoType *t1, MonoType *t2);
372 MonoMethodSignature *mono_metadata_signature_alloc (MonoImage *image, guint32 nparams);
374 MonoMethodSignature *mono_metadata_parse_signature (MonoImage *image,
377 MonoMethodSignature *mono_metadata_parse_method_signature (MonoImage *m,
381 void mono_metadata_free_method_signature (MonoMethodSignature *method);
383 gboolean mono_metadata_signature_equal (MonoMethodSignature *sig1,
384 MonoMethodSignature *sig2);
386 guint mono_signature_hash (MonoMethodSignature *sig);
388 MonoMethodHeader *mono_metadata_parse_mh (MonoImage *m, const char *ptr);
389 void mono_metadata_free_mh (MonoMethodHeader *mh);
392 mono_type_to_unmanaged (MonoType *type, MonoMarshalSpec *mspec,
393 gboolean as_field, gboolean unicode, MonoMarshalConv *conv);
396 * Makes a token based on a table and an index
398 #define mono_metadata_make_token(table,idx) (((table) << 24)| (idx))
401 * Returns the table index that this token encodes.
403 #define mono_metadata_token_table(token) ((token) >> 24)
406 * Returns the index that a token refers to
408 #define mono_metadata_token_index(token) ((token & 0xffffff))
411 #define mono_metadata_token_code(token) ((token & 0xff000000))
413 guint32 mono_metadata_token_from_dor (guint32 dor_index);
415 char *mono_guid_to_string (const guint8 *guid);
417 #endif /* __MONO_METADATA_H__ */