[corlib] Implement security properties on FieldInfo/MethodInfo.
authorAlex Rønne Petersen <alexrp@xamarin.com>
Tue, 17 Mar 2015 15:13:44 +0000 (16:13 +0100)
committerAlex Rønne Petersen <alexrp@xamarin.com>
Tue, 17 Mar 2015 15:32:04 +0000 (16:32 +0100)
mcs/class/corlib/System.Reflection/FieldInfo.cs
mcs/class/corlib/System.Reflection/MethodBase.cs
mcs/class/corlib/System.Reflection/MonoField.cs
mcs/class/corlib/System.Reflection/MonoMethod.cs
mono/metadata/icall-def.h
mono/metadata/icall.c

index 5838902b2ac15ed3d48fc4e5abd570d76bc494c3..9621fac3f77074a5a9a91136c50fc734de070df9 100644 (file)
@@ -277,19 +277,19 @@ namespace System.Reflection {
                
                public virtual bool IsSecurityCritical {
                        get {
-                               throw new NotImplementedException ();
+                               throw new NotSupportedException ();
                        }
                }
                
                public virtual bool IsSecuritySafeCritical {
                        get {
-                               throw new NotImplementedException ();
+                               throw new NotSupportedException ();
                        }
                }
 
                public virtual bool IsSecurityTransparent {
                        get {
-                               throw new NotImplementedException ();
+                               throw new NotSupportedException ();
                        }
                }
 
index ff04255d41671430ed36ec602c5a23bf6f77ad54..c496030d89f2a027fe6434d8f99bcffd33103881 100644 (file)
@@ -277,19 +277,19 @@ namespace System.Reflection {
                
                public virtual bool IsSecurityCritical {
                        get {
-                               throw new NotImplementedException ();
+                               throw new NotSupportedException ();
                        }
                }
                
                public virtual bool IsSecuritySafeCritical {
                        get {
-                               throw new NotImplementedException ();
+                               throw new NotSupportedException ();
                        }
                }
 
                public virtual bool IsSecurityTransparent {
                        get {
-                               throw new NotImplementedException ();
+                               throw new NotSupportedException ();
                        }
                }
 
index 0e6b40607d4c45b584585dbcb8a76abb18976414..1afdd03b0646c6412fcd8dca4589d7fd12bbd0ee 100644 (file)
@@ -234,5 +234,21 @@ namespace System.Reflection {
                        if (DeclaringType.ContainsGenericParameters)
                                throw new InvalidOperationException ("Late bound operations cannot be performed on fields with types for which Type.ContainsGenericParameters is true.");
            }
+
+               //seclevel { transparent = 0, safe-critical = 1, critical = 2}
+               [MethodImplAttribute(MethodImplOptions.InternalCall)]
+               public extern int get_core_clr_security_level ();
+
+               public override bool IsSecurityTransparent {
+                       get { return get_core_clr_security_level () == 0; }
+               }
+
+               public override bool IsSecurityCritical {
+                       get { return get_core_clr_security_level () > 0; }
+               }
+
+               public override bool IsSecuritySafeCritical {
+                       get { return get_core_clr_security_level () == 1; }
+               }
        }
 }
index b8b19d873b8b3a56fccb829d586b57790e572a69..af76c6a8018cfa8f26ec0319fc41f9598f25b218 100644 (file)
@@ -481,6 +481,22 @@ namespace System.Reflection {
                public override IList<CustomAttributeData> GetCustomAttributesData () {
                        return CustomAttributeData.GetCustomAttributes (this);
                }
+
+               //seclevel { transparent = 0, safe-critical = 1, critical = 2}
+               [MethodImplAttribute(MethodImplOptions.InternalCall)]
+               public extern int get_core_clr_security_level ();
+
+               public override bool IsSecurityTransparent {
+                       get { return get_core_clr_security_level () == 0; }
+               }
+
+               public override bool IsSecurityCritical {
+                       get { return get_core_clr_security_level () > 0; }
+               }
+
+               public override bool IsSecuritySafeCritical {
+                       get { return get_core_clr_security_level () == 1; }
+               }
        }
        
 
index 3fb258a63e8b9441c2e2d73143ac98a3c383427e..9532f2d559191c98f9cdc85c5b042e5331ccfeb2 100644 (file)
@@ -588,6 +588,7 @@ ICALL(MFIELD_5, "GetRawConstantValue", ves_icall_MonoField_GetRawConstantValue)
 ICALL(MFIELD_3, "GetValueInternal", ves_icall_MonoField_GetValueInternal)
 ICALL(MFIELD_6, "ResolveType", ves_icall_MonoField_ResolveType)
 ICALL(MFIELD_4, "SetValueInternal", ves_icall_MonoField_SetValueInternal)
+ICALL(MFIELD_7, "get_core_clr_security_level", ves_icall_MonoField_get_core_clr_security_level)
 
 ICALL_TYPE(MGENCM, "System.Reflection.MonoGenericCMethod", MGENCM_1)
 ICALL(MGENCM_1, "get_ReflectedType", ves_icall_MonoGenericMethod_get_ReflectedType)
@@ -609,6 +610,7 @@ ICALL(MMETH_5, "MakeGenericMethod_impl", mono_reflection_bind_generic_method_par
 ICALL(MMETH_6, "get_IsGenericMethod", ves_icall_MonoMethod_get_IsGenericMethod)
 ICALL(MMETH_7, "get_IsGenericMethodDefinition", ves_icall_MonoMethod_get_IsGenericMethodDefinition)
 ICALL(MMETH_8, "get_base_method", ves_icall_MonoMethod_get_base_method)
+ICALL(MMETH_10, "get_core_clr_security_level", ves_icall_MonoMethod_get_core_clr_security_level)
 ICALL(MMETH_9, "get_name", ves_icall_MonoMethod_get_name)
 
 ICALL_TYPE(MMETHI, "System.Reflection.MonoMethodInfo", MMETHI_4)
index 2e138108dd850cd07a2b77ac7937dc327cdcf908..73cdd8027f20c80b0cdcc46ffbfe7c35d57bf2a3 100644 (file)
@@ -4658,6 +4658,20 @@ vell_icall_MonoType_get_core_clr_security_level (MonoReflectionType *this)
        return mono_security_core_clr_class_level (klass);
 }
 
+ICALL_EXPORT int
+ves_icall_MonoField_get_core_clr_security_level (MonoReflectionField *this)
+{
+       MonoClassField *field = this->field;
+       return mono_security_core_clr_field_level (field, TRUE);
+}
+
+ICALL_EXPORT int
+ves_icall_MonoMethod_get_core_clr_security_level (MonoReflectionMethod *this)
+{
+       MonoMethod *method = this->method;
+       return mono_security_core_clr_method_level (method, TRUE);
+}
+
 static void
 fill_reflection_assembly_name (MonoDomain *domain, MonoReflectionAssemblyName *aname, MonoAssemblyName *name, const char *absolute, gboolean by_default_version, gboolean default_publickey, gboolean default_token)
 {