+2005-03-10 Sebastien Pouliot <sebastien@ximian.com>
+
+ * exception.c|h: Added mono_get_exception_reflection_type_load to
+ create a ReflectionTypeLoadException object.
+ * icall.c: Updated ves_icall_System_Reflection_Assembly_InternalGetType
+ to return NULL is a InheritanceDemand fails during reflection. Updated
+ ves_icall_System_Reflection_Assembly_GetTypes to throw a
+ ReflectionTypeLoadException if an InheritanceDemand fails during
+ reflection. Added icall mapping for GetLinkDemandSecurity.
+ * security-manager.c|h: Added ves_icall_System_Security_
+ SecurityManager_GetLinkDemandSecurity internal call to return the
+ class and methods permissions set for a LinkDemand. Removed unused
+ fields in MonoSecurityManager.
+
2005-03-10 Martin Baulig <martin@ximian.com>
* class.c (mono_bounded_array_class_get): Initialize `eclass' if
{
return mono_exception_from_name (mono_get_corlib (), "System", "StackOverflowException");
}
+
+MonoException *
+mono_get_exception_reflection_type_load (MonoArray *types, MonoArray *exceptions)
+{
+ MonoClass *klass;
+ gpointer args [2];
+ MonoObject *exc;
+ MonoMethod *method;
+
+ klass = mono_class_from_name (mono_get_corlib (), "System.Reflection", "ReflectionTypeLoadException");
+ g_assert (klass);
+ mono_class_init (klass);
+
+ method = mono_class_get_method_from_name (klass, ".ctor", 2);
+ g_assert (method);
+
+ args [0] = types;
+ args [1] = exceptions;
+
+ exc = mono_object_new (mono_domain_get (), klass);
+ mono_runtime_invoke (method, exc, args, NULL);
+
+ return (MonoException *) exc;
+}
MonoException *
mono_get_exception_stack_overflow (void);
+MonoException *
+mono_get_exception_reflection_type_load (MonoArray *types, MonoArray *exceptions);
+
#endif /* _MONO_METADATA_EXCEPTION_H_ */
/* g_print ("failed find\n"); */
return NULL;
}
+
+ if (type->type == MONO_TYPE_CLASS) {
+ MonoClass *klass = mono_type_get_class (type);
+ /* need to report exceptions ? */
+ if (throwOnError && klass->exception_type) {
+ /* report SecurityException (or others) that occured when loading the assembly */
+ MonoException *exc = mono_class_get_exception_for_failure (klass);
+ mono_raise_exception (exc);
+ } else if (klass->exception_type == MONO_EXCEPTION_SECURITY_INHERITANCEDEMAND) {
+ return NULL;
+ }
+ }
+
/* g_print ("got it\n"); */
return mono_type_get_object (mono_object_domain (assembly), type);
-
}
static MonoString *
}
}
}
- }
+ }
+
+ if (mono_is_security_manager_active ()) {
+ /* the ReflectionTypeLoadException must have all the types (Types property),
+ * NULL replacing types which throws an exception. The LoaderException must
+ * contains all exceptions for NULL items.
+ */
+
+ guint32 len = mono_array_length (res);
+ GList *list = NULL;
+
+ for (i = 0; i < len; i++) {
+ MonoReflectionType *t = mono_array_get (res, gpointer, i);
+ MonoClass *klass = mono_type_get_class (t->type);
+ if ((klass != NULL) && klass->exception_type) {
+ /* keep the class in the list */
+ list = g_list_append (list, klass);
+ /* and replace Type with NULL */
+ mono_array_set (res, gpointer, i, NULL);
+ }
+ }
+
+ if (list) {
+ GList *tmp = NULL;
+ MonoException *exc = NULL;
+ int length = g_list_length (list);
+
+ MonoArray *exl = mono_array_new (domain, mono_defaults.exception_class, length);
+ for (i = 0, tmp = list; i < length; i++, tmp = tmp->next) {
+ MonoException *exc = mono_class_get_exception_for_failure (tmp->data);
+ mono_array_set (exl, gpointer, i, exc);
+ }
+ g_list_free (list);
+ list = NULL;
+
+ exc = mono_get_exception_reflection_type_load (res, exl);
+ mono_raise_exception (exc);
+ }
+ }
+
return res;
}
};
static const IcallEntry securitymanager_icalls [] = {
+ {"GetLinkDemandSecurity", ves_icall_System_Security_SecurityManager_GetLinkDemandSecurity},
{"get_CheckExecutionRights", ves_icall_System_Security_SecurityManager_get_CheckExecutionRights},
{"get_SecurityEnabled", ves_icall_System_Security_SecurityManager_get_SecurityEnabled},
{"set_CheckExecutionRights", ves_icall_System_Security_SecurityManager_set_CheckExecutionRights},
"InternalDemand", 2);
g_assert (secman.demand);
+ secman.demandchoice = mono_class_get_method_from_name (secman.securitymanager,
+ "InternalDemandChoice", 2);
+ g_assert (secman.demandchoice);
+
secman.inheritancedemand = mono_class_get_method_from_name (secman.securitymanager,
"InheritanceDemand", 2);
g_assert (secman.inheritancedemand);
return TRUE;
}
+/* System.Security icalls */
+
MonoBoolean
ves_icall_System_Security_SecurityManager_get_SecurityEnabled (void)
{
mono_security_manager_execution = value;
}
}
+
+MonoBoolean
+ves_icall_System_Security_SecurityManager_GetLinkDemandSecurity (MonoReflectionMethod *m, MonoDeclSecurityActions *kactions, MonoDeclSecurityActions *mactions)
+{
+ MonoMethod *method = m->method;
+ /* we want the original as the wrapper is "free" of the security informations */
+ if (method->wrapper_type == MONO_WRAPPER_MANAGED_TO_NATIVE) {
+ method = mono_marshal_method_from_wrapper (method);
+ }
+
+ mono_class_init (method->klass);
+
+ /* if either the method or it's class has security (any type) */
+ if ((method->flags & METHOD_ATTRIBUTE_HAS_SECURITY) || (method->klass->flags & TYPE_ATTRIBUTE_HAS_SECURITY)) {
+ memset (kactions, 0, sizeof (MonoDeclSecurityActions));
+ memset (mactions, 0, sizeof (MonoDeclSecurityActions));
+
+ /* get any linkdemand (either on the method or it's class) */
+ return mono_declsec_get_linkdemands (method, kactions, mactions);
+ }
+ return FALSE;
+}
#include "marshal.h"
#include "image.h"
#include "reflection.h"
+#include "tabledefs.h"
/* Definitions */
MonoClass *securitymanager; /* System.Security.SecurityManager */
MonoMethod *demand; /* SecurityManager.InternalDemand */
MonoMethod *demandchoice; /* SecurityManager.InternalDemandChoice */
- MonoMethod *assert; /* SecurityManager.InternalAssert */
- MonoMethod *deny; /* SecurityManager.InternalDeny */
- MonoMethod *permitonly; /* SecurityManager.InternalPermitOnly */
MonoMethod *inheritancedemand; /* SecurityManager.InheritanceDemand */
MonoMethod *inheritsecurityexception; /* SecurityManager.InheritanceDemandSecurityException */
MonoMethod *linkdemand; /* SecurityManager.LinkDemand */
void ves_icall_System_Security_SecurityManager_set_SecurityEnabled (MonoBoolean value);
MonoBoolean ves_icall_System_Security_SecurityManager_get_CheckExecutionRights (void);
void ves_icall_System_Security_SecurityManager_set_CheckExecutionRights (MonoBoolean value);
+MonoBoolean ves_icall_System_Security_SecurityManager_GetLinkDemandSecurity (MonoReflectionMethod *m, MonoDeclSecurityActions *kactions, MonoDeclSecurityActions *mactions);
#endif /* _MONO_METADATA_SECURITY_MANAGER_H_ */