Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--configure.ac6
-rw-r--r--mono/metadata/Makefile.am2
-rw-r--r--mono/metadata/class-accessors.c84
-rw-r--r--mono/metadata/class-getters.h102
-rw-r--r--mono/metadata/class-inlines.h14
-rw-r--r--mono/metadata/class-internals.h199
-rw-r--r--mono/metadata/class-private-definition.h169
-rw-r--r--msvc/libmonoruntime-common.targets2
-rw-r--r--msvc/libmonoruntime-common.targets.filters6
9 files changed, 379 insertions, 205 deletions
diff --git a/configure.ac b/configure.ac
index 7cfb1121fa4..ea706cc6d14 100644
--- a/configure.ac
+++ b/configure.ac
@@ -4428,7 +4428,7 @@ fi
AM_CONDITIONAL([ENABLE_COOP], [test x$with_cooperative_gc != xno])
-AC_ARG_ENABLE(checked_build, [ --enable-checked-build=LIST To enable checked build (expensive asserts), configure with a comma-separated LIST of checked build modules and then include that same list in the environment variable MONO_CHECK_MODE at runtime. Recognized checked build modules: all, gc, metadata, thread],[
+AC_ARG_ENABLE(checked_build, [ --enable-checked-build=LIST To enable checked build (expensive asserts), configure with a comma-separated LIST of checked build modules and then include that same list in the environment variable MONO_CHECK_MODE at runtime. Recognized checked build modules: all, gc, metadata, thread, private_types],[
if test x$enable_checked_build != x ; then
AC_DEFINE(ENABLE_CHECKED_BUILD,1,[Enable checked build])
@@ -4441,6 +4441,7 @@ AC_ARG_ENABLE(checked_build, [ --enable-checked-build=LIST To enable check
eval "mono_checked_build_test_enable_gc='yes'"
eval "mono_checked_build_test_enable_metadata='yes'"
eval "mono_checked_build_test_enable_thread='yes'"
+ eval "mono_checked_build_test_enable_private_types='yes'"
fi
if test "x$mono_checked_build_test_enable_gc" = "xyes"; then
@@ -4455,6 +4456,9 @@ AC_ARG_ENABLE(checked_build, [ --enable-checked-build=LIST To enable check
AC_DEFINE(ENABLE_CHECKED_BUILD_THREAD, 1, [Enable thread checked build])
fi
+ if test "x$mono_checked_build_test_enable_private_types" = "xyes"; then
+ AC_DEFINE(ENABLE_CHECKED_BUILD_PRIVATE_TYPES, 1, [Enable private types checked build])
+ fi
], [])
AC_CHECK_HEADER([malloc.h],
diff --git a/mono/metadata/Makefile.am b/mono/metadata/Makefile.am
index c4d9bc00934..e3d382f0536 100644
--- a/mono/metadata/Makefile.am
+++ b/mono/metadata/Makefile.am
@@ -120,10 +120,12 @@ common_sources = \
attach.c \
cil-coff.h \
class.c \
+ class-getters.h \
class-init.h \
class-init.c \
class-internals.h \
class-inlines.h \
+ class-private-definition.h \
class-accessors.c \
cominterop.c \
cominterop.h \
diff --git a/mono/metadata/class-accessors.c b/mono/metadata/class-accessors.c
index 189cfbba3fb..b8b60d1afdc 100644
--- a/mono/metadata/class-accessors.c
+++ b/mono/metadata/class-accessors.c
@@ -6,7 +6,11 @@
#include <config.h>
#include <mono/metadata/class-internals.h>
#include <mono/metadata/tabledefs.h>
-
+#ifdef MONO_CLASS_DEF_PRIVATE
+#define REALLY_INCLUDE_CLASS_DEF 1
+#include <mono/metadata/class-private-definition.h>
+#undef REALLY_INCLUDE_CLASS_DEF
+#endif
typedef enum {
PROP_MARSHAL_INFO = 1, /* MonoMarshalType */
@@ -31,7 +35,7 @@ MonoGenericClass*
mono_class_get_generic_class (MonoClass *klass)
{
g_assert (mono_class_is_ginst (klass));
- return ((MonoClassGenericInst*)klass)->generic_class;
+ return m_classgenericinst_get_generic_class ((MonoClassGenericInst*)klass);
}
/*
@@ -43,7 +47,7 @@ MonoGenericClass*
mono_class_try_get_generic_class (MonoClass *klass)
{
if (mono_class_is_ginst (klass))
- return ((MonoClassGenericInst*)klass)->generic_class;
+ return m_classgenericinst_get_generic_class ((MonoClassGenericInst*)klass);
return NULL;
}
@@ -56,19 +60,19 @@ mono_class_try_get_generic_class (MonoClass *klass)
guint32
mono_class_get_flags (MonoClass *klass)
{
- switch (klass->class_kind) {
+ switch (m_class_get_class_kind (klass)) {
case MONO_CLASS_DEF:
case MONO_CLASS_GTD:
- return ((MonoClassDef*)klass)->flags;
+ return m_classdef_get_flags ((MonoClassDef*)klass);
case MONO_CLASS_GINST:
- return mono_class_get_flags (((MonoClassGenericInst*)klass)->generic_class->container_class);
+ return mono_class_get_flags (m_classgenericinst_get_generic_class ((MonoClassGenericInst*)klass)->container_class);
case MONO_CLASS_GPARAM:
return TYPE_ATTRIBUTE_PUBLIC;
case MONO_CLASS_ARRAY:
/* all arrays are marked serializable and sealed, bug #42779 */
return TYPE_ATTRIBUTE_CLASS | TYPE_ATTRIBUTE_SERIALIZABLE | TYPE_ATTRIBUTE_SEALED | TYPE_ATTRIBUTE_PUBLIC;
case MONO_CLASS_POINTER:
- return TYPE_ATTRIBUTE_CLASS | (mono_class_get_flags (klass->element_class) & TYPE_ATTRIBUTE_VISIBILITY_MASK);
+ return TYPE_ATTRIBUTE_CLASS | (mono_class_get_flags (m_class_get_element_class (klass)) & TYPE_ATTRIBUTE_VISIBILITY_MASK);
}
g_assert_not_reached ();
}
@@ -76,7 +80,7 @@ mono_class_get_flags (MonoClass *klass)
void
mono_class_set_flags (MonoClass *klass, guint32 flags)
{
- g_assert (klass->class_kind == MONO_CLASS_DEF || klass->class_kind == MONO_CLASS_GTD);
+ g_assert (m_class_get_class_kind (klass) == MONO_CLASS_DEF || m_class_get_class_kind (klass) == MONO_CLASS_GTD);
((MonoClassDef*)klass)->flags = flags;
}
@@ -90,14 +94,14 @@ mono_class_get_generic_container (MonoClass *klass)
{
g_assert (mono_class_is_gtd (klass));
- return ((MonoClassGtd*)klass)->generic_container;
+ return m_classgtd_get_generic_container ((MonoClassGtd*)klass);
}
MonoGenericContainer*
mono_class_try_get_generic_container (MonoClass *klass)
{
if (mono_class_is_gtd (klass))
- return ((MonoClassGtd*)klass)->generic_container;
+ return m_classgtd_get_generic_container ((MonoClassGtd*)klass);
return NULL;
}
@@ -120,7 +124,7 @@ mono_class_get_first_method_idx (MonoClass *klass)
{
g_assert (mono_class_has_static_metadata (klass));
- return ((MonoClassDef*)klass)->first_method_idx;
+ return m_classdef_get_first_method_idx ((MonoClassDef*)klass);
}
void
@@ -139,7 +143,7 @@ mono_class_get_first_field_idx (MonoClass *klass)
g_assert (mono_class_has_static_metadata (klass));
- return ((MonoClassDef*)klass)->first_field_idx;
+ return m_classdef_get_first_field_idx ((MonoClassDef*)klass);
}
void
@@ -153,16 +157,16 @@ mono_class_set_first_field_idx (MonoClass *klass, guint32 idx)
guint32
mono_class_get_method_count (MonoClass *klass)
{
- switch (klass->class_kind) {
+ switch (m_class_get_class_kind (klass)) {
case MONO_CLASS_DEF:
case MONO_CLASS_GTD:
- return ((MonoClassDef*)klass)->method_count;
+ return m_classdef_get_method_count ((MonoClassDef*)klass);
case MONO_CLASS_GINST:
- return mono_class_get_method_count (((MonoClassGenericInst*)klass)->generic_class->container_class);
+ return mono_class_get_method_count (m_classgenericinst_get_generic_class ((MonoClassGenericInst*)klass)->container_class);
case MONO_CLASS_GPARAM:
return 0;
case MONO_CLASS_ARRAY:
- return ((MonoClassArray*)klass)->method_count;
+ return m_classarray_get_method_count ((MonoClassArray*)klass);
case MONO_CLASS_POINTER:
return 0;
default:
@@ -174,7 +178,7 @@ mono_class_get_method_count (MonoClass *klass)
void
mono_class_set_method_count (MonoClass *klass, guint32 count)
{
- switch (klass->class_kind) {
+ switch (m_class_get_class_kind (klass)) {
case MONO_CLASS_DEF:
case MONO_CLASS_GTD:
((MonoClassDef*)klass)->method_count = count;
@@ -197,12 +201,12 @@ mono_class_set_method_count (MonoClass *klass, guint32 count)
guint32
mono_class_get_field_count (MonoClass *klass)
{
- switch (klass->class_kind) {
+ switch (m_class_get_class_kind (klass)) {
case MONO_CLASS_DEF:
case MONO_CLASS_GTD:
- return ((MonoClassDef*)klass)->field_count;
+ return m_classdef_get_field_count ((MonoClassDef*)klass);
case MONO_CLASS_GINST:
- return mono_class_get_field_count (((MonoClassGenericInst*)klass)->generic_class->container_class);
+ return mono_class_get_field_count (m_classgenericinst_get_generic_class ((MonoClassGenericInst*)klass)->container_class);
case MONO_CLASS_GPARAM:
case MONO_CLASS_ARRAY:
case MONO_CLASS_POINTER:
@@ -216,7 +220,7 @@ mono_class_get_field_count (MonoClass *klass)
void
mono_class_set_field_count (MonoClass *klass, guint32 count)
{
- switch (klass->class_kind) {
+ switch (m_class_get_class_kind (klass)) {
case MONO_CLASS_DEF:
case MONO_CLASS_GTD:
((MonoClassDef*)klass)->field_count = count;
@@ -237,14 +241,14 @@ mono_class_set_field_count (MonoClass *klass, guint32 count)
MonoMarshalType*
mono_class_get_marshal_info (MonoClass *klass)
{
- return mono_property_bag_get (&klass->infrequent_data, PROP_MARSHAL_INFO);
+ return mono_property_bag_get (m_class_get_infrequent_data (klass), PROP_MARSHAL_INFO);
}
void
mono_class_set_marshal_info (MonoClass *klass, MonoMarshalType *marshal_info)
{
marshal_info->head.tag = PROP_MARSHAL_INFO;
- mono_property_bag_add (&klass->infrequent_data, marshal_info);
+ mono_property_bag_add (m_class_get_infrequent_data (klass), marshal_info);
}
typedef struct {
@@ -255,7 +259,7 @@ typedef struct {
guint32
mono_class_get_ref_info_handle (MonoClass *klass)
{
- Uint32Property *prop = mono_property_bag_get (&klass->infrequent_data, PROP_REF_INFO_HANDLE);
+ Uint32Property *prop = mono_property_bag_get (m_class_get_infrequent_data (klass), PROP_REF_INFO_HANDLE);
return prop ? prop->value : 0;
}
@@ -263,7 +267,7 @@ guint32
mono_class_set_ref_info_handle (MonoClass *klass, guint32 value)
{
if (!value) {
- Uint32Property *prop = mono_property_bag_get (&klass->infrequent_data, PROP_REF_INFO_HANDLE);
+ Uint32Property *prop = mono_property_bag_get (m_class_get_infrequent_data (klass), PROP_REF_INFO_HANDLE);
if (prop)
prop->value = 0;
return 0;
@@ -272,7 +276,7 @@ mono_class_set_ref_info_handle (MonoClass *klass, guint32 value)
Uint32Property *prop = mono_class_alloc (klass, sizeof (Uint32Property));
prop->head.tag = PROP_REF_INFO_HANDLE;
prop->value = value;
- prop = mono_property_bag_add (&klass->infrequent_data, prop);
+ prop = mono_property_bag_add (m_class_get_infrequent_data (klass), prop);
return prop->value;
}
@@ -287,13 +291,13 @@ set_pointer_property (MonoClass *klass, InfrequentDataKind property, gpointer va
PointerProperty *prop = mono_class_alloc (klass, sizeof (PointerProperty));
prop->head.tag = property;
prop->value = value;
- mono_property_bag_add (&klass->infrequent_data, prop);
+ mono_property_bag_add (m_class_get_infrequent_data (klass), prop);
}
static gpointer
get_pointer_property (MonoClass *klass, InfrequentDataKind property)
{
- PointerProperty *prop = (PointerProperty*)mono_property_bag_get (&klass->infrequent_data, property);
+ PointerProperty *prop = (PointerProperty*)mono_property_bag_get (m_class_get_infrequent_data (klass), property);
return prop ? prop->value : NULL;
}
@@ -324,27 +328,27 @@ mono_class_set_nested_classes_property (MonoClass *klass, GList *value)
MonoClassPropertyInfo*
mono_class_get_property_info (MonoClass *klass)
{
- return mono_property_bag_get (&klass->infrequent_data, PROP_PROPERTY_INFO);
+ return mono_property_bag_get (m_class_get_infrequent_data (klass), PROP_PROPERTY_INFO);
}
void
mono_class_set_property_info (MonoClass *klass, MonoClassPropertyInfo *info)
{
info->head.tag = PROP_PROPERTY_INFO;
- mono_property_bag_add (&klass->infrequent_data, info);
+ mono_property_bag_add (m_class_get_infrequent_data (klass), info);
}
MonoClassEventInfo*
mono_class_get_event_info (MonoClass *klass)
{
- return mono_property_bag_get (&klass->infrequent_data, PROP_EVENT_INFO);
+ return mono_property_bag_get (m_class_get_infrequent_data (klass), PROP_EVENT_INFO);
}
void
mono_class_set_event_info (MonoClass *klass, MonoClassEventInfo *info)
{
info->head.tag = PROP_EVENT_INFO;
- mono_property_bag_add (&klass->infrequent_data, info);
+ mono_property_bag_add (m_class_get_infrequent_data (klass), info);
}
MonoFieldDefaultValue*
@@ -362,7 +366,7 @@ mono_class_set_field_def_values (MonoClass *klass, MonoFieldDefaultValue *values
guint32
mono_class_get_declsec_flags (MonoClass *klass)
{
- Uint32Property *prop = mono_property_bag_get (&klass->infrequent_data, PROP_DECLSEC_FLAGS);
+ Uint32Property *prop = mono_property_bag_get (m_class_get_infrequent_data (klass), PROP_DECLSEC_FLAGS);
return prop ? prop->value : 0;
}
@@ -372,7 +376,7 @@ mono_class_set_declsec_flags (MonoClass *klass, guint32 value)
Uint32Property *prop = mono_class_alloc (klass, sizeof (Uint32Property));
prop->head.tag = PROP_DECLSEC_FLAGS;
prop->value = value;
- mono_property_bag_add (&klass->infrequent_data, prop);
+ mono_property_bag_add (m_class_get_infrequent_data (klass), prop);
}
void
@@ -389,7 +393,7 @@ MonoType*
mono_class_gtd_get_canonical_inst (MonoClass *klass)
{
g_assert (mono_class_is_gtd (klass));
- return &((MonoClassGtd*)klass)->canonical_inst;
+ return m_classgtd_get_canonical_inst ((MonoClassGtd*)klass);
}
typedef struct {
@@ -407,15 +411,21 @@ mono_class_set_weak_bitmap (MonoClass *klass, int nbits, gsize *bits)
info->bits = bits;
info->head.tag = PROP_WEAK_BITMAP;
- mono_property_bag_add (&klass->infrequent_data, info);
+ mono_property_bag_add (m_class_get_infrequent_data (klass), info);
}
gsize*
mono_class_get_weak_bitmap (MonoClass *klass, int *nbits)
{
- WeakBitmapData *prop = mono_property_bag_get (&klass->infrequent_data, PROP_WEAK_BITMAP);
+ WeakBitmapData *prop = mono_property_bag_get (m_class_get_infrequent_data (klass), PROP_WEAK_BITMAP);
g_assert (prop);
*nbits = prop->nbits;
return prop->bits;
}
+
+#ifdef MONO_CLASS_DEF_PRIVATE
+#define MONO_CLASS_GETTER(funcname, rettype, optref, argtype, fieldname) rettype funcname (argtype *klass) { return optref klass-> fieldname ; }
+#include "class-getters.h"
+#undef MONO_CLASS_GETTER
+#endif /* MONO_CLASS_DEF_PRIVATE */
diff --git a/mono/metadata/class-getters.h b/mono/metadata/class-getters.h
new file mode 100644
index 00000000000..0e2263a423a
--- /dev/null
+++ b/mono/metadata/class-getters.h
@@ -0,0 +1,102 @@
+/*
+ * \file Definitions of getters for the fields of struct _MonoClass
+ *
+ * Copyright 2018 Microsoft
+ * Licensed under the MIT license. See LICENSE file in the project root for full license information.
+ */
+
+/* No include guards - this file is meant to be included multiple times.
+ * Before including the file define the following macros:
+ * MONO_CLASS_GETTER(funcname, rettype, optref, argtype, fieldname)
+ */
+
+/* Accessors for _MonoClass fields. */
+MONO_CLASS_GETTER(m_class_get_element_class, MonoClass *, , MonoClass, element_class)
+MONO_CLASS_GETTER(m_class_get_cast_class, MonoClass *, , MonoClass, cast_class)
+MONO_CLASS_GETTER(m_class_get_supertypes, MonoClass **, , MonoClass, supertypes)
+MONO_CLASS_GETTER(m_class_get_idepth, guint16, , MonoClass, idepth)
+MONO_CLASS_GETTER(m_class_get_rank, guint8, , MonoClass, rank)
+MONO_CLASS_GETTER(m_class_get_instance_size, int, , MonoClass, instance_size)
+MONO_CLASS_GETTER(m_class_is_inited, gboolean, , MonoClass, inited)
+MONO_CLASS_GETTER(m_class_is_size_inited, gboolean, , MonoClass, size_inited)
+MONO_CLASS_GETTER(m_class_is_valuetype, gboolean, , MonoClass, valuetype)
+MONO_CLASS_GETTER(m_class_is_enumtype, gboolean, , MonoClass, enumtype)
+MONO_CLASS_GETTER(m_class_is_blittable, gboolean, , MonoClass, blittable)
+MONO_CLASS_GETTER(m_class_is_unicode, gboolean, , MonoClass, unicode)
+MONO_CLASS_GETTER(m_class_was_typebuilder, gboolean, , MonoClass, wastypebuilder)
+MONO_CLASS_GETTER(m_class_is_array_special_interface, gboolean, , MonoClass, is_array_special_interface)
+MONO_CLASS_GETTER(m_class_get_min_align, guint8, , MonoClass, min_align)
+MONO_CLASS_GETTER(m_class_get_packing_size, guint, , MonoClass, packing_size)
+MONO_CLASS_GETTER(m_class_is_ghcimpl, gboolean, , MonoClass, ghcimpl)
+MONO_CLASS_GETTER(m_class_has_finalize, gboolean, , MonoClass, has_finalize)
+#ifndef DISABLE_REMOTING
+MONO_CLASS_GETTER(m_class_get_marshalbyref, guint, , MonoClass, marshalbyref)
+MONO_CLASS_GETTER(m_class_get_contextbound, guint, , MonoClass, contextbound)
+#endif
+MONO_CLASS_GETTER(m_class_is_delegate, gboolean, , MonoClass, delegate)
+MONO_CLASS_GETTER(m_class_is_gc_descr_inited, gboolean, , MonoClass, gc_descr_inited)
+MONO_CLASS_GETTER(m_class_has_cctor, gboolean, , MonoClass, has_cctor)
+MONO_CLASS_GETTER(m_class_has_references, gboolean, , MonoClass, has_references)
+MONO_CLASS_GETTER(m_class_has_static_refs, gboolean, , MonoClass, has_static_refs)
+MONO_CLASS_GETTER(m_class_has_no_special_static_fields, gboolean, , MonoClass, no_special_static_fields)
+MONO_CLASS_GETTER(m_class_is_com_object, gboolean, , MonoClass, is_com_object)
+MONO_CLASS_GETTER(m_class_is_nested_classes_inited, gboolean, , MonoClass, nested_classes_inited)
+MONO_CLASS_GETTER(m_class_get_class_kind, guint, , MonoClass, class_kind)
+MONO_CLASS_GETTER(m_class_is_interfaces_inited, gboolean, , MonoClass, interfaces_inited)
+MONO_CLASS_GETTER(m_class_is_simd_type, gboolean, , MonoClass, simd_type)
+MONO_CLASS_GETTER(m_class_is_has_finalize_inited, gboolean, , MonoClass, has_finalize_inited)
+MONO_CLASS_GETTER(m_class_is_fields_inited, gboolean, , MonoClass, fields_inited)
+MONO_CLASS_GETTER(m_class_has_failure, gboolean, , MonoClass, has_failure)
+MONO_CLASS_GETTER(m_class_has_weak_fields, gboolean, , MonoClass, has_weak_fields)
+MONO_CLASS_GETTER(m_class_get_parent, MonoClass *, , MonoClass, parent)
+MONO_CLASS_GETTER(m_class_get_nested_in, MonoClass *, , MonoClass, nested_in)
+MONO_CLASS_GETTER(m_class_get_image, MonoImage *, , MonoClass, image)
+MONO_CLASS_GETTER(m_class_get_name, const char *, , MonoClass, name)
+MONO_CLASS_GETTER(m_class_get_name_space, const char *, , MonoClass, name_space)
+MONO_CLASS_GETTER(m_class_get_type_token, guint32, , MonoClass, type_token)
+MONO_CLASS_GETTER(m_class_get_vtable_size, int, , MonoClass, vtable_size)
+MONO_CLASS_GETTER(m_class_get_interface_count, guint16, , MonoClass, interface_count)
+MONO_CLASS_GETTER(m_class_get_interface_id, guint32, , MonoClass, interface_id)
+MONO_CLASS_GETTER(m_class_get_max_interface_id, guint32, , MonoClass, max_interface_id)
+MONO_CLASS_GETTER(m_class_get_interface_offsets_count, guint16, , MonoClass, interface_offsets_count)
+MONO_CLASS_GETTER(m_class_get_interfaces_packed, MonoClass **, , MonoClass, interfaces_packed)
+MONO_CLASS_GETTER(m_class_get_interface_offsets_packed, guint16 *, , MonoClass, interface_offsets_packed)
+MONO_CLASS_GETTER(m_class_get_interface_bitmap, guint8 *, , MonoClass, interface_bitmap)
+MONO_CLASS_GETTER(m_class_get_interfaces, MonoClass **, , MonoClass, interfaces)
+MONO_CLASS_GETTER(m_class_get_sizes, union _MonoClassSizes, , MonoClass, sizes)
+MONO_CLASS_GETTER(m_class_get_fields, MonoClassField *, , MonoClass, fields)
+MONO_CLASS_GETTER(m_class_get_methods, MonoMethod **, , MonoClass, methods)
+MONO_CLASS_GETTER(m_class_get_this_arg, MonoType*, &, MonoClass, this_arg)
+MONO_CLASS_GETTER(m_class_get_byval_arg, MonoType*, &, MonoClass, byval_arg)
+MONO_CLASS_GETTER(m_class_get_gc_descr, MonoGCDescriptor, , MonoClass, gc_descr)
+MONO_CLASS_GETTER(m_class_get_runtime_info, MonoClassRuntimeInfo *, , MonoClass, runtime_info)
+MONO_CLASS_GETTER(m_class_get_vtable, MonoMethod **, , MonoClass, vtable)
+MONO_CLASS_GETTER(m_class_get_infrequent_data, MonoPropertyBag*, &, MonoClass, infrequent_data)
+
+/* Accessors for _MonoClassDef fields. */
+MONO_CLASS_GETTER(m_classdef_get_klass, MonoClass*, &, MonoClassDef, klass)
+MONO_CLASS_GETTER(m_classdef_get_flags, guint32, , MonoClassDef, flags)
+MONO_CLASS_GETTER(m_classdef_get_first_method_idx, guint32, , MonoClassDef, first_method_idx)
+MONO_CLASS_GETTER(m_classdef_get_first_field_idx, guint32, , MonoClassDef, first_field_idx)
+MONO_CLASS_GETTER(m_classdef_get_method_count, guint32, , MonoClassDef, method_count)
+MONO_CLASS_GETTER(m_classdef_get_field_count, guint32, , MonoClassDef, field_count)
+MONO_CLASS_GETTER(m_classdef_get_next_class_cache, MonoClass *, , MonoClassDef, next_class_cache)
+
+/* Accessors for _MonoClassGtd fields. */
+MONO_CLASS_GETTER(m_classgtd_get_klass, MonoClassDef*, &, MonoClassGtd, klass)
+MONO_CLASS_GETTER(m_classgtd_get_generic_container, MonoGenericContainer*, , MonoClassGtd, generic_container)
+MONO_CLASS_GETTER(m_classgtd_get_canonical_inst, MonoType*, &, MonoClassGtd, canonical_inst)
+
+/* Accessors for _MonoClassGenericInst fields. */
+MONO_CLASS_GETTER(m_classgenericinst_get_klass, MonoClass*, &, MonoClassGenericInst, klass)
+MONO_CLASS_GETTER(m_classgenericinst_get_generic_class, MonoGenericClass*, , MonoClassGenericInst, generic_class)
+
+/* Accessors for _MonoClassGenericParam fields. */
+MONO_CLASS_GETTER(m_classgenericparam_get_klass, MonoClass*, &, MonoClassGenericParam, klass)
+
+/* Accessors for _MonoClassArray fields. */
+MONO_CLASS_GETTER(m_classarray_get_klass, MonoClass*, &, MonoClassArray, klass)
+MONO_CLASS_GETTER(m_classarray_get_method_count, guint32, , MonoClassArray, method_count)
+
+/* Accessors for _MonoClassPointer fields. */
+MONO_CLASS_GETTER(m_classpointer_get_klass, MonoClass*, &, MonoClassPointer, klass)
diff --git a/mono/metadata/class-inlines.h b/mono/metadata/class-inlines.h
index d57d5310cc5..44f128bef89 100644
--- a/mono/metadata/class-inlines.h
+++ b/mono/metadata/class-inlines.h
@@ -12,37 +12,37 @@
static inline gboolean
mono_class_is_def (MonoClass *klass)
{
- return klass->class_kind == MONO_CLASS_DEF;
+ return m_class_get_class_kind (klass) == MONO_CLASS_DEF;
}
static inline gboolean
mono_class_is_gtd (MonoClass *klass)
{
- return klass->class_kind == MONO_CLASS_GTD;
+ return m_class_get_class_kind (klass) == MONO_CLASS_GTD;
}
static inline gboolean
mono_class_is_ginst (MonoClass *klass)
{
- return klass->class_kind == MONO_CLASS_GINST;
+ return m_class_get_class_kind (klass) == MONO_CLASS_GINST;
}
static inline gboolean
mono_class_is_gparam (MonoClass *klass)
{
- return klass->class_kind == MONO_CLASS_GPARAM;
+ return m_class_get_class_kind (klass) == MONO_CLASS_GPARAM;
}
static inline gboolean
mono_class_is_array (MonoClass *klass)
{
- return klass->class_kind == MONO_CLASS_ARRAY;
+ return m_class_get_class_kind (klass) == MONO_CLASS_ARRAY;
}
static inline gboolean
mono_class_is_pointer (MonoClass *klass)
{
- return klass->class_kind == MONO_CLASS_POINTER;
+ return m_class_get_class_kind (klass) == MONO_CLASS_POINTER;
}
static inline gboolean
@@ -90,7 +90,7 @@ mono_class_is_public (MonoClass *klass)
static inline gboolean
mono_class_has_static_metadata (MonoClass *klass)
{
- return klass->type_token && !klass->image->dynamic && !mono_class_is_ginst (klass);
+ return m_class_get_type_token (klass) && !m_class_get_image (klass)->dynamic && !mono_class_is_ginst (klass);
}
#endif
diff --git a/mono/metadata/class-internals.h b/mono/metadata/class-internals.h
index 39968552d8d..a52676d4867 100644
--- a/mono/metadata/class-internals.h
+++ b/mono/metadata/class-internals.h
@@ -15,9 +15,9 @@
#include "mono/utils/mono-error.h"
#include "mono/sgen/gc-internal-agnostic.h"
-#define MONO_CLASS_IS_ARRAY(c) ((c)->rank)
+#define MONO_CLASS_IS_ARRAY(c) (m_class_get_rank (c))
-#define MONO_CLASS_HAS_STATIC_METADATA(klass) ((klass)->type_token && !(klass)->image->dynamic && !mono_class_is_ginst (klass))
+#define MONO_CLASS_HAS_STATIC_METADATA(klass) (m_class_get_type_token (klass) && !m_class_get_image (klass)->dynamic && !mono_class_is_ginst (klass))
#define MONO_DEFAULT_SUPERTABLE_SIZE 6
@@ -260,167 +260,46 @@ typedef enum {
MONO_CLASS_POINTER, /* pointer of function pointer*/
} MonoTypeKind;
-struct _MonoClass {
- /* element class for arrays and enum basetype for enums */
- MonoClass *element_class;
- /* used for subtype checks */
- MonoClass *cast_class;
+typedef struct _MonoClassDef MonoClassDef;
+typedef struct _MonoClassGtd MonoClassGtd;
+typedef struct _MonoClassGenericInst MonoClassGenericInst;
+typedef struct _MonoClassGenericParam MonoClassGenericParam;
+typedef struct _MonoClassArray MonoClassArray;
+typedef struct _MonoClassPointer MonoClassPointer;
- /* for fast subtype checks */
- MonoClass **supertypes;
- guint16 idepth;
-
- /* array dimension */
- guint8 rank;
-
- int instance_size; /* object instance size */
-
- guint inited : 1;
-
- /* A class contains static and non static data. Static data can be
- * of the same type as the class itselfs, but it does not influence
- * the instance size of the class. To avoid cyclic calls to
- * mono_class_init (from mono_class_instance_size ()) we first
- * initialise all non static fields. After that we set size_inited
- * to 1, because we know the instance size now. After that we
- * initialise all static fields.
- */
-
- /* ALL BITFIELDS SHOULD BE WRITTEN WHILE HOLDING THE LOADER LOCK */
- guint size_inited : 1;
- guint valuetype : 1; /* derives from System.ValueType */
- guint enumtype : 1; /* derives from System.Enum */
- guint blittable : 1; /* class is blittable */
- guint unicode : 1; /* class uses unicode char when marshalled */
- guint wastypebuilder : 1; /* class was created at runtime from a TypeBuilder */
- guint is_array_special_interface : 1; /* gtd or ginst of once of the magic interfaces that arrays implement */
-
- /* next byte */
- guint8 min_align;
-
- /* next byte */
- guint packing_size : 4;
- guint ghcimpl : 1; /* class has its own GetHashCode impl */
- guint has_finalize : 1; /* class has its own Finalize impl */
-#ifndef DISABLE_REMOTING
- guint marshalbyref : 1; /* class is a MarshalByRefObject */
- guint contextbound : 1; /* class is a ContextBoundObject */
-#endif
- /* next byte */
- guint delegate : 1; /* class is a Delegate */
- guint gc_descr_inited : 1; /* gc_descr is initialized */
- guint has_cctor : 1; /* class has a cctor */
- guint has_references : 1; /* it has GC-tracked references in the instance */
- guint has_static_refs : 1; /* it has static fields that are GC-tracked */
- guint no_special_static_fields : 1; /* has no thread/context static fields */
- /* directly or indirectly derives from ComImport attributed class.
- * this means we need to create a proxy for instances of this class
- * for COM Interop. set this flag on loading so all we need is a quick check
- * during object creation rather than having to traverse supertypes
- */
- guint is_com_object : 1;
- guint nested_classes_inited : 1; /* Whenever nested_class is initialized */
-
- /* next byte*/
- guint class_kind : 3; /* One of the values from MonoTypeKind */
- guint interfaces_inited : 1; /* interfaces is initialized */
- guint simd_type : 1; /* class is a simd intrinsic type */
- guint has_finalize_inited : 1; /* has_finalize is initialized */
- guint fields_inited : 1; /* setup_fields () has finished */
- guint has_failure : 1; /* See mono_class_get_exception_data () for a MonoErrorBoxed with the details */
- guint has_weak_fields : 1; /* class has weak reference fields */
-
- MonoClass *parent;
- MonoClass *nested_in;
-
- MonoImage *image;
- const char *name;
- const char *name_space;
-
- guint32 type_token;
- int vtable_size; /* number of slots */
-
- guint16 interface_count;
- guint32 interface_id; /* unique inderface id (for interfaces) */
- guint32 max_interface_id;
-
- guint16 interface_offsets_count;
- MonoClass **interfaces_packed;
- guint16 *interface_offsets_packed;
-/* enabled only with small config for now: we might want to do it unconditionally */
-#ifdef MONO_SMALL_CONFIG
-#define COMPRESSED_INTERFACE_BITMAP 1
-#endif
- guint8 *interface_bitmap;
-
- MonoClass **interfaces;
-
- union {
+union _MonoClassSizes {
int class_size; /* size of area for static fields */
int element_size; /* for array types */
int generic_param_token; /* for generic param types, both var and mvar */
- } sizes;
-
- /*
- * Field information: Type and location from object base
- */
- MonoClassField *fields;
-
- MonoMethod **methods;
-
- /* used as the type of the this argument and when passing the arg by value */
- MonoType this_arg;
- MonoType byval_arg;
-
- MonoGCDescriptor gc_descr;
-
- MonoClassRuntimeInfo *runtime_info;
-
- /* Generic vtable. Initialized by a call to mono_class_setup_vtable () */
- MonoMethod **vtable;
-
- /* Infrequently used items. See class-accessors.c: InfrequentDataKind for what goes into here. */
- MonoPropertyBag infrequent_data;
};
-typedef struct {
- MonoClass klass;
- guint32 flags;
- /*
- * From the TypeDef table
- */
- guint32 first_method_idx;
- guint32 first_field_idx;
- guint32 method_count, field_count;
- /* next element in the class_cache hash list (in MonoImage) */
- MonoClass *next_class_cache;
-} MonoClassDef;
-
-typedef struct {
- MonoClassDef klass;
- MonoGenericContainer *generic_container;
- /* The canonical GENERICINST where we instantiate a generic type definition with its own generic parameters.*/
- /* Suppose we have class T`2<A,B> {...}. canonical_inst is the GTD T`2 applied to A and B. */
- MonoType canonical_inst;
-} MonoClassGtd;
+/* enabled only with small config for now: we might want to do it unconditionally */
+#ifdef MONO_SMALL_CONFIG
+#define COMPRESSED_INTERFACE_BITMAP 1
+#endif
-typedef struct {
- MonoClass klass;
- MonoGenericClass *generic_class;
-} MonoClassGenericInst;
-typedef struct {
- MonoClass klass;
-} MonoClassGenericParam;
+#ifdef ENABLE_CHECKED_BUILD_PRIVATE_TYPES
+#define MONO_CLASS_DEF_PRIVATE 1
+#endif
-typedef struct {
- MonoClass klass;
- guint32 method_count;
-} MonoClassArray;
+/* Hide _MonoClass definition in checked build mode to ensure that
+ * it is only accessed via getter and setter methods.
+ */
+#ifndef MONO_CLASS_DEF_PRIVATE
+#include "class-private-definition.h"
+#endif
-typedef struct {
- MonoClass klass;
-} MonoClassPointer;
+/* If MonoClass definition is hidden, just declare the getters.
+ * Otherwise, define them as static inline functions.
+ */
+#ifdef MONO_CLASS_DEF_PRIVATE
+#define MONO_CLASS_GETTER(funcname, rettype, optref, argtype, fieldname) rettype funcname (argtype *klass);
+#else
+#define MONO_CLASS_GETTER(funcname, rettype, optref, argtype, fieldname) static inline rettype funcname (argtype *klass) { return optref klass-> fieldname ; }
+#endif
+#include "class-getters.h"
+#undef MONO_CLASS_GETTER
#ifdef COMPRESSED_INTERFACE_BITMAP
int mono_compress_bitmap (uint8_t *dest, const uint8_t *bitmap, int size);
@@ -429,7 +308,7 @@ int mono_class_interface_match (const uint8_t *bitmap, int id);
#define mono_class_interface_match(bmap,uiid) ((bmap) [(uiid) >> 3] & (1 << ((uiid)&7)))
#endif
-#define MONO_CLASS_IMPLEMENTS_INTERFACE(k,uiid) (((uiid) <= (k)->max_interface_id) && mono_class_interface_match ((k)->interface_bitmap, (uiid)))
+#define MONO_CLASS_IMPLEMENTS_INTERFACE(k,uiid) (((uiid) <= m_class_get_max_interface_id (k)) && mono_class_interface_match (m_class_get_interface_bitmap (k), (uiid)))
#define MONO_VTABLE_AVAILABLE_GC_BITS 4
@@ -439,8 +318,8 @@ int mono_class_interface_match (const uint8_t *bitmap, int id);
#define mono_vtable_is_remote(vtable) (FALSE)
#define mono_vtable_set_is_remote(vtable,enable) do {} while (0)
#else
-#define mono_class_is_marshalbyref(klass) ((klass)->marshalbyref)
-#define mono_class_is_contextbound(klass) ((klass)->contextbound)
+#define mono_class_is_marshalbyref(klass) (m_class_get_marshalbyref (klass))
+#define mono_class_is_contextbound(klass) (m_class_get_contextbound (klass))
#define mono_vtable_is_remote(vtable) ((vtable)->remote)
#define mono_vtable_set_is_remote(vtable,enable) do { (vtable)->remote = enable ? 1 : 0; } while (0)
#endif
@@ -448,7 +327,7 @@ int mono_class_interface_match (const uint8_t *bitmap, int id);
#ifdef DISABLE_COM
#define mono_class_is_com_object(klass) (FALSE)
#else
-#define mono_class_is_com_object(klass) ((klass)->is_com_object)
+#define mono_class_is_com_object(klass) (m_class_is_com_object (klass))
#endif
@@ -733,16 +612,16 @@ mono_class_setup_supertypes (MonoClass *klass);
static inline gboolean
mono_class_has_parent_fast (MonoClass *klass, MonoClass *parent)
{
- return (klass->idepth >= parent->idepth) && (klass->supertypes [parent->idepth - 1] == parent);
+ return (m_class_get_idepth (klass) >= m_class_get_idepth (parent)) && (m_class_get_supertypes (klass) [m_class_get_idepth (parent) - 1] == parent);
}
static inline gboolean
mono_class_has_parent (MonoClass *klass, MonoClass *parent)
{
- if (G_UNLIKELY (!klass->supertypes))
+ if (G_UNLIKELY (!m_class_get_supertypes (klass)))
mono_class_setup_supertypes (klass);
- if (G_UNLIKELY (!parent->supertypes))
+ if (G_UNLIKELY (!m_class_get_supertypes (parent)))
mono_class_setup_supertypes (parent);
return mono_class_has_parent_fast (klass, parent);
diff --git a/mono/metadata/class-private-definition.h b/mono/metadata/class-private-definition.h
new file mode 100644
index 00000000000..90719cce0b7
--- /dev/null
+++ b/mono/metadata/class-private-definition.h
@@ -0,0 +1,169 @@
+/**
+ * \file Definitions of struct _MonoClass members
+ *
+ * NOTE: This file should NOT be included directly.
+ */
+
+#if defined(MONO_CLASS_DEF_PRIVATE) && !defined(REALLY_INCLUDE_CLASS_DEF)
+#error struct _MonoClass definition should not be accessed directly
+#endif
+
+#ifndef __MONO_METADATA_CLASS_PRIVATE_DEFINITION_H__
+#define __MONO_METADATA_CLASS_PRIVATE_DEFINITION_H__
+
+struct _MonoClass {
+ /* element class for arrays and enum basetype for enums */
+ MonoClass *element_class;
+ /* used for subtype checks */
+ MonoClass *cast_class;
+
+ /* for fast subtype checks */
+ MonoClass **supertypes;
+ guint16 idepth;
+
+ /* array dimension */
+ guint8 rank;
+
+ int instance_size; /* object instance size */
+
+ guint inited : 1;
+
+ /* A class contains static and non static data. Static data can be
+ * of the same type as the class itselfs, but it does not influence
+ * the instance size of the class. To avoid cyclic calls to
+ * mono_class_init (from mono_class_instance_size ()) we first
+ * initialise all non static fields. After that we set size_inited
+ * to 1, because we know the instance size now. After that we
+ * initialise all static fields.
+ */
+
+ /* ALL BITFIELDS SHOULD BE WRITTEN WHILE HOLDING THE LOADER LOCK */
+ guint size_inited : 1;
+ guint valuetype : 1; /* derives from System.ValueType */
+ guint enumtype : 1; /* derives from System.Enum */
+ guint blittable : 1; /* class is blittable */
+ guint unicode : 1; /* class uses unicode char when marshalled */
+ guint wastypebuilder : 1; /* class was created at runtime from a TypeBuilder */
+ guint is_array_special_interface : 1; /* gtd or ginst of once of the magic interfaces that arrays implement */
+
+ /* next byte */
+ guint8 min_align;
+
+ /* next byte */
+ guint packing_size : 4;
+ guint ghcimpl : 1; /* class has its own GetHashCode impl */
+ guint has_finalize : 1; /* class has its own Finalize impl */
+#ifndef DISABLE_REMOTING
+ guint marshalbyref : 1; /* class is a MarshalByRefObject */
+ guint contextbound : 1; /* class is a ContextBoundObject */
+#endif
+ /* next byte */
+ guint delegate : 1; /* class is a Delegate */
+ guint gc_descr_inited : 1; /* gc_descr is initialized */
+ guint has_cctor : 1; /* class has a cctor */
+ guint has_references : 1; /* it has GC-tracked references in the instance */
+ guint has_static_refs : 1; /* it has static fields that are GC-tracked */
+ guint no_special_static_fields : 1; /* has no thread/context static fields */
+ /* directly or indirectly derives from ComImport attributed class.
+ * this means we need to create a proxy for instances of this class
+ * for COM Interop. set this flag on loading so all we need is a quick check
+ * during object creation rather than having to traverse supertypes
+ */
+ guint is_com_object : 1;
+ guint nested_classes_inited : 1; /* Whenever nested_class is initialized */
+
+ /* next byte*/
+ guint class_kind : 3; /* One of the values from MonoTypeKind */
+ guint interfaces_inited : 1; /* interfaces is initialized */
+ guint simd_type : 1; /* class is a simd intrinsic type */
+ guint has_finalize_inited : 1; /* has_finalize is initialized */
+ guint fields_inited : 1; /* setup_fields () has finished */
+ guint has_failure : 1; /* See mono_class_get_exception_data () for a MonoErrorBoxed with the details */
+ guint has_weak_fields : 1; /* class has weak reference fields */
+
+ MonoClass *parent;
+ MonoClass *nested_in;
+
+ MonoImage *image;
+ const char *name;
+ const char *name_space;
+
+ guint32 type_token;
+ int vtable_size; /* number of slots */
+
+ guint16 interface_count;
+ guint32 interface_id; /* unique inderface id (for interfaces) */
+ guint32 max_interface_id;
+
+ guint16 interface_offsets_count;
+ MonoClass **interfaces_packed;
+ guint16 *interface_offsets_packed;
+ guint8 *interface_bitmap;
+
+ MonoClass **interfaces;
+
+ union _MonoClassSizes sizes;
+
+ /*
+ * Field information: Type and location from object base
+ */
+ MonoClassField *fields;
+
+ MonoMethod **methods;
+
+ /* used as the type of the this argument and when passing the arg by value */
+ MonoType this_arg;
+ MonoType byval_arg;
+
+ MonoGCDescriptor gc_descr;
+
+ MonoClassRuntimeInfo *runtime_info;
+
+ /* Generic vtable. Initialized by a call to mono_class_setup_vtable () */
+ MonoMethod **vtable;
+
+ /* Infrequently used items. See class-accessors.c: InfrequentDataKind for what goes into here. */
+ MonoPropertyBag infrequent_data;
+};
+
+struct _MonoClassDef {
+ MonoClass klass;
+ guint32 flags;
+ /*
+ * From the TypeDef table
+ */
+ guint32 first_method_idx;
+ guint32 first_field_idx;
+ guint32 method_count, field_count;
+ /* next element in the class_cache hash list (in MonoImage) */
+ MonoClass *next_class_cache;
+};
+
+struct _MonoClassGtd {
+ MonoClassDef klass;
+ MonoGenericContainer *generic_container;
+ /* The canonical GENERICINST where we instantiate a generic type definition with its own generic parameters.*/
+ /* Suppose we have class T`2<A,B> {...}. canonical_inst is the GTD T`2 applied to A and B. */
+ MonoType canonical_inst;
+};
+
+struct _MonoClassGenericInst {
+ MonoClass klass;
+ MonoGenericClass *generic_class;
+};
+
+struct _MonoClassGenericParam {
+ MonoClass klass;
+};
+
+struct _MonoClassArray {
+ MonoClass klass;
+ guint32 method_count;
+};
+
+struct _MonoClassPointer {
+ MonoClass klass;
+};
+
+
+#endif
diff --git a/msvc/libmonoruntime-common.targets b/msvc/libmonoruntime-common.targets
index 82e809cc046..c52db52cb7e 100644
--- a/msvc/libmonoruntime-common.targets
+++ b/msvc/libmonoruntime-common.targets
@@ -13,11 +13,13 @@
<ClCompile Include="$(MonoSourceLocation)\mono\metadata\attach.c" />
<ClInclude Include="$(MonoSourceLocation)\mono\metadata\cil-coff.h" />
<ClCompile Include="$(MonoSourceLocation)\mono\metadata\class.c" />
+ <ClInclude Include="$(MonoSourceLocation)\mono\metadata\class-getters.h" />
<ClInclude Include="$(MonoSourceLocation)\mono\metadata\class-internals.h" />
<ClInclude Include="$(MonoSourceLocation)\mono\metadata\class-inlines.h" />
<ClCompile Include="$(MonoSourceLocation)\mono\metadata\class-init.c" />
<ClInclude Include="$(MonoSourceLocation)\mono\metadata\class-init.h" />
<ClCompile Include="$(MonoSourceLocation)\mono\metadata\class-accessors.c" />
+ <ClInclude Include="$(MonosourceLocation)\mono\metadata\class-private-definition.h" />
<ClCompile Include="$(MonoSourceLocation)\mono\metadata\cominterop.c" />
<ClInclude Include="$(MonoSourceLocation)\mono\metadata\cominterop.h" />
<ClInclude Include="$(MonoSourceLocation)\mono\metadata\console-io.h" />
diff --git a/msvc/libmonoruntime-common.targets.filters b/msvc/libmonoruntime-common.targets.filters
index 6892b165a04..2d501392ae7 100644
--- a/msvc/libmonoruntime-common.targets.filters
+++ b/msvc/libmonoruntime-common.targets.filters
@@ -28,6 +28,9 @@
<ClCompile Include="$(MonoSourceLocation)\mono\metadata\class.c">
<Filter>Source Files$(MonoRuntimeFilterSubFolder)\common</Filter>
</ClCompile>
+ <ClInclude Include="$(MonoSourceLocation)\mono\metadata\class-getters.h">
+ <Filter>Header Files$(MonoRuntimeFilterSubFolder)\common</Filter>
+ </ClInclude>
<ClInclude Include="$(MonoSourceLocation)\mono\metadata\class-internals.h">
<Filter>Header Files$(MonoRuntimeFilterSubFolder)\common</Filter>
</ClInclude>
@@ -43,6 +46,9 @@
<ClInclude Include="$(MonoSourceLocation)\mono\metadata\class-init.h">
<Filter>Header Files$(MonoRuntimeFilterSubFolder)\common</Filter>
</ClInclude>
+ <ClInclude Include="$(MonoSourceLocation)\mono\metadata\class-private-definition.h">
+ <Filter>Header Files$(MonoRuntimeFilterSubFolder)\common</Filter>
+ </ClInclude>
<ClCompile Include="$(MonoSourceLocation)\mono\metadata\cominterop.c">
<Filter>Source Files$(MonoRuntimeFilterSubFolder)\common</Filter>
</ClCompile>