diff --git a/src/mono/mono/metadata/assembly.c b/src/mono/mono/metadata/assembly.c index 9766e932b9525f..41e60fb831a47a 100644 --- a/src/mono/mono/metadata/assembly.c +++ b/src/mono/mono/metadata/assembly.c @@ -653,7 +653,7 @@ mono_assembly_fill_assembly_name_full (MonoImage *image, MonoAssemblyName *aname guint32 cols [MONO_ASSEMBLY_SIZE]; gint32 machine, flags; - if (!t->rows) + if (!table_info_get_rows (t)) return FALSE; mono_metadata_decode_row (t, 0, cols, MONO_ASSEMBLY_SIZE); @@ -1237,8 +1237,9 @@ mono_assembly_load_reference (MonoImage *image, int index) if (!image->references) { MonoTableInfo *t = &image->tables [MONO_TABLE_ASSEMBLYREF]; - image->references = g_new0 (MonoAssembly *, t->rows + 1); - image->nreferences = t->rows; + int n = table_info_get_rows (t); + image->references = g_new0 (MonoAssembly *, n + 1); + image->nreferences = n; } reference = image->references [index]; mono_image_unlock (image); @@ -2334,7 +2335,7 @@ mono_assembly_request_load_from (MonoImage *image, const char *fname, predicate = req->predicate; user_data = req->predicate_ud; - if (!image->tables [MONO_TABLE_ASSEMBLY].rows) { + if (!table_info_get_rows (&image->tables [MONO_TABLE_ASSEMBLY])) { /* 'image' doesn't have a manifest -- maybe someone is trying to Assembly.Load a .netmodule */ *status = MONO_IMAGE_IMAGE_INVALID; return NULL; @@ -3685,7 +3686,8 @@ mono_assembly_has_skip_verification (MonoAssembly *assembly) t = &assembly->image->tables [MONO_TABLE_DECLSECURITY]; - for (i = 0; i < t->rows; ++i) { + int rows = table_info_get_rows (t); + for (i = 0; i < rows; ++i) { mono_metadata_decode_row (t, i, cols, MONO_DECL_SECURITY_SIZE); if ((cols [MONO_DECL_SECURITY_PARENT] & MONO_HAS_DECL_SECURITY_MASK) != MONO_HAS_DECL_SECURITY_ASSEMBLY) continue; diff --git a/src/mono/mono/metadata/class-init.c b/src/mono/mono/metadata/class-init.c index d92bef56d3ca73..f0c802a48264d0 100644 --- a/src/mono/mono/metadata/class-init.c +++ b/src/mono/mono/metadata/class-init.c @@ -433,7 +433,8 @@ mono_class_create_from_typedef (MonoImage *image, guint32 type_token, MonoError error_init (error); - if (mono_metadata_token_table (type_token) != MONO_TABLE_TYPEDEF || tidx > tt->rows) { + /* FIXME: metadata-update - this function needs extensive work */ + if (mono_metadata_token_table (type_token) != MONO_TABLE_TYPEDEF || tidx > table_info_get_rows (tt)) { mono_error_set_bad_image (error, image, "Invalid typedef token %x", type_token); return NULL; } @@ -620,19 +621,19 @@ mono_class_create_from_typedef (MonoImage *image, guint32 type_token, MonoError first_method_idx = cols [MONO_TYPEDEF_METHOD_LIST] - 1; mono_class_set_first_method_idx (klass, first_method_idx); - if (tt->rows > tidx){ + if (table_info_get_rows (tt) > tidx){ mono_metadata_decode_row (tt, tidx, cols_next, MONO_TYPEDEF_SIZE); field_last = cols_next [MONO_TYPEDEF_FIELD_LIST] - 1; method_last = cols_next [MONO_TYPEDEF_METHOD_LIST] - 1; } else { - field_last = image->tables [MONO_TABLE_FIELD].rows; - method_last = image->tables [MONO_TABLE_METHOD].rows; + field_last = table_info_get_rows (&image->tables [MONO_TABLE_FIELD]); + method_last = table_info_get_rows (&image->tables [MONO_TABLE_METHOD]); } if (cols [MONO_TYPEDEF_FIELD_LIST] && - cols [MONO_TYPEDEF_FIELD_LIST] <= image->tables [MONO_TABLE_FIELD].rows) + cols [MONO_TYPEDEF_FIELD_LIST] <= table_info_get_rows (&image->tables [MONO_TABLE_FIELD])) mono_class_set_field_count (klass, field_last - first_field_idx); - if (cols [MONO_TYPEDEF_METHOD_LIST] <= image->tables [MONO_TABLE_METHOD].rows) + if (cols [MONO_TYPEDEF_METHOD_LIST] <= table_info_get_rows (&image->tables [MONO_TABLE_METHOD])) mono_class_set_method_count (klass, method_last - first_method_idx); /* reserve space to store vector pointer in arrays */ diff --git a/src/mono/mono/metadata/class.c b/src/mono/mono/metadata/class.c index 6d42b3accdb4bf..2d472f7b4c8eee 100644 --- a/src/mono/mono/metadata/class.c +++ b/src/mono/mono/metadata/class.c @@ -2678,13 +2678,14 @@ mono_class_name_from_token (MonoImage *image, guint32 type_token) switch (type_token & 0xff000000){ case MONO_TOKEN_TYPE_DEF: { - guint32 cols [MONO_TYPEDEF_SIZE]; - MonoTableInfo *tt = &image->tables [MONO_TABLE_TYPEDEF]; guint tidx = mono_metadata_token_index (type_token); - if (tidx > tt->rows) + if (mono_metadata_table_bounds_check (image, MONO_TABLE_TYPEDEF, tidx)) return g_strdup_printf ("Invalid type token 0x%08x", type_token); + guint32 cols [MONO_TYPEDEF_SIZE]; + MonoTableInfo *tt = &image->tables [MONO_TABLE_TYPEDEF]; + mono_metadata_decode_row (tt, tidx - 1, cols, MONO_TYPEDEF_SIZE); name = mono_metadata_string_heap (image, cols [MONO_TYPEDEF_NAME]); nspace = mono_metadata_string_heap (image, cols [MONO_TYPEDEF_NAMESPACE]); @@ -2695,13 +2696,14 @@ mono_class_name_from_token (MonoImage *image, guint32 type_token) } case MONO_TOKEN_TYPE_REF: { - guint32 cols [MONO_TYPEREF_SIZE]; - MonoTableInfo *t = &image->tables [MONO_TABLE_TYPEREF]; guint tidx = mono_metadata_token_index (type_token); - if (tidx > t->rows) + if (mono_metadata_table_bounds_check (image, MONO_TABLE_TYPEREF, tidx)) return g_strdup_printf ("Invalid type token 0x%08x", type_token); + guint32 cols [MONO_TYPEREF_SIZE]; + MonoTableInfo *t = &image->tables [MONO_TABLE_TYPEREF]; + mono_metadata_decode_row (t, tidx-1, cols, MONO_TYPEREF_SIZE); name = mono_metadata_string_heap (image, cols [MONO_TYPEREF_NAME]); nspace = mono_metadata_string_heap (image, cols [MONO_TYPEREF_NAMESPACE]); @@ -2738,7 +2740,7 @@ mono_assembly_name_from_token (MonoImage *image, guint32 type_token) MonoTableInfo *t = &image->tables [MONO_TABLE_TYPEREF]; guint32 idx = mono_metadata_token_index (type_token); - if (idx > t->rows) + if (mono_metadata_table_bounds_check (image, MONO_TABLE_TYPEREF, idx)) return g_strdup_printf ("Invalid type token 0x%08x", type_token); mono_metadata_decode_row (t, idx-1, cols, MONO_TYPEREF_SIZE); @@ -2973,7 +2975,9 @@ mono_image_init_name_cache (MonoImage *image) /* Temporary hash table to avoid lookups in the nspace_table */ name_cache2 = g_hash_table_new (NULL, NULL); - for (i = 1; i <= t->rows; ++i) { + /* FIXME: metadata-update */ + int rows = table_info_get_rows (t); + for (i = 1; i <= rows; ++i) { mono_metadata_decode_row (t, i - 1, cols, MONO_TYPEDEF_SIZE); visib = cols [MONO_TYPEDEF_FLAGS] & TYPE_ATTRIBUTE_VISIBILITY_MASK; /* @@ -3002,7 +3006,8 @@ mono_image_init_name_cache (MonoImage *image) guint32 cols [MONO_EXP_TYPE_SIZE]; int i; - for (i = 0; i < t->rows; ++i) { + rows = table_info_get_rows (t); + for (i = 0; i < rows; ++i) { mono_metadata_decode_row (t, i, cols, MONO_EXP_TYPE_SIZE); guint32 impl = cols [MONO_EXP_TYPE_IMPLEMENTATION]; @@ -3191,7 +3196,8 @@ search_modules (MonoImage *image, const char *name_space, const char *name, gboo * Note: image->modules contains the contents of the MODULEREF table, while * the real module list is in the FILE table. */ - for (i = 0; i < file_table->rows; i++) { + int rows = table_info_get_rows (file_table); + for (i = 0; i < rows; i++) { guint32 cols [MONO_FILE_SIZE]; mono_metadata_decode_row (file_table, i, cols, MONO_FILE_SIZE); if (cols [MONO_FILE_FLAGS] == FILE_CONTAINS_NO_METADATA) @@ -3244,7 +3250,7 @@ mono_class_from_name_checked_aux (MonoImage *image, const char* name_space, cons /* FIXME: get_class_from_name () can't handle types in the EXPORTEDTYPE table */ // The AOT cache in get_class_from_name is case-sensitive, so don't bother with it for case-insensitive lookups - if (get_class_from_name && image->tables [MONO_TABLE_EXPORTEDTYPE].rows == 0 && case_sensitive) { + if (get_class_from_name && table_info_get_rows (&image->tables [MONO_TABLE_EXPORTEDTYPE]) == 0 && case_sensitive) { gboolean res = get_class_from_name (image, name_space, name, &klass); if (res) { if (!klass) { diff --git a/src/mono/mono/metadata/coree.c b/src/mono/mono/metadata/coree.c index 78794486cf7b26..0a364ed4880e5b 100644 --- a/src/mono/mono/metadata/coree.c +++ b/src/mono/mono/metadata/coree.c @@ -119,7 +119,7 @@ BOOL STDMETHODCALLTYPE _CorDllMain(HINSTANCE hInst, DWORD dwReason, LPVOID lpRes * loader trampolines should be used and assembly loading should * probably be delayed until the first call to an exported function. */ - if (image->tables [MONO_TABLE_ASSEMBLY].rows && image->image_info->cli_cli_header.ch_vtable_fixups.rva) { + if (table_info_get_rows (&image->tables [MONO_TABLE_ASSEMBLY]) && image->image_info->cli_cli_header.ch_vtable_fixups.rva) { MonoAssemblyOpenRequest req; mono_assembly_request_prepare_open (&req, MONO_ASMCTX_DEFAULT, alc); assembly = mono_assembly_request_open (file_name, &req, NULL); diff --git a/src/mono/mono/metadata/custom-attrs.c b/src/mono/mono/metadata/custom-attrs.c index 2763b008e32fbe..a51d89d1854c56 100644 --- a/src/mono/mono/metadata/custom-attrs.c +++ b/src/mono/mono/metadata/custom-attrs.c @@ -1623,6 +1623,8 @@ mono_custom_attrs_from_index_checked (MonoImage *image, guint32 idx, gboolean ig error_init (error); ca = &image->tables [MONO_TABLE_CUSTOMATTRIBUTE]; + /* FIXME: metadata-update */ + int rows = table_info_get_rows (ca); i = mono_metadata_custom_attrs_from_index (image, idx); if (!i) @@ -1630,7 +1632,7 @@ mono_custom_attrs_from_index_checked (MonoImage *image, guint32 idx, gboolean ig i --; // initial size chosen arbitrarily, but default is 16 which is rather small attr_array = g_array_sized_new (TRUE, TRUE, sizeof (guint32), 128); - while (i < ca->rows) { + while (i < rows) { if (mono_metadata_decode_row_col (ca, i, MONO_CUSTOM_ATTR_PARENT) != idx) break; attr_array = g_array_append_val (attr_array, i); @@ -1978,14 +1980,16 @@ mono_custom_attrs_from_param_checked (MonoMethod *method, guint32 param, MonoErr return NULL; ca = &image->tables [MONO_TABLE_METHOD]; + /* FIXME: metadata-update */ param_list = mono_metadata_decode_row_col (ca, method_index - 1, MONO_METHOD_PARAMLIST); - if (method_index == ca->rows) { - ca = &image->tables [MONO_TABLE_PARAM]; - param_last = ca->rows + 1; + int rows = table_info_get_rows (ca); + if (method_index == rows) { + param_last = rows + 1; } else { param_last = mono_metadata_decode_row_col (ca, method_index, MONO_METHOD_PARAMLIST); - ca = &image->tables [MONO_TABLE_PARAM]; } + ca = &image->tables [MONO_TABLE_PARAM]; + found = FALSE; for (i = param_list; i < param_last; ++i) { param_pos = mono_metadata_decode_row_col (ca, i - 1, MONO_PARAM_SEQUENCE); @@ -2345,7 +2349,7 @@ custom_attr_class_name_from_methoddef (MonoImage *image, guint32 method_token, c guint32 cols [MONO_TYPEDEF_SIZE]; guint tidx = mono_metadata_token_index (type_token); - if (mono_metadata_token_table (type_token) != MONO_TABLE_TYPEDEF || tidx > tt->rows) { + if (mono_metadata_token_table (type_token) != MONO_TABLE_TYPEDEF || mono_metadata_table_bounds_check (image, MONO_TABLE_TYPEDEF, tidx)) { /* "Invalid typedef token %x", type_token */ return FALSE; } @@ -2485,7 +2489,8 @@ metadata_foreach_custom_attr_from_index (MonoImage *image, guint32 idx, MonoAsse return; i --; gboolean stop_iterating = FALSE; - while (!stop_iterating && i < ca->rows) { + int rows = table_info_get_rows (ca); + while (!stop_iterating && i < rows) { if (mono_metadata_decode_row_col (ca, i, MONO_CUSTOM_ATTR_PARENT) != idx) break; mono_metadata_decode_row (ca, i, cols, MONO_CUSTOM_ATTR_SIZE); @@ -2600,7 +2605,8 @@ init_weak_fields_inner (MonoImage *image, GHashTable *indexes) tdef = &image->tables [MONO_TABLE_CUSTOMATTRIBUTE]; guint32 parent, field_idx, col, mtoken, idx; - for (int i = 0; i < tdef->rows; ++i) { + int rows = table_info_get_rows (tdef); + for (int i = 0; i < rows; ++i) { parent = mono_metadata_decode_row_col (tdef, i, MONO_CUSTOM_ATTR_PARENT); if ((parent & MONO_CUSTOM_ATTR_MASK) != MONO_CUSTOM_ATTR_FIELDDEF) continue; @@ -2616,13 +2622,16 @@ init_weak_fields_inner (MonoImage *image, GHashTable *indexes) } } } else { + /* FIXME: metadata-update */ + /* Memberref pointing to a typeref */ tdef = &image->tables [MONO_TABLE_MEMBERREF]; /* Check whenever the assembly references the WeakAttribute type */ gboolean found = FALSE; tdef = &image->tables [MONO_TABLE_TYPEREF]; - for (int i = 0; i < tdef->rows; ++i) { + int rows = table_info_get_rows (tdef); + for (int i = 0; i < rows; ++i) { guint32 string_offset = mono_metadata_decode_row_col (tdef, i, MONO_TYPEREF_NAME); const char *name = mono_metadata_string_heap (image, string_offset); if (!strcmp (name, "WeakAttribute")) { @@ -2636,7 +2645,8 @@ init_weak_fields_inner (MonoImage *image, GHashTable *indexes) /* Find the memberref pointing to a typeref */ tdef = &image->tables [MONO_TABLE_MEMBERREF]; - for (int i = 0; i < tdef->rows; ++i) { + rows = table_info_get_rows (tdef); + for (int i = 0; i < rows; ++i) { guint32 cols [MONO_MEMBERREF_SIZE]; const char *sig; @@ -2686,7 +2696,8 @@ init_weak_fields_inner (MonoImage *image, GHashTable *indexes) tdef = &image->tables [MONO_TABLE_CUSTOMATTRIBUTE]; guint32 parent, field_idx, col, mtoken, idx; - for (int i = 0; i < tdef->rows; ++i) { + rows = table_info_get_rows (tdef); + for (int i = 0; i < rows; ++i) { parent = mono_metadata_decode_row_col (tdef, i, MONO_CUSTOM_ATTR_PARENT); if ((parent & MONO_CUSTOM_ATTR_MASK) != MONO_CUSTOM_ATTR_FIELDDEF) continue; diff --git a/src/mono/mono/metadata/debug-mono-ppdb.c b/src/mono/mono/metadata/debug-mono-ppdb.c index b4b42fa645829f..070f9b8b0cf280 100644 --- a/src/mono/mono/metadata/debug-mono-ppdb.c +++ b/src/mono/mono/metadata/debug-mono-ppdb.c @@ -158,7 +158,7 @@ mono_ppdb_load_file (MonoImage *image, const guint8 *raw_contents, int size) int ppdb_size = 0, ppdb_compressed_size = 0; gboolean is_embedded_ppdb = FALSE; - if (image->tables [MONO_TABLE_DOCUMENT].rows) { + if (table_info_get_rows (&image->tables [MONO_TABLE_DOCUMENT])) { /* Embedded ppdb */ mono_image_addref (image); return create_ppdb_file (image, TRUE); @@ -490,16 +490,16 @@ mono_ppdb_get_seq_points (MonoDebugMethodInfo *minfo, char **source_file, GPtrAr if (source_files) sindexes = g_ptr_array_new (); - if (!method->token || tables [MONO_TABLE_METHODBODY].rows == 0) + if (!method->token || table_info_get_rows (&tables [MONO_TABLE_METHODBODY]) == 0) return; method_idx = mono_metadata_token_index (method->token); MonoTableInfo *methodbody_table = &tables [MONO_TABLE_METHODBODY]; - if (G_UNLIKELY (method_idx - 1 >= methodbody_table->rows)) { + if (G_UNLIKELY (method_idx - 1 >= table_info_get_rows (methodbody_table))) { char *method_name = mono_method_full_name (method, FALSE); g_error ("Method idx %d is greater than number of rows (%d) in PPDB MethodDebugInformation table, for method %s in '%s'. Likely a malformed PDB file.", - method_idx - 1, methodbody_table->rows, method_name, image->name); + method_idx - 1, table_info_get_rows (methodbody_table), method_name, image->name); g_free (method_name); } mono_metadata_decode_row (methodbody_table, method_idx - 1, cols, MONO_METHODBODY_SIZE); @@ -641,7 +641,8 @@ mono_ppdb_lookup_locals (MonoDebugMethodInfo *minfo) // this endpoint becomes locals_end_idx below // March to the last scope that is in this method - while (scope_idx <= tables [MONO_TABLE_LOCALSCOPE].rows) { + int rows = table_info_get_rows (&tables [MONO_TABLE_LOCALSCOPE]); + while (scope_idx <= rows) { mono_metadata_decode_row (&tables [MONO_TABLE_LOCALSCOPE], scope_idx-1, cols, MONO_LOCALSCOPE_SIZE); if (cols [MONO_LOCALSCOPE_METHOD] != method_idx) break; @@ -654,8 +655,8 @@ mono_ppdb_lookup_locals (MonoDebugMethodInfo *minfo) // Ends with "the last row of the LocalVariable table" // this happens if the above loop marched one past the end // of the rows - if (scope_idx > tables [MONO_TABLE_LOCALSCOPE].rows) { - locals_end_idx = tables [MONO_TABLE_LOCALVARIABLE].rows + 1; + if (scope_idx > table_info_get_rows (&tables [MONO_TABLE_LOCALSCOPE])) { + locals_end_idx = table_info_get_rows (&tables [MONO_TABLE_LOCALVARIABLE]) + 1; } else { // Ends with "the next run of LocalVariables, // found by inspecting the VariableList of the next row in this LocalScope table." @@ -674,8 +675,8 @@ mono_ppdb_lookup_locals (MonoDebugMethodInfo *minfo) mono_metadata_decode_row (&tables [MONO_TABLE_LOCALSCOPE], scope_idx-1, cols, MONO_LOCALSCOPE_SIZE); locals_idx = cols [MONO_LOCALSCOPE_VARIABLELIST]; - if (scope_idx == tables [MONO_TABLE_LOCALSCOPE].rows) { - locals_end_idx = tables [MONO_TABLE_LOCALVARIABLE].rows + 1; + if (scope_idx == table_info_get_rows (&tables [MONO_TABLE_LOCALSCOPE])) { + locals_end_idx = table_info_get_rows (&tables [MONO_TABLE_LOCALVARIABLE]) + 1; } else { locals_end_idx = mono_metadata_decode_row_col (&tables [MONO_TABLE_LOCALSCOPE], scope_idx-1 + 1, MONO_LOCALSCOPE_VARIABLELIST); } @@ -756,7 +757,7 @@ lookup_custom_debug_information (MonoImage* image, guint32 token, uint8_t parent loc.col_idx = MONO_CUSTOMDEBUGINFORMATION_PARENT; loc.t = table; - if (!mono_binary_search (&loc, table->base, table->rows, table->row_size, table_locator)) + if (!mono_binary_search (&loc, table->base, table_info_get_rows (table), table->row_size, table_locator)) return NULL; // Great we found one of possibly many CustomDebugInformations of this entity they are distinguished by KIND guid // First try on this index found by binary search...(it's most likeley to be only one and binary search found the one we want) @@ -764,7 +765,8 @@ lookup_custom_debug_information (MonoImage* image, guint32 token, uint8_t parent return mono_metadata_blob_heap (image, mono_metadata_decode_row_col (table, loc.result, MONO_CUSTOMDEBUGINFORMATION_VALUE)); // Move forward from binary found index, until parent token differs - for (int i = loc.result + 1; i < table->rows; i++) + int rows = table_info_get_rows (table); + for (int i = loc.result + 1; i < rows; i++) { if (mono_metadata_decode_row_col (table, i, MONO_CUSTOMDEBUGINFORMATION_PARENT) != loc.idx) break; diff --git a/src/mono/mono/metadata/icall.c b/src/mono/mono/metadata/icall.c index 138fcac9b04eb6..815faa8bace508 100644 --- a/src/mono/mono/metadata/icall.c +++ b/src/mono/mono/metadata/icall.c @@ -4590,11 +4590,13 @@ ves_icall_System_Reflection_RuntimeAssembly_GetManifestResourceNames (MonoReflec { MonoAssembly *assembly = MONO_HANDLE_GETVAL (assembly_h, assembly); MonoTableInfo *table = &assembly->image->tables [MONO_TABLE_MANIFESTRESOURCE]; - MonoArrayHandle result = mono_array_new_handle (mono_defaults.string_class, table->rows, error); + /* FIXME: metadata-update */ + int rows = table_info_get_rows (table); + MonoArrayHandle result = mono_array_new_handle (mono_defaults.string_class, rows, error); goto_if_nok (error, fail); int i; - for (i = 0; i < table->rows; ++i) { + for (i = 0; i < rows; ++i) { if (!add_manifest_resource_name_to_array (assembly->image, table, i, result, error)) goto fail; } @@ -4634,13 +4636,15 @@ ves_icall_System_Reflection_Assembly_InternalGetReferencedAssemblies (MonoReflec MonoImage *image = ass->image; int count; + /* FIXME: metadata-update */ + if (image_is_dynamic (ass->image)) { MonoDynamicTable *t = &(((MonoDynamicImage*) image)->tables [MONO_TABLE_ASSEMBLYREF]); count = t->rows; } else { MonoTableInfo *t = &image->tables [MONO_TABLE_ASSEMBLYREF]; - count = t->rows; + count = table_info_get_rows (t); } GPtrArray *result = g_ptr_array_sized_new (count); @@ -4729,14 +4733,16 @@ get_manifest_resource_internal (MonoReflectionAssemblyHandle assembly_h, MonoStr char *n = mono_string_handle_to_utf8 (name, error); return_val_if_nok (error, NULL); - for (i = 0; i < table->rows; ++i) { + /* FIXME: metadata update */ + int rows = table_info_get_rows (table); + for (i = 0; i < rows; ++i) { mono_metadata_decode_row (table, i, cols, MONO_MANIFEST_SIZE); val = mono_metadata_string_heap (assembly->image, cols [MONO_MANIFEST_NAME]); if (strcmp (val, n) == 0) break; } g_free (n); - if (i == table->rows) + if (i == rows) return NULL; /* FIXME */ impl = cols [MONO_MANIFEST_IMPLEMENTATION]; @@ -4794,14 +4800,15 @@ get_manifest_resource_info_internal (MonoReflectionAssemblyHandle assembly_h, Mo n = mono_string_handle_to_utf8 (name, error); goto_if_nok (error, leave); - for (i = 0; i < table->rows; ++i) { + int rows = table_info_get_rows (table); + for (i = 0; i < rows; ++i) { mono_metadata_decode_row (table, i, cols, MONO_MANIFEST_SIZE); val = mono_metadata_string_heap (assembly->image, cols [MONO_MANIFEST_NAME]); if (strcmp (val, n) == 0) break; } g_free (n); - if (i == table->rows) + if (i == rows) goto leave; if (!cols [MONO_MANIFEST_IMPLEMENTATION]) { @@ -4880,12 +4887,13 @@ ves_icall_System_Reflection_RuntimeAssembly_GetFilesInternal (MonoReflectionAsse MonoTableInfo *table = &assembly->image->tables [MONO_TABLE_FILE]; int i, count; + int rows = table_info_get_rows (table); /* check hash if needed */ if (!MONO_HANDLE_IS_NULL(name)) { char *n = mono_string_handle_to_utf8 (name, error); goto_if_nok (error, fail); - for (i = 0; i < table->rows; ++i) { + for (i = 0; i < rows; ++i) { const char *val = mono_metadata_string_heap (assembly->image, mono_metadata_decode_row_col (table, i, MONO_FILE_NAME)); if (strcmp (val, n) == 0) { g_free (n); @@ -4901,7 +4909,7 @@ ves_icall_System_Reflection_RuntimeAssembly_GetFilesInternal (MonoReflectionAsse } count = 0; - for (i = 0; i < table->rows; ++i) { + for (i = 0; i < rows; ++i) { if (resource_modules || !(mono_metadata_decode_row_col (table, i, MONO_FILE_FLAGS) & FILE_CONTAINS_NO_METADATA)) count ++; } @@ -4911,7 +4919,7 @@ ves_icall_System_Reflection_RuntimeAssembly_GetFilesInternal (MonoReflectionAsse goto_if_nok (error, fail); count = 0; - for (i = 0; i < table->rows; ++i) { + for (i = 0; i < rows; ++i) { if (resource_modules || !(mono_metadata_decode_row_col (table, i, MONO_FILE_FLAGS) & FILE_CONTAINS_NO_METADATA)) { if (!add_filename_to_files_array (assembly, table, i, result, count, error)) goto fail; @@ -4984,7 +4992,7 @@ ves_icall_System_Reflection_RuntimeAssembly_GetModulesInternal (MonoReflectionAs g_assert (!assembly_is_dynamic (assembly)); table = &image->tables [MONO_TABLE_FILE]; - file_count = table->rows; + file_count = table_info_get_rows (table); modules = image->modules; module_count = image->module_count; @@ -5284,7 +5292,9 @@ image_get_type (MonoImage *image, MonoTableInfo *tdef, int table_idx, int count, static MonoArrayHandle mono_module_get_types (MonoImage *image, MonoArrayHandleOut exceptions, MonoBoolean exportedOnly, MonoError *error) { + /* FIXME: metadata-update */ MonoTableInfo *tdef = &image->tables [MONO_TABLE_TYPEDEF]; + int rows = table_info_get_rows (tdef); int i, count; error_init (error); @@ -5292,19 +5302,19 @@ mono_module_get_types (MonoImage *image, MonoArrayHandleOut exceptions, MonoBool /* we start the count from 1 because we skip the special type */ if (exportedOnly) { count = 0; - for (i = 1; i < tdef->rows; ++i) { + for (i = 1; i < rows; ++i) { if (mono_module_type_is_visible (tdef, image, i + 1)) count++; } } else { - count = tdef->rows - 1; + count = rows - 1; } MonoArrayHandle res = mono_array_new_handle (mono_defaults.runtimetype_class, count, error); return_val_if_nok (error, NULL_HANDLE_ARRAY); MONO_HANDLE_ASSIGN (exceptions, mono_array_new_handle (mono_defaults.exception_class, count, error)); return_val_if_nok (error, NULL_HANDLE_ARRAY); count = 0; - for (i = 1; i < tdef->rows; ++i) { + for (i = 1; i < rows; ++i) { if (!exportedOnly || mono_module_type_is_visible (tdef, image, i+1)) { image_get_type (image, tdef, i + 1, count, res, exceptions, exportedOnly, error); return_val_if_nok (error, NULL_HANDLE_ARRAY); @@ -5376,7 +5386,8 @@ assembly_get_types (MonoReflectionAssemblyHandle assembly_handle, MonoBoolean ex return_val_if_nok (error, NULL_HANDLE_ARRAY); /* Append data from all modules in the assembly */ - for (i = 0; i < table->rows; ++i) { + int rows = table_info_get_rows (table); + for (i = 0; i < rows; ++i) { if (!(mono_metadata_decode_row_col (table, i, MONO_FILE_FLAGS) & FILE_CONTAINS_NO_METADATA)) { MonoImage *loaded_image = mono_assembly_load_module_checked (image->assembly, i + 1, error); return_val_if_nok (error, NULL_HANDLE_ARRAY); @@ -5520,7 +5531,8 @@ ves_icall_System_Reflection_RuntimeAssembly_GetTopLevelForwardedTypes (MonoRefle g_assert (!assembly_is_dynamic (assembly)); MonoTableInfo *table = &image->tables [MONO_TABLE_EXPORTEDTYPE]; - for (int i = 0; i < table->rows; ++i) { + int rows = table_info_get_rows (table); + for (int i = 0; i < rows; ++i) { if (mono_metadata_decode_row_col (table, i, MONO_EXP_TYPE_FLAGS) & TYPE_ATTRIBUTE_FORWARDER) count ++; } @@ -5532,7 +5544,7 @@ ves_icall_System_Reflection_RuntimeAssembly_GetTopLevelForwardedTypes (MonoRefle int aindex = 0; int exception_count = 0; - for (int i = 0; i < table->rows; ++i) { + for (int i = 0; i < rows; ++i) { get_top_level_forwarded_type (image, table, i, types, exceptions, &aindex, &exception_count); } @@ -5929,15 +5941,15 @@ static gboolean mono_memberref_is_method (MonoImage *image, guint32 token) { if (!image_is_dynamic (image)) { - guint32 cols [MONO_MEMBERREF_SIZE]; - const char *sig; - const MonoTableInfo *table = &image->tables [MONO_TABLE_MEMBERREF]; - int idx = mono_metadata_token_index (token) - 1; - if (idx < 0 || table->rows <= idx) { + int idx = mono_metadata_token_index (token); + if (idx <= 0 || mono_metadata_table_bounds_check (image, MONO_TABLE_MEMBERREF, idx)) { return FALSE; } - mono_metadata_decode_row (table, idx, cols, MONO_MEMBERREF_SIZE); - sig = mono_metadata_blob_heap (image, cols [MONO_MEMBERREF_SIGNATURE]); + + guint32 cols [MONO_MEMBERREF_SIZE]; + const MonoTableInfo *table = &image->tables [MONO_TABLE_MEMBERREF]; + mono_metadata_decode_row (table, idx - 1, cols, MONO_MEMBERREF_SIZE); + const char *sig = mono_metadata_blob_heap (image, cols [MONO_MEMBERREF_SIGNATURE]); mono_metadata_decode_blob_size (sig, &sig); return (*sig != 0x6); } else { @@ -6029,7 +6041,7 @@ module_resolve_type_token (MonoImage *image, guint32 token, MonoArrayHandle type goto leave; } - if ((index <= 0) || (index > image->tables [table].rows)) { + if ((index <= 0) || mono_metadata_table_bounds_check (image, table, index)) { *resolve_error = ResolveTokenError_OutOfRange; goto leave; } @@ -6091,7 +6103,7 @@ module_resolve_method_token (MonoImage *image, guint32 token, MonoArrayHandle ty goto leave; } - if ((index <= 0) || (index > image->tables [table].rows)) { + if ((index <= 0) || mono_metadata_table_bounds_check (image, table, index)) { *resolve_error = ResolveTokenError_OutOfRange; goto leave; } @@ -6183,7 +6195,7 @@ module_resolve_field_token (MonoImage *image, guint32 token, MonoArrayHandle typ goto leave; } - if ((index <= 0) || (index > image->tables [table].rows)) { + if ((index <= 0) || mono_metadata_table_bounds_check (image, table, index)) { *resolve_error = ResolveTokenError_OutOfRange; goto leave; } @@ -6282,7 +6294,7 @@ ves_icall_System_Reflection_RuntimeModule_ResolveSignature (MonoImage *image, gu if (image_is_dynamic (image)) return NULL_HANDLE_ARRAY; - if ((idx == 0) || (idx > tables [MONO_TABLE_STANDALONESIG].rows)) + if ((idx == 0) || mono_metadata_table_bounds_check (image, MONO_TABLE_STANDALONESIG, idx)) return NULL_HANDLE_ARRAY; sig = mono_metadata_decode_row_col (&tables [MONO_TABLE_STANDALONESIG], idx - 1, 0); diff --git a/src/mono/mono/metadata/image.c b/src/mono/mono/metadata/image.c index e45d9c5068d81d..6c98a85f2fd958 100644 --- a/src/mono/mono/metadata/image.c +++ b/src/mono/mono/metadata/image.c @@ -622,13 +622,13 @@ load_tables (MonoImage *image) if ((valid_mask & ((guint64) 1 << table)) == 0){ if (table > MONO_TABLE_LAST) continue; - image->tables [table].rows = 0; + image->tables [table].rows_ = 0; continue; } if (table > MONO_TABLE_LAST) { g_warning("bits in valid must be zero above 0x37 (II - 23.1.6)"); } else { - image->tables [table].rows = read32 (rows); + image->tables [table].rows_ = read32 (rows); } rows++; valid++; @@ -680,16 +680,16 @@ mono_image_check_for_module_cctor (MonoImage *image) image->checked_module_cctor = TRUE; return; } - if (t->rows >= 1) { + if (table_info_get_rows (t) >= 1) { guint32 nameidx = mono_metadata_decode_row_col (t, 0, MONO_TYPEDEF_NAME); const char *name = mono_metadata_string_heap (image, nameidx); if (strcmp (name, "") == 0) { guint32 first_method = mono_metadata_decode_row_col (t, 0, MONO_TYPEDEF_METHOD_LIST) - 1; guint32 last_method; - if (t->rows > 1) + if (table_info_get_rows (t) > 1) last_method = mono_metadata_decode_row_col (t, 1, MONO_TYPEDEF_METHOD_LIST) - 1; else - last_method = mt->rows; + last_method = table_info_get_rows (mt); for (; first_method < last_method; first_method++) { nameidx = mono_metadata_decode_row_col (mt, first_method, MONO_METHOD_NAME); name = mono_metadata_string_heap (image, nameidx); @@ -1114,7 +1114,7 @@ void mono_image_load_names (MonoImage *image) { /* modules don't have an assembly table row */ - if (image->tables [MONO_TABLE_ASSEMBLY].rows) { + if (table_info_get_rows (&image->tables [MONO_TABLE_ASSEMBLY])) { image->assembly_name = mono_metadata_string_heap (image, mono_metadata_decode_row_col (&image->tables [MONO_TABLE_ASSEMBLY], 0, MONO_ASSEMBLY_NAME)); @@ -1124,7 +1124,7 @@ mono_image_load_names (MonoImage *image) /* Minimal ENC delta images index the combined string heap of the base and delta image, * so the module index is out of bounds here. */ - if (image->tables [MONO_TABLE_MODULE].rows && !image->minimal_delta) { + if (table_info_get_rows (&image->tables [MONO_TABLE_MODULE]) && !image->minimal_delta) { image->module_name = mono_metadata_string_heap (image, mono_metadata_decode_row_col (&image->tables [MONO_TABLE_MODULE], 0, MONO_MODULE_NAME)); @@ -1186,12 +1186,12 @@ static void dump_encmap (MonoImage *image) { MonoTableInfo *encmap = &image->tables [MONO_TABLE_ENCMAP]; - if (!encmap || !encmap->rows) + if (!encmap || !table_info_get_rows (encmap)) return; if (mono_trace_is_traced (G_LOG_LEVEL_DEBUG, MONO_TRACE_METADATA_UPDATE)) { mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_METADATA_UPDATE, "ENCMAP for %s", image->filename); - for (int i = 0; i < encmap->rows; ++i) { + for (int i = 0; i < table_info_get_rows (encmap); ++i) { guint32 cols [MONO_ENCMAP_SIZE]; mono_metadata_decode_row (encmap, i, cols, MONO_ENCMAP_SIZE); int token = cols [MONO_ENCMAP_TOKEN]; @@ -2626,7 +2626,7 @@ mono_image_load_file_for_image_checked (MonoImage *image, int fileidx, MonoError error_init (error); - if (fileidx < 1 || fileidx > t->rows) + if (fileidx < 1 || fileidx > table_info_get_rows (t)) return NULL; mono_image_lock (image); @@ -2665,8 +2665,9 @@ mono_image_load_file_for_image_checked (MonoImage *image, int fileidx, MonoError } if (!image->files) { - image->files = g_new0 (MonoImage*, t->rows); - image->file_count = t->rows; + int n = table_info_get_rows (t); + image->files = g_new0 (MonoImage*, n); + image->file_count = n; } image->files [fileidx - 1] = res; mono_image_unlock (image); @@ -2773,7 +2774,7 @@ mono_image_get_public_key (MonoImage *image, guint32 *size) *size = ((MonoDynamicImage*)image)->public_key_len; return (char*)((MonoDynamicImage*)image)->public_key; } - if (image->tables [MONO_TABLE_ASSEMBLY].rows != 1) + if (table_info_get_rows (&image->tables [MONO_TABLE_ASSEMBLY]) != 1) return NULL; tok = mono_metadata_decode_row_col (&image->tables [MONO_TABLE_ASSEMBLY], 0, MONO_ASSEMBLY_PUBLIC_KEY); if (!tok) @@ -2836,7 +2837,7 @@ mono_image_get_table_rows (MonoImage *image, int table_id) { if (table_id < 0 || table_id >= MONO_TABLE_NUM) return 0; - return image->tables [table_id].rows; + return table_info_get_rows (&image->tables [table_id]); } /** @@ -2845,7 +2846,7 @@ mono_image_get_table_rows (MonoImage *image, int table_id) int mono_table_info_get_rows (const MonoTableInfo *table) { - return table->rows; + return table_info_get_rows (table); } /** diff --git a/src/mono/mono/metadata/loader.c b/src/mono/mono/metadata/loader.c index 1b473b075f6109..2d6ff56839ff94 100644 --- a/src/mono/mono/metadata/loader.c +++ b/src/mono/mono/metadata/loader.c @@ -1476,10 +1476,10 @@ mono_method_get_param_names (MonoMethod *method, const char **names) param_index = mono_metadata_decode_row_col (methodt, idx - 1, MONO_METHOD_PARAMLIST); - if (idx < methodt->rows) + if (idx < table_info_get_rows (methodt)) lastp = mono_metadata_decode_row_col (methodt, idx, MONO_METHOD_PARAMLIST); else - lastp = paramt->rows + 1; + lastp = table_info_get_rows (paramt) + 1; for (i = param_index; i < lastp; ++i) { mono_metadata_decode_row (paramt, i -1, cols, MONO_PARAM_SIZE); if (cols [MONO_PARAM_SEQUENCE] && cols [MONO_PARAM_SEQUENCE] <= signature->param_count) /* skip return param spec and bounds check*/ @@ -1571,10 +1571,10 @@ mono_method_get_marshal_info (MonoMethod *method, MonoMarshalSpec **mspecs) guint32 cols [MONO_PARAM_SIZE]; guint param_index = mono_metadata_decode_row_col (methodt, idx - 1, MONO_METHOD_PARAMLIST); - if (idx < methodt->rows) + if (idx < table_info_get_rows (methodt)) lastp = mono_metadata_decode_row_col (methodt, idx, MONO_METHOD_PARAMLIST); else - lastp = paramt->rows + 1; + lastp = table_info_get_rows (paramt) + 1; for (i = param_index; i < lastp; ++i) { mono_metadata_decode_row (paramt, i -1, cols, MONO_PARAM_SIZE); @@ -1625,10 +1625,10 @@ mono_method_has_marshal_info (MonoMethod *method) guint32 cols [MONO_PARAM_SIZE]; guint param_index = mono_metadata_decode_row_col (methodt, idx - 1, MONO_METHOD_PARAMLIST); - if (idx + 1 < methodt->rows) + if (idx + 1 < table_info_get_rows (methodt)) lastp = mono_metadata_decode_row_col (methodt, idx, MONO_METHOD_PARAMLIST); else - lastp = paramt->rows + 1; + lastp = table_info_get_rows (paramt) + 1; for (i = param_index; i < lastp; ++i) { mono_metadata_decode_row (paramt, i -1, cols, MONO_PARAM_SIZE); diff --git a/src/mono/mono/metadata/metadata-internals.h b/src/mono/mono/metadata/metadata-internals.h index 6ec2d98afde619..698dd0ca7baf41 100644 --- a/src/mono/mono/metadata/metadata-internals.h +++ b/src/mono/mono/metadata/metadata-internals.h @@ -276,7 +276,8 @@ typedef struct { struct _MonoTableInfo { const char *base; - guint rows : 24; + guint rows_ : 24; /* don't access directly, use table_info_get_rows */ + guint row_size : 8; /* @@ -801,6 +802,12 @@ assembly_is_dynamic (MonoAssembly *assembly) #endif } +static inline int +table_info_get_rows (const MonoTableInfo *table) +{ + return table->rows_; +} + /* for use with allocated memory blocks (assumes alignment is to 8 bytes) */ guint mono_aligned_addr_hash (gconstpointer ptr); @@ -893,7 +900,7 @@ static inline void mono_image_effective_table (const MonoTableInfo **t, int *idx) { if (G_UNLIKELY (mono_metadata_has_updates ())) { - if (G_UNLIKELY (*idx >= (*t)->rows)) { + if (G_UNLIKELY (*idx >= table_info_get_rows ((*t)))) { mono_image_effective_table_slow (t, idx); } } @@ -967,7 +974,7 @@ static inline gboolean mono_metadata_table_bounds_check (MonoImage *image, int table_index, int token_index) { /* token_index is 1-based. TRUE means the token is out of bounds */ - return token_index > image->tables [table_index].rows; + return token_index > image->tables [table_index].rows_; } #else gboolean @@ -978,7 +985,7 @@ static inline gboolean mono_metadata_table_bounds_check (MonoImage *image, int table_index, int token_index) { /* returns true if given index is not in bounds with provided table/index pair */ - if (G_LIKELY (token_index <= image->tables [table_index].rows)) + if (G_LIKELY (token_index <= table_info_get_rows (&image->tables [table_index]))) return FALSE; return mono_metadata_table_bounds_check_slow (image, table_index, token_index); } diff --git a/src/mono/mono/metadata/metadata-update.c b/src/mono/mono/metadata/metadata-update.c index 0e9cf557ec9129..3d1d78e4808460 100644 --- a/src/mono/mono/metadata/metadata-update.c +++ b/src/mono/mono/metadata/metadata-update.c @@ -538,7 +538,7 @@ dump_update_summary (MonoImage *image_base, MonoImage *image_dmeta) void mono_image_effective_table_slow (const MonoTableInfo **t, int *idx) { - if (G_LIKELY (*idx < (*t)->rows)) + if (G_LIKELY (*idx < table_info_get_rows (*t))) return; /* FIXME: don't let any thread other than the updater thread see values from a delta image @@ -590,9 +590,9 @@ mono_image_effective_table_slow (const MonoTableInfo **t, int *idx) table = &dmeta->tables [tbl_index]; ridx = mono_image_relative_delta_index (dmeta, mono_metadata_make_token (tbl_index, *idx + 1)) - 1; g++; - } while (ridx < 0 || ridx >= table->rows); + } while (ridx < 0 || ridx >= table_info_get_rows (table)); - mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_METADATA_UPDATE, "effective table for %s: 0x%08x -> 0x%08x (rows = 0x%08x) (gen %d, g %d)", mono_meta_table_name (tbl_index), *idx, ridx, table->rows, metadata_update_local_generation (base, dmeta), g); + mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_METADATA_UPDATE, "effective table for %s: 0x%08x -> 0x%08x (rows = 0x%08x) (gen %d, g %d)", mono_meta_table_name (tbl_index), *idx, ridx, table_info_get_rows (table), metadata_update_local_generation (base, dmeta), g); *t = table; *idx = ridx; @@ -628,7 +628,7 @@ mono_image_relative_delta_index (MonoImage *image_dmeta, int token) /* this helper expects and returns as "index origin = 1" */ g_assert (index > 0); - if (!encmap->rows || !image_dmeta->minimal_delta) + if (!table_info_get_rows (encmap) || !image_dmeta->minimal_delta) return mono_metadata_token_index (token); DeltaInfo *delta_info = delta_info_lookup (image_dmeta); @@ -639,7 +639,8 @@ mono_image_relative_delta_index (MonoImage *image_dmeta, int token) mono_metadata_decode_row (encmap, index_map - 1, cols, MONO_ENCMAP_SIZE); int map_entry = cols [MONO_ENCMAP_TOKEN]; - while (mono_metadata_token_table (map_entry) == table && mono_metadata_token_index (map_entry) < index && index_map < encmap->rows) { + int encmap_rows = table_info_get_rows (encmap); + while (mono_metadata_token_table (map_entry) == table && mono_metadata_token_index (map_entry) < index && index_map < encmap_rows) { mono_metadata_decode_row (encmap, ++index_map - 1, cols, MONO_ENCMAP_SIZE); map_entry = cols [MONO_ENCMAP_TOKEN]; } @@ -648,12 +649,12 @@ mono_image_relative_delta_index (MonoImage *image_dmeta, int token) if (mono_metadata_token_index (map_entry) == index) { /* token resolves to this generation */ int return_val = index_map - delta_info->enc_recs [table] + 1; - g_assert (return_val > 0 && return_val <= image_dmeta->tables[table].rows); + g_assert (return_val > 0 && return_val <= table_info_get_rows (&image_dmeta->tables[table])); mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_METADATA_UPDATE, "relative index for token 0x%08x -> table 0x%02x row 0x%08x", token, table, return_val); return return_val; } else { /* otherwise the last entry in the encmap is for this table, but is still less than the index - the index is in the next generation */ - g_assert (mono_metadata_token_index (map_entry) < index && index_map == encmap->rows); + g_assert (mono_metadata_token_index (map_entry) < index && index_map == encmap_rows); return -1; } } else { @@ -671,7 +672,7 @@ delta_info_init (MonoImage *image_dmeta, MonoImage *image_base) g_assert (!delta_info_lookup (image_dmeta)); - if (!encmap->rows) + if (!table_info_get_rows (encmap)) return NULL; DeltaInfo *delta_info = g_malloc0 (sizeof (DeltaInfo)); @@ -680,7 +681,7 @@ delta_info_init (MonoImage *image_dmeta, MonoImage *image_base) if (image_base->delta_image == image_base->delta_image_last) { /* this is the first update. */ for (int i = 0; i < MONO_TABLE_NUM; ++i) { - delta_info->count[i].prev_gen_rows = image_base->tables[i].rows; + delta_info->count[i].prev_gen_rows = table_info_get_rows (&image_base->tables[i]); } } else { /* Current image_dmeta is image_base->delta_image_last->data, @@ -698,7 +699,8 @@ delta_info_init (MonoImage *image_dmeta, MonoImage *image_base) /* TODO: while going through the tables, update delta_info->count[tbl].{modified,inserted}_rows */ - for (idx = 1; idx <= encmap->rows; ++idx) { + int encmap_rows = table_info_get_rows (encmap); + for (idx = 1; idx <= encmap_rows; ++idx) { guint32 cols[MONO_ENCMAP_SIZE]; mono_metadata_decode_row (encmap, idx - 1, cols, MONO_ENCMAP_SIZE); uint32_t tok = cols [MONO_ENCMAP_TOKEN]; @@ -765,7 +767,7 @@ static gboolean apply_enclog_pass1 (MonoImage *image_base, MonoImage *image_dmeta, gconstpointer dil_data, uint32_t dil_length, MonoError *error) { MonoTableInfo *table_enclog = &image_dmeta->tables [MONO_TABLE_ENCLOG]; - int rows = table_enclog->rows; + int rows = table_info_get_rows (table_enclog); gboolean unsupported_edits = FALSE; @@ -787,13 +789,13 @@ apply_enclog_pass1 (MonoImage *image_base, MonoImage *image_dmeta, gconstpointer int token_table = mono_metadata_token_table (log_token); int token_index = mono_metadata_token_index (log_token); - mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_METADATA_UPDATE, "row[0x%02x]:0x%08x (%s idx=0x%02x) (base table has 0x%04x rows)\tfunc=0x%02x\n", i, log_token, mono_meta_table_name (token_table), token_index, image_base->tables [token_table].rows, func_code); + mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_METADATA_UPDATE, "row[0x%02x]:0x%08x (%s idx=0x%02x) (base table has 0x%04x rows)\tfunc=0x%02x\n", i, log_token, mono_meta_table_name (token_table), token_index, table_info_get_rows (&image_base->tables [token_table]), func_code); if (token_table != MONO_TABLE_METHOD) continue; - if (token_index > image_base->tables [token_table].rows) { + if (token_index > table_info_get_rows (&image_base->tables [token_table])) { mono_trace (G_LOG_LEVEL_INFO, MONO_TRACE_METADATA_UPDATE, "\tcannot add new method with token 0x%08x", log_token); mono_error_set_type_load_name (error, NULL, image_base->name, "EnC: cannot add new method with token 0x%08x", log_token); unsupported_edits = TRUE; @@ -817,7 +819,7 @@ apply_enclog_pass1 (MonoImage *image_base, MonoImage *image_dmeta, gconstpointer } else if (token_table == MONO_TABLE_METHOD) { /* handled above */ } else { - if (token_index <= image_base->tables [token_table].rows) { + if (token_index <= table_info_get_rows (&image_base->tables [token_table])) { mono_trace (G_LOG_LEVEL_INFO, MONO_TRACE_METADATA_UPDATE, "row[0x%02x]:0x%08x we do not support patching of existing table cols.", i, log_token); mono_error_set_type_load_name (error, NULL, image_base->name, "EnC: we do not support patching of existing table cols. token=0x%08x", log_token); unsupported_edits = TRUE; @@ -857,7 +859,7 @@ static gboolean apply_enclog_pass2 (MonoImage *image_base, uint32_t generation, MonoImage *image_dmeta, gconstpointer dil_data, uint32_t dil_length, MonoError *error) { MonoTableInfo *table_enclog = &image_dmeta->tables [MONO_TABLE_ENCLOG]; - int rows = table_enclog->rows; + int rows = table_info_get_rows (table_enclog); gboolean assemblyref_updated = FALSE; for (int i = 0; i < rows ; ++i) { @@ -882,7 +884,7 @@ apply_enclog_pass2 (MonoImage *image_base, uint32_t generation, MonoImage *image } if (token_table == MONO_TABLE_ASSEMBLYREF) { - g_assert (token_index > image_base->tables [token_table].rows); + g_assert (token_index > table_info_get_rows (&image_base->tables [token_table])); if (assemblyref_updated) continue; @@ -891,12 +893,12 @@ apply_enclog_pass2 (MonoImage *image_base, uint32_t generation, MonoImage *image /* FIXME: use DeltaInfo:prev_gen_rows instead of looping */ /* TODO: do we know that there will never be modified rows in ASSEMBLYREF? */ - int old_rows = image_base->tables [MONO_TABLE_ASSEMBLYREF].rows; + int old_rows = table_info_get_rows (&image_base->tables [MONO_TABLE_ASSEMBLYREF]); for (GList *l = image_base->delta_image; l; l = l->next) { MonoImage *delta_child = l->data; - old_rows += delta_child->tables [MONO_TABLE_ASSEMBLYREF].rows; + old_rows += table_info_get_rows (&delta_child->tables [MONO_TABLE_ASSEMBLYREF]); } - int new_rows = image_dmeta->tables [MONO_TABLE_ASSEMBLYREF].rows; + int new_rows = table_info_get_rows (&image_dmeta->tables [MONO_TABLE_ASSEMBLYREF]); old_rows -= new_rows; g_assert (new_rows > 0); @@ -914,7 +916,7 @@ apply_enclog_pass2 (MonoImage *image_base, uint32_t generation, MonoImage *image g_free (old_array); } else if (token_table == MONO_TABLE_METHOD) { - if (token_index > image_base->tables [token_table].rows) { + if (token_index > table_info_get_rows (&image_base->tables [token_table])) { g_error ("EnC: new method added, should be caught by pass1"); } @@ -937,9 +939,9 @@ apply_enclog_pass2 (MonoImage *image_base, uint32_t generation, MonoImage *image /* TODO: happens changing the class (adding field or method). we ignore it, but dragons are here */ /* existing entries are supposed to be patched */ - g_assert (token_index <= image_base->tables [token_table].rows); + g_assert (token_index <= table_info_get_rows (&image_base->tables [token_table])); } else { - g_assert (token_index > image_base->tables [token_table].rows); + g_assert (token_index > table_info_get_rows (&image_base->tables [token_table])); if (mono_trace_is_traced (G_LOG_LEVEL_DEBUG, MONO_TRACE_METADATA_UPDATE)) g_print ("todo: do something about this table index: 0x%02x\n", token_table); } @@ -1007,7 +1009,7 @@ mono_image_load_enc_delta (MonoImage *image_base, gconstpointer dmeta_bytes, uin MonoTableInfo *table_enclog = &image_dmeta->tables [MONO_TABLE_ENCLOG]; MonoTableInfo *table_encmap = &image_dmeta->tables [MONO_TABLE_ENCMAP]; - if (!table_enclog->rows && !table_encmap->rows) { + if (!table_info_get_rows (table_enclog) && !table_info_get_rows (table_encmap)) { mono_trace (G_LOG_LEVEL_INFO, MONO_TRACE_METADATA_UPDATE, "No enclog or encmap in delta image for base=%s, nothing to do", basename); mono_metadata_update_cancel (generation); return; @@ -1020,7 +1022,7 @@ mono_image_load_enc_delta (MonoImage *image_base, gconstpointer dmeta_bytes, uin } /* if there are updates, start tracking the tables of the base image, if we weren't already. */ - if (table_enclog->rows) + if (table_info_get_rows (table_enclog)) table_to_image_add (image_base); delta_info_init (image_dmeta, image_base); diff --git a/src/mono/mono/metadata/metadata.c b/src/mono/mono/metadata/metadata.c index 8fd3fc856458af..bb23af5094bb63 100644 --- a/src/mono/mono/metadata/metadata.c +++ b/src/mono/mono/metadata/metadata.c @@ -585,7 +585,7 @@ idx_size (MonoImage *meta, int idx) if (meta->referenced_tables && (meta->referenced_tables & ((guint64)1 << idx))) return meta->referenced_table_rows [idx] < 65536 ? 2 : 4; else - return meta->tables [idx].rows < 65536 ? 2 : 4; + return table_info_get_rows (&meta->tables [idx]) < 65536 ? 2 : 4; } static int @@ -594,7 +594,7 @@ get_nrows (MonoImage *meta, int idx) if (meta->referenced_tables && (meta->referenced_tables & ((guint64)1 << idx))) return meta->referenced_table_rows [idx]; else - return meta->tables [idx].rows; + return table_info_get_rows (&meta->tables [idx]); } /* Reference: Partition II - 23.2.6 */ @@ -994,7 +994,7 @@ mono_metadata_compute_size (MonoImage *meta, int tableindex, guint32 *result_bit gboolean mono_metadata_table_bounds_check_slow (MonoImage *image, int table_index, int token_index) { - if (G_LIKELY (token_index <= image->tables [table_index].rows)) + if (G_LIKELY (token_index <= table_info_get_rows (&image->tables [table_index]))) return FALSE; GList *list = image->delta_image; @@ -1016,7 +1016,7 @@ mono_metadata_table_bounds_check_slow (MonoImage *image, int table_index, int to table = &dmeta->tables [table_index]; /* mono_image_relative_delta_index returns a 1-based index */ ridx = mono_image_relative_delta_index (dmeta, original_token) - 1; - } while (ridx < 0 || ridx >= table->rows); + } while (ridx < 0 || ridx >= table_info_get_rows (table)); return FALSE; } @@ -1037,12 +1037,12 @@ mono_metadata_compute_table_bases (MonoImage *meta) for (i = 0; i < MONO_TABLE_NUM; i++) { MonoTableInfo *table = &meta->tables [i]; - if (table->rows == 0) + if (table_info_get_rows (table) == 0) continue; table->row_size = mono_metadata_compute_size (meta, i, &table->size_bitfield); table->base = base; - base += table->rows * table->row_size; + base += table_info_get_rows (table) * table->row_size; } } @@ -1058,8 +1058,9 @@ mono_metadata_compute_table_bases (MonoImage *meta) const char * mono_metadata_locate (MonoImage *meta, int table, int idx) { + /* FIXME: metadata-update */ /* idx == 0 refers always to NULL */ - g_return_val_if_fail (idx > 0 && idx <= meta->tables [table].rows, ""); /*FIXME shouldn't we return NULL here?*/ + g_return_val_if_fail (idx > 0 && idx <= table_info_get_rows (&meta->tables [table]), ""); /*FIXME shouldn't we return NULL here?*/ return meta->tables [table].base + (meta->tables [table].row_size * (idx - 1)); } @@ -1381,7 +1382,7 @@ mono_metadata_decode_row_raw (const MonoTableInfo *t, int idx, guint32 *res, int int i, count = mono_metadata_table_count (bitfield); const char *data; - g_assert (idx < t->rows); + g_assert (idx < table_info_get_rows (t)); g_assert (idx >= 0); data = t->base + idx * t->row_size; @@ -1428,8 +1429,8 @@ mono_metadata_decode_row_checked (const MonoImage *image, const MonoTableInfo *t guint32 bitfield = t->size_bitfield; int i, count = mono_metadata_table_count (bitfield); - if (G_UNLIKELY (! (idx < t->rows && idx >= 0))) { - mono_error_set_bad_image_by_name (error, image_name, "row index %d out of bounds: %d rows: %s", idx, t->rows, image_name); + if (G_UNLIKELY (! (idx < table_info_get_rows (t) && idx >= 0))) { + mono_error_set_bad_image_by_name (error, image_name, "row index %d out of bounds: %d rows: %s", idx, table_info_get_rows (t), image_name); return FALSE; } const char *data = t->base + idx * t->row_size; @@ -1531,7 +1532,7 @@ mono_metadata_decode_row_col_raw (const MonoTableInfo *t, int idx, guint col) guint32 bitfield = t->size_bitfield; - g_assert (idx < t->rows); + g_assert (idx < table_info_get_rows (t)); g_assert (col < mono_metadata_table_count (bitfield)); data = t->base + idx * t->row_size; @@ -1670,27 +1671,27 @@ mono_metadata_translate_token_index (MonoImage *image, int table, guint32 idx) switch (table) { case MONO_TABLE_METHOD: - if (image->tables [MONO_TABLE_METHOD_POINTER].rows) + if (table_info_get_rows (&image->tables [MONO_TABLE_METHOD_POINTER])) return mono_metadata_decode_row_col (&image->tables [MONO_TABLE_METHOD_POINTER], idx - 1, MONO_METHOD_POINTER_METHOD); else return idx; case MONO_TABLE_FIELD: - if (image->tables [MONO_TABLE_FIELD_POINTER].rows) + if (table_info_get_rows (&image->tables [MONO_TABLE_FIELD_POINTER])) return mono_metadata_decode_row_col (&image->tables [MONO_TABLE_FIELD_POINTER], idx - 1, MONO_FIELD_POINTER_FIELD); else return idx; case MONO_TABLE_EVENT: - if (image->tables [MONO_TABLE_EVENT_POINTER].rows) + if (table_info_get_rows (&image->tables [MONO_TABLE_EVENT_POINTER])) return mono_metadata_decode_row_col (&image->tables [MONO_TABLE_EVENT_POINTER], idx - 1, MONO_EVENT_POINTER_EVENT); else return idx; case MONO_TABLE_PROPERTY: - if (image->tables [MONO_TABLE_PROPERTY_POINTER].rows) + if (table_info_get_rows (&image->tables [MONO_TABLE_PROPERTY_POINTER])) return mono_metadata_decode_row_col (&image->tables [MONO_TABLE_PROPERTY_POINTER], idx - 1, MONO_PROPERTY_POINTER_PROPERTY); else return idx; case MONO_TABLE_PARAM: - if (image->tables [MONO_TABLE_PARAM_POINTER].rows) + if (table_info_get_rows (&image->tables [MONO_TABLE_PARAM_POINTER])) return mono_metadata_decode_row_col (&image->tables [MONO_TABLE_PARAM_POINTER], idx - 1, MONO_PARAM_POINTER_PARAM); else return idx; @@ -2265,10 +2266,11 @@ mono_metadata_method_has_param_attrs (MonoImage *m, int def) MonoTableInfo *methodt = &m->tables [MONO_TABLE_METHOD]; guint lastp, i, param_index = mono_metadata_decode_row_col (methodt, def - 1, MONO_METHOD_PARAMLIST); - if (def < methodt->rows) + /* FIXME: metadata-update */ + if (def < table_info_get_rows (methodt)) lastp = mono_metadata_decode_row_col (methodt, def, MONO_METHOD_PARAMLIST); else - lastp = m->tables [MONO_TABLE_PARAM].rows + 1; + lastp = table_info_get_rows (&m->tables [MONO_TABLE_PARAM]) + 1; for (i = param_index; i < lastp; ++i) { guint32 flags = mono_metadata_decode_row_col (paramt, i - 1, MONO_PARAM_FLAGS); @@ -2299,10 +2301,12 @@ mono_metadata_get_param_attrs (MonoImage *m, int def, int param_count) guint lastp, i, param_index = mono_metadata_decode_row_col (methodt, def - 1, MONO_METHOD_PARAMLIST); int *pattrs = NULL; - if (def < methodt->rows) + /* FIXME: metadata-update */ + int rows = table_info_get_rows (methodt); + if (def < rows) lastp = mono_metadata_decode_row_col (methodt, def, MONO_METHOD_PARAMLIST); else - lastp = paramt->rows + 1; + lastp = table_info_get_rows (paramt) + 1; for (i = param_index; i < lastp; ++i) { mono_metadata_decode_row (paramt, i - 1, cols, MONO_PARAM_SIZE); @@ -5099,7 +5103,7 @@ typedef_locator (const void *a, const void *b) /* * Need to check that the next row is valid. */ - if (typedef_index + 1 < loc->t->rows) { + if (typedef_index + 1 < table_info_get_rows (loc->t)) { col_next = mono_metadata_decode_row_col (loc->t, typedef_index + 1, loc->col_idx); if (loc->idx >= col_next) return 1; @@ -5163,15 +5167,16 @@ static guint32 search_ptr_table (MonoImage *image, int table, int idx) { MonoTableInfo *ptrdef = &image->tables [table]; + int rows = table_info_get_rows (ptrdef); int i; /* Use a linear search to find our index in the table */ - for (i = 0; i < ptrdef->rows; i ++) + for (i = 0; i < rows; i ++) /* All the Ptr tables have the same structure */ if (mono_metadata_decode_row_col (ptrdef, i, 0) == idx) break; - if (i < ptrdef->rows) + if (i < rows) return i + 1; else return idx; @@ -5201,7 +5206,9 @@ mono_metadata_typedef_from_field (MonoImage *meta, guint32 index) if (meta->uncompressed_metadata) loc.idx = search_ptr_table (meta, MONO_TABLE_FIELD_POINTER, loc.idx); - if (!mono_binary_search (&loc, tdef->base, tdef->rows, tdef->row_size, typedef_locator)) + /* FIXME: metadata-update */ + + if (!mono_binary_search (&loc, tdef->base, table_info_get_rows (tdef), tdef->row_size, typedef_locator)) return 0; /* loc_result is 0..1, needs to be mapped to table index (that is +1) */ @@ -5231,7 +5238,9 @@ mono_metadata_typedef_from_method (MonoImage *meta, guint32 index) if (meta->uncompressed_metadata) loc.idx = search_ptr_table (meta, MONO_TABLE_METHOD_POINTER, loc.idx); - if (!mono_binary_search (&loc, tdef->base, tdef->rows, tdef->row_size, typedef_locator)) + /* FIXME: metadata-update */ + + if (!mono_binary_search (&loc, tdef->base, table_info_get_rows (tdef), tdef->row_size, typedef_locator)) return 0; /* loc_result is 0..1, needs to be mapped to table index (that is +1) */ @@ -5274,7 +5283,9 @@ mono_metadata_interfaces_from_typedef_full (MonoImage *meta, guint32 index, Mono loc.col_idx = MONO_INTERFACEIMPL_CLASS; loc.t = tdef; - if (!mono_binary_search (&loc, tdef->base, tdef->rows, tdef->row_size, table_locator)) + /* FIXME: metadata-update */ + + if (!mono_binary_search (&loc, tdef->base, table_info_get_rows (tdef), tdef->row_size, table_locator)) return TRUE; start = loc.result; @@ -5288,7 +5299,8 @@ mono_metadata_interfaces_from_typedef_full (MonoImage *meta, guint32 index, Mono break; } pos = start; - while (pos < tdef->rows) { + int rows = table_info_get_rows (tdef); + while (pos < rows) { mono_metadata_decode_row (tdef, pos, cols, MONO_INTERFACEIMPL_SIZE); if (cols [MONO_INTERFACEIMPL_CLASS] != loc.idx) break; @@ -5301,7 +5313,7 @@ mono_metadata_interfaces_from_typedef_full (MonoImage *meta, guint32 index, Mono result = (MonoClass **)mono_image_alloc0 (meta, sizeof (MonoClass*) * (pos - start)); pos = start; - while (pos < tdef->rows) { + while (pos < rows) { MonoClass *iface; mono_metadata_decode_row (tdef, pos, cols, MONO_INTERFACEIMPL_SIZE); @@ -5369,7 +5381,9 @@ mono_metadata_nested_in_typedef (MonoImage *meta, guint32 index) loc.col_idx = MONO_NESTED_CLASS_NESTED; loc.t = tdef; - if (!mono_binary_search (&loc, tdef->base, tdef->rows, tdef->row_size, table_locator)) + /* FIXME: metadata-update */ + + if (!mono_binary_search (&loc, tdef->base, table_info_get_rows (tdef), tdef->row_size, table_locator)) return 0; /* loc_result is 0..1, needs to be mapped to table index (that is +1) */ @@ -5396,14 +5410,17 @@ mono_metadata_nesting_typedef (MonoImage *meta, guint32 index, guint32 start_ind start = start_index; - while (start <= tdef->rows) { + /* FIXME: metadata-udpate */ + + int rows = table_info_get_rows (tdef); + while (start <= rows) { if (class_index == mono_metadata_decode_row_col (tdef, start - 1, MONO_NESTED_CLASS_ENCLOSING)) break; else start++; } - if (start > tdef->rows) + if (start > rows) return 0; else return start; @@ -5431,7 +5448,9 @@ mono_metadata_packing_from_typedef (MonoImage *meta, guint32 index, guint32 *pac loc.col_idx = MONO_CLASS_LAYOUT_PARENT; loc.t = tdef; - if (!mono_binary_search (&loc, tdef->base, tdef->rows, tdef->row_size, table_locator)) + /* FIXME: metadata-update */ + + if (!mono_binary_search (&loc, tdef->base, table_info_get_rows (tdef), tdef->row_size, table_locator)) return 0; mono_metadata_decode_row (tdef, loc.result, cols, MONO_CLASS_LAYOUT_SIZE); @@ -5465,9 +5484,10 @@ mono_metadata_custom_attrs_from_index (MonoImage *meta, guint32 index) loc.col_idx = MONO_CUSTOM_ATTR_PARENT; loc.t = tdef; + /* FIXME: metadata-update */ /* FIXME: Index translation */ - if (!mono_binary_search (&loc, tdef->base, tdef->rows, tdef->row_size, table_locator)) + if (!mono_binary_search (&loc, tdef->base, table_info_get_rows (tdef), tdef->row_size, table_locator)) return 0; /* Find the first entry by searching backwards */ @@ -5499,7 +5519,9 @@ mono_metadata_declsec_from_index (MonoImage *meta, guint32 index) loc.col_idx = MONO_DECL_SECURITY_PARENT; loc.t = tdef; - if (!mono_binary_search (&loc, tdef->base, tdef->rows, tdef->row_size, declsec_locator)) + /* FIXME: metadata-update */ + + if (!mono_binary_search (&loc, tdef->base, table_info_get_rows (tdef), tdef->row_size, declsec_locator)) return -1; /* Find the first entry by searching backwards */ @@ -5531,7 +5553,9 @@ mono_metadata_localscope_from_methoddef (MonoImage *meta, guint32 index) loc.col_idx = MONO_LOCALSCOPE_METHOD; loc.t = tdef; - if (!mono_binary_search (&loc, tdef->base, tdef->rows, tdef->row_size, table_locator)) + /* FIXME: metadata-update */ + + if (!mono_binary_search (&loc, tdef->base, table_info_get_rows (tdef), tdef->row_size, table_locator)) return 0; /* Find the first entry by searching backwards */ @@ -6548,7 +6572,9 @@ mono_metadata_field_info_full (MonoImage *meta, guint32 index, guint32 *offset, loc.col_idx = MONO_FIELD_LAYOUT_FIELD; loc.t = tdef; - if (tdef->base && mono_binary_search (&loc, tdef->base, tdef->rows, tdef->row_size, table_locator)) { + /* FIXME: metadata-update */ + + if (tdef->base && mono_binary_search (&loc, tdef->base, table_info_get_rows (tdef), tdef->row_size, table_locator)) { *offset = mono_metadata_decode_row_col (tdef, loc.result, MONO_FIELD_LAYOUT_OFFSET); } else { *offset = (guint32)-1; @@ -6560,7 +6586,7 @@ mono_metadata_field_info_full (MonoImage *meta, guint32 index, guint32 *offset, loc.col_idx = MONO_FIELD_RVA_FIELD; loc.t = tdef; - if (tdef->base && mono_binary_search (&loc, tdef->base, tdef->rows, tdef->row_size, table_locator)) { + if (tdef->base && mono_binary_search (&loc, tdef->base, table_info_get_rows (tdef), tdef->row_size, table_locator)) { /* * LAMESPEC: There is no signature, no nothing, just the raw data. */ @@ -6616,12 +6642,14 @@ mono_metadata_get_constant_index (MonoImage *meta, guint32 token, guint32 hint) loc.col_idx = MONO_CONSTANT_PARENT; loc.t = tdef; + /* FIXME: metadata-update */ + /* FIXME: Index translation */ - if ((hint > 0) && (hint < tdef->rows) && (mono_metadata_decode_row_col (tdef, hint - 1, MONO_CONSTANT_PARENT) == index)) + if ((hint > 0) && (hint < table_info_get_rows (tdef)) && (mono_metadata_decode_row_col (tdef, hint - 1, MONO_CONSTANT_PARENT) == index)) return hint; - if (tdef->base && mono_binary_search (&loc, tdef->base, tdef->rows, tdef->row_size, table_locator)) { + if (tdef->base && mono_binary_search (&loc, tdef->base, table_info_get_rows (tdef), tdef->row_size, table_locator)) { return loc.result + 1; } return 0; @@ -6651,14 +6679,16 @@ mono_metadata_events_from_typedef (MonoImage *meta, guint32 index, guint *end_id loc.col_idx = MONO_EVENT_MAP_PARENT; loc.idx = index + 1; - if (!mono_binary_search (&loc, tdef->base, tdef->rows, tdef->row_size, table_locator)) + /* FIXME: metadata-update */ + + if (!mono_binary_search (&loc, tdef->base, table_info_get_rows (tdef), tdef->row_size, table_locator)) return 0; start = mono_metadata_decode_row_col (tdef, loc.result, MONO_EVENT_MAP_EVENTLIST); - if (loc.result + 1 < tdef->rows) { + if (loc.result + 1 < table_info_get_rows (tdef)) { end = mono_metadata_decode_row_col (tdef, loc.result + 1, MONO_EVENT_MAP_EVENTLIST) - 1; } else { - end = meta->tables [MONO_TABLE_EVENT].rows; + end = table_info_get_rows (&meta->tables [MONO_TABLE_EVENT]); } *end_idx = end; @@ -6692,7 +6722,9 @@ mono_metadata_methods_from_event (MonoImage *meta, guint32 index, guint *end_i loc.col_idx = MONO_METHOD_SEMA_ASSOCIATION; loc.idx = ((index + 1) << MONO_HAS_SEMANTICS_BITS) | MONO_HAS_SEMANTICS_EVENT; /* Method association coded index */ - if (!mono_binary_search (&loc, msemt->base, msemt->rows, msemt->row_size, table_locator)) + /* FIXME: metadata-update */ + + if (!mono_binary_search (&loc, msemt->base, table_info_get_rows (msemt), msemt->row_size, table_locator)) return 0; start = loc.result; @@ -6706,7 +6738,8 @@ mono_metadata_methods_from_event (MonoImage *meta, guint32 index, guint *end_i break; } end = start + 1; - while (end < msemt->rows) { + int rows = table_info_get_rows (msemt); + while (end < rows) { mono_metadata_decode_row (msemt, end, cols, MONO_METHOD_SEMA_SIZE); if (cols [MONO_METHOD_SEMA_ASSOCIATION] != loc.idx) break; @@ -6740,14 +6773,16 @@ mono_metadata_properties_from_typedef (MonoImage *meta, guint32 index, guint *en loc.col_idx = MONO_PROPERTY_MAP_PARENT; loc.idx = index + 1; - if (!mono_binary_search (&loc, tdef->base, tdef->rows, tdef->row_size, table_locator)) + /* FIXME: metadata-update */ + + if (!mono_binary_search (&loc, tdef->base, table_info_get_rows (tdef), tdef->row_size, table_locator)) return 0; start = mono_metadata_decode_row_col (tdef, loc.result, MONO_PROPERTY_MAP_PROPERTY_LIST); - if (loc.result + 1 < tdef->rows) { + if (loc.result + 1 < table_info_get_rows (tdef)) { end = mono_metadata_decode_row_col (tdef, loc.result + 1, MONO_PROPERTY_MAP_PROPERTY_LIST) - 1; } else { - end = meta->tables [MONO_TABLE_PROPERTY].rows; + end = table_info_get_rows (&meta->tables [MONO_TABLE_PROPERTY]); } *end_idx = end; @@ -6781,7 +6816,9 @@ mono_metadata_methods_from_property (MonoImage *meta, guint32 index, guint *en loc.col_idx = MONO_METHOD_SEMA_ASSOCIATION; loc.idx = ((index + 1) << MONO_HAS_SEMANTICS_BITS) | MONO_HAS_SEMANTICS_PROPERTY; /* Method association coded index */ - if (!mono_binary_search (&loc, msemt->base, msemt->rows, msemt->row_size, table_locator)) + /* FIXME: metadata-update */ + + if (!mono_binary_search (&loc, msemt->base, table_info_get_rows (msemt), msemt->row_size, table_locator)) return 0; start = loc.result; @@ -6795,7 +6832,8 @@ mono_metadata_methods_from_property (MonoImage *meta, guint32 index, guint *en break; } end = start + 1; - while (end < msemt->rows) { + int rows = table_info_get_rows (msemt); + while (end < rows) { mono_metadata_decode_row (msemt, end, cols, MONO_METHOD_SEMA_SIZE); if (cols [MONO_METHOD_SEMA_ASSOCIATION] != loc.idx) break; @@ -6823,7 +6861,9 @@ mono_metadata_implmap_from_method (MonoImage *meta, guint32 method_idx) loc.col_idx = MONO_IMPLMAP_MEMBER; loc.idx = ((method_idx + 1) << MONO_MEMBERFORWD_BITS) | MONO_MEMBERFORWD_METHODDEF; - if (!mono_binary_search (&loc, tdef->base, tdef->rows, tdef->row_size, table_locator)) + /* FIXME: metadata-update */ + + if (!mono_binary_search (&loc, tdef->base, table_info_get_rows (tdef), tdef->row_size, table_locator)) return 0; return loc.result + 1; @@ -7242,9 +7282,10 @@ mono_metadata_get_marshal_info (MonoImage *meta, guint32 idx, gboolean is_field) loc.col_idx = MONO_FIELD_MARSHAL_PARENT; loc.idx = ((idx + 1) << MONO_HAS_FIELD_MARSHAL_BITS) | (is_field? MONO_HAS_FIELD_MARSHAL_FIELDSREF: MONO_HAS_FIELD_MARSHAL_PARAMDEF); + /* FIXME: metadata-update */ /* FIXME: Index translation */ - if (!mono_binary_search (&loc, tdef->base, tdef->rows, tdef->row_size, table_locator)) + if (!mono_binary_search (&loc, tdef->base, table_info_get_rows (tdef), tdef->row_size, table_locator)) return NULL; return mono_metadata_blob_heap (meta, mono_metadata_decode_row_col (tdef, loc.result, MONO_FIELD_MARSHAL_NATIVE_TYPE)); @@ -7301,7 +7342,9 @@ mono_class_get_overrides_full (MonoImage *image, guint32 type_token, MonoMethod loc.col_idx = MONO_METHODIMPL_CLASS; loc.idx = mono_metadata_token_index (type_token); - if (!mono_binary_search (&loc, tdef->base, tdef->rows, tdef->row_size, table_locator)) + /* FIXME metadata-update */ + + if (!mono_binary_search (&loc, tdef->base, table_info_get_rows (tdef), tdef->row_size, table_locator)) return; start = loc.result; @@ -7315,7 +7358,8 @@ mono_class_get_overrides_full (MonoImage *image, guint32 type_token, MonoMethod else break; } - while (end < tdef->rows) { + int rows = table_info_get_rows (tdef); + while (end < rows) { if (loc.idx == mono_metadata_decode_row_col (tdef, end, MONO_METHODIMPL_CLASS)) end++; else @@ -7396,7 +7440,9 @@ get_constraints (MonoImage *image, int owner, MonoClass ***constraints, MonoGene *constraints = NULL; found = 0; - for (i = 0; i < tdef->rows; ++i) { + /* FIXME: metadata-update */ + int rows = table_info_get_rows (tdef); + for (i = 0; i < rows; ++i) { mono_metadata_decode_row (tdef, i, cols, MONO_GENPARCONSTRAINT_SIZE); if (cols [MONO_GENPARCONSTRAINT_GENERICPAR] == owner) { token = mono_metadata_token_from_dor (cols [MONO_GENPARCONSTRAINT_CONSTRAINT]); @@ -7458,7 +7504,9 @@ mono_metadata_get_generic_param_row (MonoImage *image, guint32 token, guint32 *o loc.col_idx = MONO_GENERICPARAM_OWNER; loc.t = tdef; - if (!mono_binary_search (&loc, tdef->base, tdef->rows, tdef->row_size, table_locator)) + /* FIXME: metadata-update */ + + if (!mono_binary_search (&loc, tdef->base, table_info_get_rows (tdef), tdef->row_size, table_locator)) return 0; /* Find the first entry by searching backwards */ @@ -7551,7 +7599,8 @@ mono_metadata_load_generic_params (MonoImage *image, guint32 token, MonoGenericC params [n - 1].info.name = mono_metadata_string_heap (image, cols [MONO_GENERICPARAM_NAME]); if (params [n - 1].num != n - 1) g_warning ("GenericParam table unsorted or hole in generic param sequence: token %d", i); - if (++i > tdef->rows) + /* FIXME: metadata-update */ + if (++i > table_info_get_rows (tdef)) break; mono_metadata_decode_row (tdef, i - 1, cols, MONO_GENERICPARAM_SIZE); } while (cols [MONO_GENERICPARAM_OWNER] == owner); diff --git a/src/mono/mono/metadata/metadata.h b/src/mono/mono/metadata/metadata.h index 7870adbdf88b89..62350f113ff385 100644 --- a/src/mono/mono/metadata/metadata.h +++ b/src/mono/mono/metadata/metadata.h @@ -231,7 +231,8 @@ MONO_API int mono_metadata_compute_size (MonoImage *meta, * */ MONO_API const char *mono_metadata_locate (MonoImage *meta, int table, int idx); -MONO_API const char *mono_metadata_locate_token (MonoImage *meta, uint32_t token); +MONO_API MONO_RT_EXTERNAL_ONLY +const char *mono_metadata_locate_token (MonoImage *meta, uint32_t token); MONO_API const char *mono_metadata_string_heap (MonoImage *meta, uint32_t table_index); MONO_API const char *mono_metadata_blob_heap (MonoImage *meta, uint32_t table_index); diff --git a/src/mono/mono/metadata/native-library.c b/src/mono/mono/metadata/native-library.c index 8f3a04751da547..7e1a16cab4be56 100644 --- a/src/mono/mono/metadata/native-library.c +++ b/src/mono/mono/metadata/native-library.c @@ -990,12 +990,12 @@ lookup_pinvoke_call_impl (MonoMethod *method, MonoLookupPInvokeStatus *status_ou orig_scope = method_aux->dll; } else { - if (!piinfo->implmap_idx || piinfo->implmap_idx > im->rows) + if (!piinfo->implmap_idx || mono_metadata_table_bounds_check (image, MONO_TABLE_IMPLMAP, piinfo->implmap_idx)) goto exit; mono_metadata_decode_row (im, piinfo->implmap_idx - 1, im_cols, MONO_IMPLMAP_SIZE); - if (!im_cols [MONO_IMPLMAP_SCOPE] || im_cols [MONO_IMPLMAP_SCOPE] > mr->rows) + if (!im_cols [MONO_IMPLMAP_SCOPE] || mono_metadata_table_bounds_check (image, MONO_TABLE_MODULEREF, im_cols [MONO_IMPLMAP_SCOPE])) goto exit; piinfo->piflags = im_cols [MONO_IMPLMAP_FLAGS]; diff --git a/src/mono/mono/metadata/reflection.c b/src/mono/mono/metadata/reflection.c index 019ba3d40c6c8d..e680f9905c4065 100644 --- a/src/mono/mono/metadata/reflection.c +++ b/src/mono/mono/metadata/reflection.c @@ -330,7 +330,7 @@ mono_module_file_get_object_handle (MonoImage *image, int table_index, MonoError goto_if_nok (error, fail); table = &image->tables [MONO_TABLE_FILE]; - g_assert (table_index < table->rows); + g_assert (table_index < table_info_get_rows (table)); mono_metadata_decode_row (table, table_index, cols, MONO_FILE_SIZE); MONO_HANDLE_SETVAL (res, image, MonoImage*, NULL); @@ -342,7 +342,8 @@ mono_module_file_get_object_handle (MonoImage *image, int table_index, MonoError /* Check whenever the row has a corresponding row in the moduleref table */ table = &image->tables [MONO_TABLE_MODULEREF]; - for (i = 0; i < table->rows; ++i) { + int rows = table_info_get_rows (table); + for (i = 0; i < rows; ++i) { name_idx = mono_metadata_decode_row_col (table, i, MONO_MODULEREF_NAME); val = mono_metadata_string_heap (image, name_idx); if (strcmp (val, name) == 0) @@ -1382,14 +1383,18 @@ get_default_param_value_blobs (MonoMethod *method, char **blobs, guint32 *types) paramt = &image->tables [MONO_TABLE_PARAM]; constt = &image->tables [MONO_TABLE_CONSTANT]; - idx = mono_method_get_index (method) - 1; - g_assert (idx != -1); + idx = mono_method_get_index (method); + g_assert (idx != 0); - param_index = mono_metadata_decode_row_col (methodt, idx, MONO_METHOD_PARAMLIST); - if (idx + 1 < methodt->rows) - lastp = mono_metadata_decode_row_col (methodt, idx + 1, MONO_METHOD_PARAMLIST); + /* lastp is the starting param index for the next method in the table, or + * one past the last row if this is the last method + */ + /* FIXME: metadata-update : will this work with added methods ? */ + param_index = mono_metadata_decode_row_col (methodt, idx - 1, MONO_METHOD_PARAMLIST); + if (!mono_metadata_table_bounds_check (image, MONO_TABLE_METHOD, idx + 1)) + lastp = mono_metadata_decode_row_col (methodt, idx, MONO_METHOD_PARAMLIST); else - lastp = paramt->rows + 1; + lastp = table_info_get_rows (paramt) + 1; for (i = param_index; i < lastp; ++i) { guint32 paramseq; @@ -2707,7 +2712,8 @@ mono_declsec_get_flags (MonoImage *image, guint32 token) if (index < 0) return 0; - for (i = index; i < t->rows; i++) { + int rows = table_info_get_rows (t); + for (i = index; i < rows; i++) { guint32 cols [MONO_DECL_SECURITY_SIZE]; mono_metadata_decode_row (t, i, cols, MONO_DECL_SECURITY_SIZE); @@ -2806,7 +2812,8 @@ fill_actions_from_index (MonoImage *image, guint32 token, MonoDeclSecurityAction int i; t = &image->tables [MONO_TABLE_DECLSECURITY]; - for (i = index; i < t->rows; i++) { + int rows = table_info_get_rows (t); + for (i = index; i < rows; i++) { mono_metadata_decode_row (t, i, cols, MONO_DECL_SECURITY_SIZE); if (cols [MONO_DECL_SECURITY_PARENT] != token) @@ -2879,7 +2886,7 @@ mono_declsec_get_demands (MonoMethod *method, MonoDeclSecurityActions* demands) guint32 flags; /* quick exit if no declarative security is present in the metadata */ - if (!m_class_get_image (method->klass)->tables [MONO_TABLE_DECLSECURITY].rows) + if (!table_info_get_rows (&m_class_get_image (method->klass)->tables [MONO_TABLE_DECLSECURITY])) return FALSE; /* we want the original as the wrapper is "free" of the security informations */ @@ -2927,7 +2934,7 @@ mono_declsec_get_linkdemands (MonoMethod *method, MonoDeclSecurityActions* klass guint32 flags; /* quick exit if no declarative security is present in the metadata */ - if (!m_class_get_image (method->klass)->tables [MONO_TABLE_DECLSECURITY].rows) + if (!table_info_get_rows (&m_class_get_image (method->klass)->tables [MONO_TABLE_DECLSECURITY])) return FALSE; /* we want the original as the wrapper is "free" of the security informations */ @@ -2976,7 +2983,7 @@ mono_declsec_get_inheritdemands_class (MonoClass *klass, MonoDeclSecurityActions guint32 flags; /* quick exit if no declarative security is present in the metadata */ - if (!m_class_get_image (klass)->tables [MONO_TABLE_DECLSECURITY].rows) + if (!table_info_get_rows (&m_class_get_image (klass)->tables [MONO_TABLE_DECLSECURITY])) return FALSE; /* Here we use (or create) the class declarative cache to look for demands */ @@ -3001,7 +3008,7 @@ MonoBoolean mono_declsec_get_inheritdemands_method (MonoMethod *method, MonoDeclSecurityActions* demands) { /* quick exit if no declarative security is present in the metadata */ - if (!m_class_get_image (method->klass)->tables [MONO_TABLE_DECLSECURITY].rows) + if (!table_info_get_rows (&m_class_get_image (method->klass)->tables [MONO_TABLE_DECLSECURITY])) return FALSE; /* we want the original as the wrapper is "free" of the security informations */ @@ -3026,15 +3033,15 @@ static MonoBoolean get_declsec_action (MonoImage *image, guint32 token, guint32 action, MonoDeclSecurityEntry *entry) { guint32 cols [MONO_DECL_SECURITY_SIZE]; - MonoTableInfo *t; int i; int index = mono_metadata_declsec_from_index (image, token); if (index == -1) return FALSE; - t = &image->tables [MONO_TABLE_DECLSECURITY]; - for (i = index; i < t->rows; i++) { + MonoTableInfo *t = &image->tables [MONO_TABLE_DECLSECURITY]; + int rows = table_info_get_rows (t); + for (i = index; i < rows; i++) { mono_metadata_decode_row (t, i, cols, MONO_DECL_SECURITY_SIZE); /* shortcut - index are ordered */ diff --git a/src/mono/mono/mini/aot-compiler.c b/src/mono/mono/mini/aot-compiler.c index 14dd5380ef1970..c75493a74030a5 100644 --- a/src/mono/mono/mini/aot-compiler.c +++ b/src/mono/mono/mini/aot-compiler.c @@ -3226,7 +3226,7 @@ static guint32 find_typespec_for_class (MonoAotCompile *acfg, MonoClass *klass) { int i; - int len = acfg->image->tables [MONO_TABLE_TYPESPEC].rows; + int len = table_info_get_rows (&acfg->image->tables [MONO_TABLE_TYPESPEC]); /* FIXME: Search referenced images as well */ if (!acfg->typespec_classes) { @@ -4562,7 +4562,8 @@ add_wrappers (MonoAotCompile *acfg) * so there is only one wrapper of a given type, or inlining their contents into their * callers. */ - for (i = 0; i < acfg->image->tables [MONO_TABLE_METHOD].rows; ++i) { + int rows = table_info_get_rows (&acfg->image->tables [MONO_TABLE_METHOD]); + for (i = 0; i < rows; ++i) { ERROR_DECL (error); MonoMethod *method; guint32 token = MONO_TOKEN_METHOD_DEF | (i + 1); @@ -4739,7 +4740,8 @@ add_wrappers (MonoAotCompile *acfg) */ #if 0 /* remoting-invoke wrappers */ - for (i = 0; i < acfg->image->tables [MONO_TABLE_METHOD].rows; ++i) { + rows = table_info_get_rows (&acfg->image->tables [MONO_TABLE_METHOD]); + for (i = 0; i < rows; ++i) { ERROR_DECL (error); MonoMethodSignature *sig; @@ -4758,7 +4760,8 @@ add_wrappers (MonoAotCompile *acfg) #endif /* delegate-invoke wrappers */ - for (i = 0; i < acfg->image->tables [MONO_TABLE_TYPEDEF].rows; ++i) { + rows = table_info_get_rows (&acfg->image->tables [MONO_TABLE_TYPEDEF]); + for (i = 0; i < rows; ++i) { ERROR_DECL (error); MonoClass *klass; @@ -4876,7 +4879,8 @@ add_wrappers (MonoAotCompile *acfg) } /* array access wrappers */ - for (i = 0; i < acfg->image->tables [MONO_TABLE_TYPESPEC].rows; ++i) { + rows = table_info_get_rows (&acfg->image->tables [MONO_TABLE_TYPESPEC]); + for (i = 0; i < rows; ++i) { ERROR_DECL (error); MonoClass *klass; @@ -4910,7 +4914,8 @@ add_wrappers (MonoAotCompile *acfg) } /* Synchronized wrappers */ - for (i = 0; i < acfg->image->tables [MONO_TABLE_METHOD].rows; ++i) { + rows = table_info_get_rows (&acfg->image->tables [MONO_TABLE_METHOD]); + for (i = 0; i < rows; ++i) { ERROR_DECL (error); token = MONO_TOKEN_METHOD_DEF | (i + 1); method = mono_get_method_checked (acfg->image, token, NULL, NULL, error); @@ -4943,7 +4948,8 @@ add_wrappers (MonoAotCompile *acfg) } /* pinvoke wrappers */ - for (i = 0; i < acfg->image->tables [MONO_TABLE_METHOD].rows; ++i) { + rows = table_info_get_rows (&acfg->image->tables [MONO_TABLE_METHOD]); + for (i = 0; i < rows; ++i) { ERROR_DECL (error); MonoMethod *method; guint32 token = MONO_TOKEN_METHOD_DEF | (i + 1); @@ -4965,7 +4971,8 @@ add_wrappers (MonoAotCompile *acfg) } /* native-to-managed wrappers */ - for (i = 0; i < acfg->image->tables [MONO_TABLE_METHOD].rows; ++i) { + rows = table_info_get_rows (&acfg->image->tables [MONO_TABLE_METHOD]); + for (i = 0; i < rows; ++i) { ERROR_DECL (error); MonoMethod *method; guint32 token = MONO_TOKEN_METHOD_DEF | (i + 1); @@ -5130,7 +5137,8 @@ MONO_RESTORE_WARNING } /* StructureToPtr/PtrToStructure wrappers */ - for (i = 0; i < acfg->image->tables [MONO_TABLE_TYPEDEF].rows; ++i) { + rows = table_info_get_rows (&acfg->image->tables [MONO_TABLE_TYPEDEF]); + for (i = 0; i < rows; ++i) { ERROR_DECL (error); MonoClass *klass; @@ -5603,7 +5611,8 @@ add_generic_instances (MonoAotCompile *acfg) if (acfg->aot_opts.no_instances) return; - for (i = 0; i < acfg->image->tables [MONO_TABLE_METHODSPEC].rows; ++i) { + int rows = table_info_get_rows (&acfg->image->tables [MONO_TABLE_METHODSPEC]); + for (i = 0; i < rows; ++i) { ERROR_DECL (error); token = MONO_TOKEN_METHOD_SPEC | (i + 1); method = mono_get_method_checked (acfg->image, token, NULL, NULL, error); @@ -5712,7 +5721,8 @@ add_generic_instances (MonoAotCompile *acfg) add_extra_method (acfg, method); } - for (i = 0; i < acfg->image->tables [MONO_TABLE_TYPESPEC].rows; ++i) { + rows = table_info_get_rows (&acfg->image->tables [MONO_TABLE_TYPESPEC]); + for (i = 0; i < rows; ++i) { ERROR_DECL (error); MonoClass *klass; @@ -6053,7 +6063,6 @@ get_pinvoke_import (MonoAotCompile *acfg, MonoMethod *method) MonoMethodPInvoke *piinfo = (MonoMethodPInvoke *) method; MonoTableInfo *tables = image->tables; MonoTableInfo *im = &tables [MONO_TABLE_IMPLMAP]; - MonoTableInfo *mr = &tables [MONO_TABLE_MODULEREF]; guint32 im_cols [MONO_IMPLMAP_SIZE]; char *import; @@ -6061,12 +6070,13 @@ get_pinvoke_import (MonoAotCompile *acfg, MonoMethod *method) if (import != NULL) return import; - if (!piinfo->implmap_idx || piinfo->implmap_idx > im->rows) + if (piinfo->implmap_idx == 0 || mono_metadata_table_bounds_check (image, MONO_TABLE_IMPLMAP, piinfo->implmap_idx)) return NULL; mono_metadata_decode_row (im, piinfo->implmap_idx - 1, im_cols, MONO_IMPLMAP_SIZE); - if (!im_cols [MONO_IMPLMAP_SCOPE] || im_cols [MONO_IMPLMAP_SCOPE] > mr->rows) + int module_idx = im_cols [MONO_IMPLMAP_SCOPE]; + if (module_idx == 0 || mono_metadata_table_bounds_check (image, MONO_TABLE_MODULEREF, module_idx)) return NULL; import = g_strdup_printf ("%s", mono_metadata_string_heap (image, im_cols [MONO_IMPLMAP_NAME])); @@ -10923,11 +10933,12 @@ emit_class_info (MonoAotCompile *acfg) int i; gint32 *offsets; - offsets = g_new0 (gint32, acfg->image->tables [MONO_TABLE_TYPEDEF].rows); - for (i = 0; i < acfg->image->tables [MONO_TABLE_TYPEDEF].rows; ++i) + int rows = table_info_get_rows (&acfg->image->tables [MONO_TABLE_TYPEDEF]); + offsets = g_new0 (gint32, rows); + for (i = 0; i < rows; ++i) offsets [i] = emit_klass_info (acfg, MONO_TOKEN_TYPE_DEF | (i + 1)); - acfg->stats.offsets_size += emit_offset_table (acfg, "class_info_offsets", MONO_AOT_TABLE_CLASS_INFO_OFFSETS, acfg->image->tables [MONO_TABLE_TYPEDEF].rows, 10, offsets); + acfg->stats.offsets_size += emit_offset_table (acfg, "class_info_offsets", MONO_AOT_TABLE_CLASS_INFO_OFFSETS, rows, 10, offsets); g_free (offsets); } @@ -10950,11 +10961,12 @@ emit_class_name_table (MonoAotCompile *acfg) /* * Construct a chained hash table for mapping class names to typedef tokens. */ - table_size = g_spaced_primes_closest ((int)(acfg->image->tables [MONO_TABLE_TYPEDEF].rows * 1.5)); + int rows = table_info_get_rows (&acfg->image->tables [MONO_TABLE_TYPEDEF]); + table_size = g_spaced_primes_closest ((int)(rows * 1.5)); table = g_ptr_array_sized_new (table_size); for (i = 0; i < table_size; ++i) g_ptr_array_add (table, NULL); - for (i = 0; i < acfg->image->tables [MONO_TABLE_TYPEDEF].rows; ++i) { + for (i = 0; i < rows; ++i) { ERROR_DECL (error); token = MONO_TOKEN_TYPE_DEF | (i + 1); klass = mono_class_get_checked (acfg->image, token, error); @@ -12140,7 +12152,8 @@ collect_methods (MonoAotCompile *acfg) MonoImage *image = acfg->image; /* Collect methods */ - for (i = 0; i < image->tables [MONO_TABLE_METHOD].rows; ++i) { + int rows = table_info_get_rows (&image->tables [MONO_TABLE_METHOD]); + for (i = 0; i < rows; ++i) { ERROR_DECL (error); MonoMethod *method; guint32 token = MONO_TOKEN_METHOD_DEF | (i + 1); @@ -12196,7 +12209,8 @@ collect_methods (MonoAotCompile *acfg) } /* gsharedvt methods */ - for (mindex = 0; mindex < image->tables [MONO_TABLE_METHOD].rows; ++mindex) { + rows = table_info_get_rows (&image->tables [MONO_TABLE_METHOD]); + for (mindex = 0; mindex < rows; ++mindex) { ERROR_DECL (error); MonoMethod *method; guint32 token = MONO_TOKEN_METHOD_DEF | (mindex + 1); @@ -13915,7 +13929,8 @@ mono_compile_assembly (MonoAssembly *ass, guint32 opts, const char *aot_options, } if (!(mono_aot_mode_is_interp (&acfg->aot_opts) && !mono_aot_mode_is_full (&acfg->aot_opts))) { - for (int method_index = 0; method_index < acfg->image->tables [MONO_TABLE_METHOD].rows; ++method_index) + int rows = table_info_get_rows (&acfg->image->tables [MONO_TABLE_METHOD]); + for (int method_index = 0; method_index < rows; ++method_index) g_ptr_array_add (acfg->method_order,GUINT_TO_POINTER (method_index)); } diff --git a/src/mono/mono/mini/aot-runtime.c b/src/mono/mono/mini/aot-runtime.c index a1045c596915ab..fc683e7b4c0ffa 100644 --- a/src/mono/mono/mini/aot-runtime.c +++ b/src/mono/mono/mini/aot-runtime.c @@ -1979,7 +1979,7 @@ load_aot_module (MonoAssemblyLoadContext *alc, MonoAssembly *assembly, gpointer if (!sofile) { // Maybe do these on more platforms ? #ifndef HOST_WASM - if (mono_aot_only && !mono_use_interpreter && assembly->image->tables [MONO_TABLE_METHOD].rows) { + if (mono_aot_only && !mono_use_interpreter && table_info_get_rows (&assembly->image->tables [MONO_TABLE_METHOD])) { aot_name = g_strdup_printf ("%s%s", assembly->image->name, MONO_SOLIB_EXT); g_error ("Failed to load AOT module '%s' ('%s') in aot-only mode.\n", aot_name, assembly->image->name); g_free (aot_name); @@ -3543,7 +3543,7 @@ mono_aot_find_jit_info (MonoDomain *domain, MonoImage *image, gpointer addr) } if (!method) { - if (method_index >= image->tables [MONO_TABLE_METHOD].rows) { + if (method_index >= table_info_get_rows (&image->tables [MONO_TABLE_METHOD])) { /* * This is hit for extra methods which are called directly, so they are * not in amodule->extra_methods.