Exemple #1
0
        /// <summary>
        /// Managed implementation of CEEInfo::getClassAlignmentRequirementStatic
        /// </summary>
        private static int GetClassAlignmentRequirement(MetadataType type)
        {
            int alignment = type.Context.Target.PointerSize;

            if (type.HasLayout())
            {
                if (type.IsSequentialLayout || MarshalUtils.IsBlittableType(type))
                {
                    alignment = type.InstanceFieldAlignment.AsInt;
                }
            }

            if (type.Context.Target.Architecture == TargetArchitecture.ARM &&
                alignment < 8 && type.RequiresAlign8())
            {
                // If the structure contains 64-bit primitive fields and the platform requires 8-byte alignment for
                // such fields then make sure we return at least 8-byte alignment. Note that it's technically possible
                // to create unmanaged APIs that take unaligned structures containing such fields and this
                // unconditional alignment bump would cause us to get the calling convention wrong on platforms such
                // as ARM. If we see such cases in the future we'd need to add another control (such as an alignment
                // property for the StructLayout attribute or a marshaling directive attribute for p/invoke arguments)
                // that allows more precise control. For now we'll go with the likely scenario.
                alignment = 8;
            }

            return(alignment);
        }
        public void IsBlittableType_TypeWithEmptyBase_ReturnsFalse(string className)
        {
            TypeDesc classWithEmptyBase = _testModule.GetType("Marshalling", className);

            Assert.False(MarshalUtils.IsBlittableType(classWithEmptyBase));
        }
 public void IsBlittableType_NonBilittableWellKnownTypes_ReturnsFalse(WellKnownType type) =>
 Assert.False(MarshalUtils.IsBlittableType(_context.GetWellKnownType(type)));