Author: spouliot
Date: 2005-03-10 08:25:35 -0500 (Thu, 10 Mar 2005)
New Revision: 41645
Modified:
trunk/mono/mono/metadata/ChangeLog
trunk/mono/mono/metadata/exception.c
trunk/mono/mono/metadata/exception.h
trunk/mono/mono/metadata/icall.c
trunk/mono/mono/metadata/security-manager.c
trunk/mono/mono/metadata/security-manager.h
Log:
2005-03-10 Sebastien Pouliot <[EMAIL PROTECTED]>
* 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.
Modified: trunk/mono/mono/metadata/ChangeLog
===================================================================
--- trunk/mono/mono/metadata/ChangeLog 2005-03-10 12:55:11 UTC (rev 41644)
+++ trunk/mono/mono/metadata/ChangeLog 2005-03-10 13:25:35 UTC (rev 41645)
@@ -1,3 +1,17 @@
+2005-03-10 Sebastien Pouliot <[EMAIL PROTECTED]>
+
+ * 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 <[EMAIL PROTECTED]>
* class.c (mono_bounded_array_class_get): Initialize `eclass' if
Modified: trunk/mono/mono/metadata/exception.c
===================================================================
--- trunk/mono/mono/metadata/exception.c 2005-03-10 12:55:11 UTC (rev
41644)
+++ trunk/mono/mono/metadata/exception.c 2005-03-10 13:25:35 UTC (rev
41645)
@@ -410,3 +410,27 @@
{
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;
+}
Modified: trunk/mono/mono/metadata/exception.h
===================================================================
--- trunk/mono/mono/metadata/exception.h 2005-03-10 12:55:11 UTC (rev
41644)
+++ trunk/mono/mono/metadata/exception.h 2005-03-10 13:25:35 UTC (rev
41645)
@@ -112,4 +112,7 @@
MonoException *
mono_get_exception_stack_overflow (void);
+MonoException *
+mono_get_exception_reflection_type_load (MonoArray *types, MonoArray
*exceptions);
+
#endif /* _MONO_METADATA_EXCEPTION_H_ */
Modified: trunk/mono/mono/metadata/icall.c
===================================================================
--- trunk/mono/mono/metadata/icall.c 2005-03-10 12:55:11 UTC (rev 41644)
+++ trunk/mono/mono/metadata/icall.c 2005-03-10 13:25:35 UTC (rev 41645)
@@ -3325,9 +3325,21 @@
/* 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 *
@@ -4179,7 +4191,46 @@
}
}
}
- }
+ }
+
+ 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;
}
@@ -6620,6 +6671,7 @@
};
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},
Modified: trunk/mono/mono/metadata/security-manager.c
===================================================================
--- trunk/mono/mono/metadata/security-manager.c 2005-03-10 12:55:11 UTC (rev
41644)
+++ trunk/mono/mono/metadata/security-manager.c 2005-03-10 13:25:35 UTC (rev
41645)
@@ -38,6 +38,10 @@
"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);
@@ -167,6 +171,8 @@
return TRUE;
}
+/* System.Security icalls */
+
MonoBoolean
ves_icall_System_Security_SecurityManager_get_SecurityEnabled (void)
{
@@ -200,3 +206,25 @@
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;
+}
Modified: trunk/mono/mono/metadata/security-manager.h
===================================================================
--- trunk/mono/mono/metadata/security-manager.h 2005-03-10 12:55:11 UTC (rev
41644)
+++ trunk/mono/mono/metadata/security-manager.h 2005-03-10 13:25:35 UTC (rev
41645)
@@ -19,6 +19,7 @@
#include "marshal.h"
#include "image.h"
#include "reflection.h"
+#include "tabledefs.h"
/* Definitions */
@@ -38,9 +39,6 @@
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 */
@@ -66,6 +64,7 @@
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_ */
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches