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_LPSTR_SB,
147 MONO_MARSHAL_CONV_ARRAY_BYVALARRAY,
148 MONO_MARSHAL_CONV_ARRAY_SAVEARRAY,
149 MONO_MARSHAL_CONV_ARRAY_LPARRAY,
150 MONO_MARSHAL_CONV_OBJECT_INTERFACE,
151 MONO_MARSHAL_CONV_OBJECT_IDISPATCH,
152 MONO_MARSHAL_CONV_OBJECT_IUNKNOWN,
153 MONO_MARSHAL_CONV_OBJECT_STRUCT,
154 MONO_MARSHAL_CONV_DEL_FTN,
155 MONO_MARSHAL_CONV_STRARRAY_STRLPARRAY,
156 MONO_MARSHAL_FREE_ARRAY
160 MonoMarshalNative native;
163 MonoMarshalNative elem_type;
174 void mono_metadata_init (void);
176 void mono_metadata_decode_row (MonoTableInfo *t,
181 guint32 mono_metadata_decode_row_col (MonoTableInfo *t,
186 * This macro is used to extract the size of the table encoded in
187 * the size_bitfield of MonoTableInfo.
189 #define mono_metadata_table_size(bitfield,table) ((((bitfield) >> ((table)*2)) & 0x3) + 1)
190 #define mono_metadata_table_count(bitfield) ((bitfield) >> 24)
192 int mono_metadata_compute_size (MonoImage *meta,
194 guint32 *result_bitfield);
199 const char *mono_metadata_locate (MonoImage *meta, int table, int idx);
200 const char *mono_metadata_locate_token (MonoImage *meta, guint32 token);
202 const char *mono_metadata_string_heap (MonoImage *meta, guint32 table_index);
203 const char *mono_metadata_blob_heap (MonoImage *meta, guint32 table_index);
204 const char *mono_metadata_user_string (MonoImage *meta, guint32 table_index);
205 const char *mono_metadata_guid_heap (MonoImage *meta, guint32 table_index);
207 guint32 mono_metadata_typedef_from_field (MonoImage *meta, guint32 table_index);
208 guint32 mono_metadata_typedef_from_method (MonoImage *meta, guint32 table_index);
209 guint32 mono_metadata_nested_in_typedef (MonoImage *meta, guint32 table_index);
210 guint32 mono_metadata_nesting_typedef (MonoImage *meta, guint32 table_index, guint32 start_index);
212 MonoClass** mono_metadata_interfaces_from_typedef (MonoImage *meta, guint32 table_index, guint *count);
214 guint32 mono_metadata_events_from_typedef (MonoImage *meta, guint32 table_index, guint *end_idx);
215 guint32 mono_metadata_methods_from_event (MonoImage *meta, guint32 table_index, guint *end);
216 guint32 mono_metadata_properties_from_typedef (MonoImage *meta, guint32 table_index, guint *end);
217 guint32 mono_metadata_methods_from_property (MonoImage *meta, guint32 table_index, guint *end);
218 guint32 mono_metadata_packing_from_typedef (MonoImage *meta, guint32 table_index, guint32 *packing, guint32 *size);
219 const char* mono_metadata_get_marshal_info (MonoImage *meta, guint32 idx, gboolean is_field);
220 guint32 mono_metadata_custom_attrs_from_index (MonoImage *meta, guint32 index);
222 MonoMarshalSpec *mono_metadata_parse_marshal_spec (MonoImage *image, const char *ptr);
224 guint32 mono_metadata_implmap_from_method (MonoImage *meta, guint32 method_idx);
226 void mono_metadata_field_info (MonoImage *meta,
230 MonoMarshalSpec **marshal_spec);
232 guint32 mono_metadata_get_constant_index (MonoImage *meta, guint32 token);
235 * Functions to extract information from the Blobs
237 guint32 mono_metadata_decode_value (const char *ptr,
239 guint32 mono_metadata_decode_blob_size (const char *ptr,
242 void mono_metadata_encode_value (guint32 value, char *bug, char **endbuf);
244 #define MONO_OFFSET_IN_CLAUSE(clause,offset) \
245 ((clause)->try_offset <= (offset) && (offset) < ((clause)->try_offset + (clause)->try_len))
246 #define MONO_OFFSET_IN_HANDLER(clause,offset) \
247 ((clause)->handler_offset <= (offset) && (offset) < ((clause)->handler_offset + (clause)->handler_len))
253 guint32 handler_offset;
255 guint32 token_or_filter;
256 } MonoExceptionClause;
258 typedef struct _MonoType MonoType;
259 typedef struct _MonoGenericInst MonoGenericInst;
260 typedef struct _MonoGenericParam MonoGenericParam;
261 typedef struct _MonoArrayType MonoArrayType;
262 typedef struct _MonoMethodSignature MonoMethodSignature;
265 unsigned int required : 1;
266 unsigned int token : 31;
269 struct _MonoArrayType {
280 MonoClass *klass; /* for VALUETYPE and CLASS */
281 MonoType *type; /* for PTR */
282 MonoArrayType *array; /* for ARRAY */
283 MonoMethodSignature *method;
284 MonoGenericParam *generic_param; /* for VAR and MVAR */
285 MonoGenericInst *generic_inst; /* for GENERICINST */
287 unsigned int attrs : 16; /* param attributes or field flags */
288 unsigned int type : 8; /* ElementTypeEnum */
289 unsigned int num_mods : 6; /* max 64 modifiers follow at the end */
290 unsigned int byref : 1;
291 unsigned int pinned : 1; /* valid when included in a local var signature */
292 MonoCustomMod modifiers [MONO_ZERO_LEN_ARRAY]; /* this may grow */
295 struct _MonoMethodSignature {
296 unsigned int hasthis : 1;
297 unsigned int explicit_this : 1;
298 unsigned int call_convention : 6;
299 unsigned int pinvoke : 1;
300 unsigned int ref_count : 23;
303 guint16 generic_param_count;
305 MonoType *params [MONO_ZERO_LEN_ARRAY];
310 const unsigned char *code;
312 unsigned int num_clauses : 15;
313 /* if num_locals != 0, then the following apply: */
314 unsigned int init_locals : 1;
316 MonoExceptionClause *clauses;
317 MonoGenericParam *gen_params;
318 MonoGenericInst *geninst;
319 MonoType *locals [MONO_ZERO_LEN_ARRAY];
331 guint32 mono_metadata_parse_typedef_or_ref (MonoImage *m,
334 int mono_metadata_parse_custom_mod (MonoImage *m,
338 MonoArrayType *mono_metadata_parse_array (MonoImage *m,
341 void mono_metadata_free_array (MonoArrayType *array);
342 MonoType *mono_metadata_parse_type (MonoImage *m,
343 MonoParseTypeMode mode,
347 MonoType *mono_metadata_parse_param (MonoImage *m,
350 MonoType *mono_metadata_parse_ret_type (MonoImage *m,
353 MonoType *mono_metadata_parse_field_type (MonoImage *m,
357 MonoType *mono_type_create_from_typespec (MonoImage *image,
359 void mono_metadata_free_type (MonoType *type);
360 int mono_type_size (MonoType *type,
362 int mono_type_stack_size (MonoType *type,
365 guint mono_metadata_type_hash (MonoType *t1);
366 gboolean mono_metadata_type_equal (MonoType *t1, MonoType *t2);
368 MonoMethodSignature *mono_metadata_signature_alloc (MonoImage *image, guint32 nparams);
370 MonoMethodSignature *mono_metadata_parse_signature (MonoImage *image,
373 MonoMethodSignature *mono_metadata_parse_method_signature (MonoImage *m,
377 void mono_metadata_free_method_signature (MonoMethodSignature *method);
379 gboolean mono_metadata_signature_equal (MonoMethodSignature *sig1,
380 MonoMethodSignature *sig2);
382 guint mono_signature_hash (MonoMethodSignature *sig);
384 MonoMethodHeader *mono_metadata_parse_mh (MonoImage *m, const char *ptr);
385 void mono_metadata_free_mh (MonoMethodHeader *mh);
388 mono_type_to_unmanaged (MonoType *type, MonoMarshalSpec *mspec,
389 gboolean as_field, gboolean unicode, MonoMarshalConv *conv);
392 * Makes a token based on a table and an index
394 #define mono_metadata_make_token(table,idx) (((table) << 24)| (idx))
397 * Returns the table index that this token encodes.
399 #define mono_metadata_token_table(token) ((token) >> 24)
402 * Returns the index that a token refers to
404 #define mono_metadata_token_index(token) ((token & 0xffffff))
407 #define mono_metadata_token_code(token) ((token & 0xff000000))
409 guint32 mono_metadata_token_from_dor (guint32 dor_index);
411 char *mono_guid_to_string (const guint8 *guid);
413 #endif /* __MONO_METADATA_H__ */