public override bool IsBlocked(MethodDesc method)
        {
            Debug.Assert(method.IsTypicalMethodDefinition);

            var ecmaMethod = method as EcmaMethod;

            if (ecmaMethod == null)
            {
                return(true);
            }

            if (_blockedTypes.GetOrCreateValue((EcmaType)ecmaMethod.OwningType).IsBlocked)
            {
                return(true);
            }

            if (_blockedModules.GetOrCreateValue(ecmaMethod.Module).HasBlockedInternals)
            {
                if ((ecmaMethod.Attributes & MethodAttributes.Public) != MethodAttributes.Public)
                {
                    return(true);
                }
            }

            return(false);
        }
Exemple #2
0
        public override bool IsBlocked(MethodDesc method)
        {
            Debug.Assert(method.IsTypicalMethodDefinition);

            var ecmaMethod = method as EcmaMethod;

            if (ecmaMethod == null)
            {
                return(true);
            }

            ModuleBlockingMode moduleBlockingMode = _blockedModules.GetOrCreateValue(ecmaMethod.Module).BlockingMode;

            if (moduleBlockingMode == ModuleBlockingMode.None)
            {
                return(false);
            }
            else if (moduleBlockingMode == ModuleBlockingMode.FullyBlocked)
            {
                return(true);
            }

            // We are blocking internal implementation details
            Debug.Assert(moduleBlockingMode == ModuleBlockingMode.BlockedInternals);

            var owningType = (EcmaType)ecmaMethod.OwningType;

            if (_blockedTypes.GetOrCreateValue(owningType).IsBlocked)
            {
                return(true);
            }

            MethodAttributes accessibility = ecmaMethod.Attributes & MethodAttributes.Public;

            if (accessibility != MethodAttributes.Family &&
                accessibility != MethodAttributes.FamORAssem &&
                accessibility != MethodAttributes.Public)
            {
                return(true);
            }

            // Methods on Array`1<T> are implementation details that implement the generic interfaces on
            // arrays. They should not generate metadata or be reflection invokable.
            // We could get rid of this special casing two ways:
            // * Make these method stop being regular EcmaMethods with Array<T> as their owning type, or
            // * Make these methods implement the interfaces explicitly (they would become private and naturally blocked)
            if (ecmaMethod.OwningType == ArrayOfTType)
            {
                return(true);
            }

            return(false);
        }
Exemple #3
0
            protected override BlockingState CreateValueFromKey(EcmaType type)
            {
                ModuleBlockingMode moduleBlockingMode = _blockedModules.GetOrCreateValue(type.EcmaModule).BlockingMode;
                bool isBlocked = ComputeIsBlocked(type, moduleBlockingMode);

                return(new BlockingState(type, isBlocked));
            }
            protected override BlockingState CreateValueFromKey(EcmaType type)
            {
                bool isBlocked = false;

                if (_blockedModules.GetOrCreateValue(type.EcmaModule).HasBlockedInternals)
                {
                    isBlocked = ComputeIsBlocked(type);
                }

                return(new BlockingState(type, isBlocked));
            }
Exemple #5
0
        public override bool IsBlocked(MethodDesc method)
        {
            Debug.Assert(method.IsTypicalMethodDefinition);

            var ecmaMethod = method as EcmaMethod;

            if (ecmaMethod == null)
            {
                return(true);
            }

            ModuleBlockingMode moduleBlockingMode = _blockedModules.GetOrCreateValue(ecmaMethod.Module).BlockingMode;

            if (moduleBlockingMode == ModuleBlockingMode.None)
            {
                return(false);
            }
            else if (moduleBlockingMode == ModuleBlockingMode.FullyBlocked)
            {
                return(true);
            }

            // We are blocking internal implementation details
            Debug.Assert(moduleBlockingMode == ModuleBlockingMode.BlockedInternals);

            var owningType = (EcmaType)ecmaMethod.OwningType;

            if (_blockedTypes.GetOrCreateValue(owningType).IsBlocked)
            {
                return(true);
            }

            MethodAttributes accessibility = ecmaMethod.Attributes & MethodAttributes.Public;

            if (accessibility != MethodAttributes.Family &&
                accessibility != MethodAttributes.FamORAssem &&
                accessibility != MethodAttributes.Public)
            {
                // Non-public and non-protected methods should be blocked, but binary serialization
                // forces us to exclude a couple things if the type is serializable.
                if (owningType.IsSerializable)
                {
                    MethodSignature signature = ecmaMethod.Signature;

                    if (ecmaMethod.IsConstructor &&
                        signature.Length == 2 &&
                        signature[0] == SerializationInfoType
                        /* && ecmaMethod.Signature[1] is StreamingContext */)
                    {
                        return(false);
                    }

                    // Methods with these attributes can be called during serialization
                    if (signature.Length == 1 && !signature.IsStatic && signature.ReturnType.IsVoid &&
                        (ecmaMethod.HasCustomAttribute("System.Runtime.Serialization", "OnSerializingAttribute") ||
                         ecmaMethod.HasCustomAttribute("System.Runtime.Serialization", "OnSerializedAttribute") ||
                         ecmaMethod.HasCustomAttribute("System.Runtime.Serialization", "OnDeserializingAttribute") ||
                         ecmaMethod.HasCustomAttribute("System.Runtime.Serialization", "OnDeserializedAttribute")))
                    {
                        return(false);
                    }
                }

                return(true);
            }

            // Methods on Array`1<T> are implementation details that implement the generic interfaces on
            // arrays. They should not generate metadata or be reflection invokable.
            // We could get rid of this special casing two ways:
            // * Make these method stop being regular EcmaMethods with Array<T> as their owning type, or
            // * Make these methods implement the interfaces explicitly (they would become private and naturally blocked)
            if (ecmaMethod.OwningType == ArrayOfTType)
            {
                return(true);
            }

            return(false);
        }