* icall.c (ves_icall_MonoMethod_get_base_definition): Simplify
[mono.git] / mono / metadata / security-manager.c
index 923102f8e19e04feb5afbd0f8d5e1ee0fffc396b..a2382ac49dfe76ad84a9cf20400472ec88292dfe 100644 (file)
@@ -47,7 +47,7 @@ mono_security_manager_get_methods (void)
        g_assert (secman.demandunmanaged);
 
        secman.inheritancedemand = mono_class_get_method_from_name (secman.securitymanager,
-               "InheritanceDemand", 2);        
+               "InheritanceDemand", 3);        
        g_assert (secman.inheritancedemand);
 
        secman.inheritsecurityexception = mono_class_get_method_from_name (secman.securitymanager,
@@ -89,10 +89,11 @@ mono_secman_inheritance_check (MonoClass *klass, MonoDeclSecurityActions *demand
        MonoAssembly *assembly = mono_image_get_assembly (klass->image);
        MonoReflectionAssembly *refass = mono_assembly_get_object (domain, assembly);
        MonoObject *res;
-       gpointer args [2];
+       gpointer args [3];
 
-       args [0] = refass;
-       args [1] = demands;
+       args [0] = domain->domain;
+       args [1] = refass;
+       args [2] = demands;
 
        res = mono_runtime_invoke (secman->inheritancedemand, NULL, args, NULL);
        return (*(MonoBoolean *) mono_object_unbox (res));
@@ -107,6 +108,11 @@ mono_secman_inheritancedemand_class (MonoClass *klass, MonoClass *parent)
        if (klass->exception_type != 0)
                return;
 
+       /* short-circuit corlib as it is fully trusted (within itself)
+        * and because this cause major recursion headaches */
+       if ((klass->image == mono_defaults.corlib) && (parent->image == mono_defaults.corlib))
+               return;
+
        /* Check if there are an InheritanceDemand on the parent class */
        if (mono_declsec_get_inheritdemands_class (parent, &demands)) {
                /* If so check the demands on the klass (inheritor) */
@@ -127,6 +133,11 @@ mono_secman_inheritancedemand_method (MonoMethod *override, MonoMethod *base)
        if (override->klass->exception_type != 0)
                return;
 
+       /* short-circuit corlib as it is fully trusted (within itself)
+        * and because this cause major recursion headaches */
+       if ((override->klass->image == mono_defaults.corlib) && (base->klass->image == mono_defaults.corlib))
+               return;
+
        /* Check if there are an InheritanceDemand on the base (virtual) method */
        if (mono_declsec_get_inheritdemands_method (base, &demands)) {
                /* If so check the demands on the overriding method */
@@ -179,6 +190,34 @@ mono_is_ecma_key (const char *publickey, int size)
        return TRUE;
 }
 
+/*
+ * Context propagation is required when:
+ * (a) the security manager is active (1.x and later)
+ * (b) other contexts needs to be propagated (2.x and later)
+ *
+ * returns NULL if no context propagation is required, else the returns the
+ * MonoMethod to call to Capture the ExecutionContext.
+ */
+MonoMethod*
+mono_get_context_capture_method (void)
+{
+       static MonoMethod *method = NULL;
+
+       if (!mono_security_manager_activated) {
+               if (mono_image_get_assembly (mono_defaults.corlib)->aname.major < 2)
+                       return NULL;
+       }
+
+       /* older corlib revisions won't have the class (nor the method) */
+       if (mono_defaults.executioncontext_class && !method) {
+               mono_class_init (mono_defaults.executioncontext_class);
+               method = mono_class_get_method_from_name (mono_defaults.executioncontext_class, "Capture", 0);
+       }
+
+       return method;
+}
+
+
 /* System.Security icalls */
 
 MonoBoolean