#define mono_type_array_get_and_resolve(array, index) mono_reflection_type_get_handle ((MonoReflectionType*)mono_array_get (array, gpointer, index))
+#define CHECK_ADD4_OVERFLOW_UN(a, b) ((guint32)(0xFFFFFFFFU) - (guint32)(b) < (guint32)(a))
+#define CHECK_ADD8_OVERFLOW_UN(a, b) ((guint64)(0xFFFFFFFFFFFFFFFFUL) - (guint64)(b) < (guint64)(a))
+
+#if SIZEOF_VOID_P == 4
+#define CHECK_ADDP_OVERFLOW_UN(a,b) CHECK_ADD4_OVERFLOW_UN(a, b)
+#else
+#define CHECK_ADDP_OVERFLOW_UN(a,b) CHECK_ADD8_OVERFLOW_UN(a, b)
+#endif
+
+#define ADDP_IS_GREATER_OR_OVF(a, b, c) (((a) + (b) > (c)) || CHECK_ADDP_OVERFLOW_UN (a, b))
+#define ADD_IS_GREATER_OR_OVF(a, b, c) (((a) + (b) > (c)) || CHECK_ADD4_OVERFLOW_UN (a, b))
+
+
void
mono_reflection_init (void)
{
char *p, *box_val;
char* buf;
guint32 idx = 0, len = 0, dummy = 0;
-#ifdef ARM_FPU_FPA
-#if G_BYTE_ORDER == G_LITTLE_ENDIAN
- guint32 fpa_double [2];
- guint32 *fpa_p;
-#endif
-#endif
-
+
p = buf = g_malloc (64);
if (!val) {
*ret_type = MONO_TYPE_CLASS;
break;
case MONO_TYPE_R8:
len = 8;
-#ifdef ARM_FPU_FPA
-#if G_BYTE_ORDER == G_LITTLE_ENDIAN
- fpa_p = (guint32*)box_val;
- fpa_double [0] = fpa_p [1];
- fpa_double [1] = fpa_p [0];
- box_val = (char*)fpa_double;
-#endif
-#endif
break;
case MONO_TYPE_VALUETYPE: {
MonoClass *klass = val->vtable->klass;
if (field->parent->generic_class && field->parent->generic_class->container_class && field->parent->generic_class->container_class->fields) {
int index = field - field->parent->fields;
- type = field->parent->generic_class->container_class->fields [index].type;
+ type = mono_field_get_type (&field->parent->generic_class->container_class->fields [index]);
} else {
if (is_field_on_inst (field))
type = get_field_on_inst_generic_type (field);
MonoMethodSignature *sig;
klass = obj->vtable->klass;
- if (strcmp (klass->name, "MonoMethod") == 0) {
+ if (strcmp (klass->name, "MonoMethod") == 0 || strcmp (klass->name, "MonoCMethod") == 0) {
MonoMethod *method = ((MonoReflectionMethod *)obj)->method;
MonoMethodSignature *old;
guint32 sig_token, parent;
}
mono_domain_assemblies_lock (domain);
- domain->domain_assemblies = g_slist_prepend (domain->domain_assemblies, assembly);
+ domain->domain_assemblies = g_slist_append (domain->domain_assemblies, assembly);
mono_domain_assemblies_unlock (domain);
register_assembly (mono_object_domain (assemblyb), &assemblyb->assembly, &assembly->assembly);
if (!System_Reflection_ParameterInfo_array) {
MonoClass *klass;
- klass = mono_class_from_name (mono_defaults.corlib, "System.Reflection", "ParameterInfo");
+ klass = mono_class_from_name (mono_defaults.corlib, "System.Reflection", "MonoParameterInfo");
+ if (!klass)
+ klass = mono_class_from_name (mono_defaults.corlib, "System.Reflection", "ParameterInfo");
+
mono_memory_barrier ();
System_Reflection_ParameterInfo = klass;
+
klass = mono_array_class_get (klass, 1);
mono_memory_barrier ();
MonoReflectionMonoEvent *p = (MonoReflectionMonoEvent*)obj;
token = mono_class_get_event_token (p->event);
- } else if (strcmp (klass->name, "ParameterInfo") == 0) {
+ } else if (strcmp (klass->name, "ParameterInfo") == 0 || strcmp (klass->name, "MonoParameterInfo") == 0) {
MonoReflectionParameter *p = (MonoReflectionParameter*)obj;
MonoClass *member_class = mono_object_class (p->MemberImpl);
g_assert (mono_class_is_reflection_method_or_constructor (member_class));
return token;
}
+static MonoClass*
+load_cattr_enum_type (MonoImage *image, const char *p, const char **end)
+{
+ char *n;
+ MonoType *t;
+ int slen = mono_metadata_decode_value (p, &p);
+ n = g_memdup (p, slen + 1);
+ n [slen] = 0;
+ t = mono_reflection_type_from_name (n, image);
+ if (!t)
+ g_error ("Cannot load type '%s'", n);
+ g_free (n);
+ p += slen;
+ *end = p;
+ return mono_class_from_mono_type (t);
+}
+
static void*
load_cattr_value (MonoImage *image, MonoType *t, const char *p, const char **end)
{
type = MONO_TYPE_SZARRAY;
if (etype == 0x50) {
tklass = mono_defaults.systemtype_class;
+ } else if (etype == 0x55) {
+ tklass = load_cattr_enum_type (image, p, &p);
} else {
if (etype == 0x51)
/* See Partition II, Appendix B3 */
* NAMED_ARG_INFO will contain information about the named arguments.
*/
void
-mono_reflection_create_custom_attr_data_args (MonoImage *image, MonoMethod *method, const guchar *data, guint32 len, MonoArray **typed_args, MonoArray **named_args, CattrNamedArg **named_arg_info)
+mono_reflection_create_custom_attr_data_args (MonoImage *image, MonoMethod *method, const guchar *data, guint32 len, MonoArray **typed_args, MonoArray **named_args, CattrNamedArg **named_arg_info, MonoError *error)
{
MonoArray *typedargs, *namedargs;
MonoClass *attrklass;
guint32 i, j, num_named;
CattrNamedArg *arginfo = NULL;
- if (!mono_verifier_verify_cattr_content (image, method, data, len, NULL))
- return;
-
- mono_class_init (method->klass);
-
*typed_args = NULL;
*named_args = NULL;
*named_arg_info = NULL;
+
+ mono_error_init (error);
+
+ if (!mono_verifier_verify_cattr_content (image, method, data, len, NULL)) {
+ mono_error_set_generic_error (error, "System.Reflection", "CustomAttributeFormatException", "Binary format of the specified custom attribute was invalid.");
+ return;
+ }
+
+ mono_class_init (method->klass);
domain = mono_domain_get ();
gint type_len;
char *type_name;
type_len = mono_metadata_decode_blob_size (named, &named);
+ if (ADDP_IS_GREATER_OR_OVF ((const guchar*)named, type_len, data + len))
+ goto fail;
+
type_name = g_malloc (type_len + 1);
memcpy (type_name, named, type_len);
type_name [type_len] = 0;
g_free (type_name);
}
name_len = mono_metadata_decode_blob_size (named, &named);
+ if (ADDP_IS_GREATER_OR_OVF ((const guchar*)named, name_len, data + len))
+ goto fail;
name = g_malloc (name_len + 1);
memcpy (name, named, name_len);
name [name_len] = 0;
*typed_args = typedargs;
*named_args = namedargs;
+ return;
+fail:
+ mono_error_set_generic_error (error, "System.Reflection", "CustomAttributeFormatException", "Binary format of the specified custom attribute was invalid.");
+ g_free (arginfo);
+ *named_arg_info = NULL;
}
void
MonoArray *typedargs, *namedargs;
MonoImage *image;
MonoMethod *method;
- CattrNamedArg *arginfo;
+ CattrNamedArg *arginfo = NULL;
+ MonoError error;
int i;
*ctor_args = NULL;
if (!mono_class_init (method->klass))
mono_raise_exception (mono_class_get_exception_for_failure (method->klass));
- mono_reflection_create_custom_attr_data_args (image, method, data, len, &typedargs, &namedargs, &arginfo);
+ mono_reflection_create_custom_attr_data_args (image, method, data, len, &typedargs, &namedargs, &arginfo, &error);
+ if (!mono_error_ok (&error))
+ mono_error_raise_exception (&error);
if (mono_loader_get_last_error ())
mono_raise_exception (mono_loader_error_prepare_exception (mono_loader_get_last_error ()));
- if (!typedargs || !namedargs)
+ if (!typedargs || !namedargs) {
+ g_free (arginfo);
return;
+ }
for (i = 0; i < mono_method_signature (method)->param_count; ++i) {
MonoObject *obj = mono_array_get (typedargs, MonoObject*, i);
*ctor_args = typedargs;
*named_args = namedargs;
+ g_free (arginfo);
}
static MonoObject*
return mono_custom_attrs_from_index (klass->image, idx);
}
+/**
+ * mono_custom_attrs_from_param:
+ * @method: handle to the method that we want to retrieve custom parameter information from
+ * @param: parameter number, where zero represent the return value, and one is the first parameter in the method
+ *
+ * The result must be released with mono_custom_attrs_free().
+ *
+ * Returns: the custom attribute object for the specified parameter, or NULL if there are none.
+ */
MonoCustomAttrInfo*
mono_custom_attrs_from_param (MonoMethod *method, guint32 param)
{
} else if ((strcmp ("MonoGenericMethod", klass->name) == 0) || (strcmp ("MonoGenericCMethod", klass->name) == 0)) {
MonoReflectionMethod *rmethod = (MonoReflectionMethod*)obj;
cinfo = mono_custom_attrs_from_method (rmethod->method);
- } else if (strcmp ("ParameterInfo", klass->name) == 0) {
+ } else if (strcmp ("ParameterInfo", klass->name) == 0 || strcmp ("MonoParameterInfo", klass->name) == 0) {
MonoReflectionParameter *param = (MonoReflectionParameter*)obj;
MonoClass *member_class = mono_object_class (param->MemberImpl);
if (mono_class_is_reflection_method_or_constructor (member_class)) {
p += 4;
break;
case MONO_TYPE_R8:
-#if defined(ARM_FPU_FPA) && G_BYTE_ORDER == G_LITTLE_ENDIAN
- p [0] = argval [4];
- p [1] = argval [5];
- p [2] = argval [6];
- p [3] = argval [7];
- p [4] = argval [0];
- p [5] = argval [1];
- p [6] = argval [2];
- p [7] = argval [3];
-#else
swap_with_size (p, argval, 8, 1);
-#endif
p += 8;
break;
case MONO_TYPE_U8:
ref = resolve_object (mb->module->image, obj, &handle_class, NULL);
if (!ref)
ex = mono_get_exception_type_load (NULL, NULL);
- else if (mono_security_get_mode () == MONO_SECURITY_MODE_CORE_CLR)
+ else if (mono_security_core_clr_enabled ())
ex = mono_security_core_clr_ensure_dynamic_method_resolved_object (ref, handle_class);
if (ex) {