Imported Upstream version 6.0.0.172

Former-commit-id: f3cc9b82f3e5bd8f0fd3ebc098f789556b44e9cd
This commit is contained in:
Xamarin Public Jenkins (auto-signing)
2019-04-12 14:10:50 +00:00
parent 8016999e4d
commit 64ac736ec5
32155 changed files with 3981439 additions and 75368 deletions

View File

@@ -0,0 +1,22 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System.Reflection;
namespace System.Security.Cryptography
{
internal static class CryptoConfigForwarder
{
internal static object CreateFromName (string name) => CryptoConfig.CreateFromName (name);
internal static HashAlgorithm CreateDefaultHashAlgorithm ()
{
#if FULL_AOT_RUNTIME
return new System.Security.Cryptography.SHA1CryptoServiceProvider ();
#else
return (HashAlgorithm)CreateFromName ("System.Security.Cryptography.HashAlgorithm");
#endif
}
}
}

View File

@@ -0,0 +1,52 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
/*============================================================
**
**
**
** Purpose:
** This class represents the current system timezone. It is
** the only meaningful implementation of the TimeZone class
** available in this version.
**
** The only TimeZone that we support in version 1 is the
** CurrentTimeZone as determined by the system timezone.
**
**
============================================================*/
using System.Collections;
using System.Globalization;
using System.Runtime.Serialization;
namespace System
{
partial class CurrentSystemTimeZone
{
// copied from CoreRT
private DaylightTime GetCachedDaylightChanges(int year)
{
object objYear = (object)year;
if (!m_CachedDaylightChanges.Contains(objYear))
{
DaylightTime currentDaylightChanges = CreateDaylightChanges(year);
lock (m_CachedDaylightChanges)
{
if (!m_CachedDaylightChanges.Contains(objYear))
{
m_CachedDaylightChanges.Add(objYear, currentDaylightChanges);
}
}
}
return (DaylightTime)m_CachedDaylightChanges[objYear];
}
// The per-year information is cached in in this instance value. As a result it can
// be cleaned up by CultureInfo.ClearCachedData, which will clear the instance of this object
private readonly Hashtable m_CachedDaylightChanges = new Hashtable();
} // class CurrentSystemTimeZone
}

View File

@@ -0,0 +1,28 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.Runtime;
using System.Runtime.InteropServices;
using System.Runtime.CompilerServices;
namespace System
{
partial struct DateTime
{
public static DateTime UtcNow
{
get
{
long ticks = GetSystemTimeAsFileTime();
return new DateTime(((UInt64)(ticks + FileTimeOffset)) | KindUtc);
}
}
[MethodImplAttribute(MethodImplOptions.InternalCall)]
internal static extern long GetSystemTimeAsFileTime();
internal Int64 ToBinaryRaw() => (Int64)_dateData;
}
}

View File

@@ -0,0 +1,181 @@
using System.Reflection;
namespace System {
partial class DefaultBinder {
internal static bool CompareMethodSig (MethodBase m1, MethodBase m2)
{
ParameterInfo[] params1 = m1.GetParametersNoCopy ();
ParameterInfo[] params2 = m2.GetParametersNoCopy ();
if (params1.Length != params2.Length)
return false;
int numParams = params1.Length;
for (int i = 0; i < numParams; i++) {
if (params1 [i].ParameterType != params2 [i].ParameterType)
return false;
}
return true;
}
// Given a set of methods that match the base criteria, select a method based
// upon an array of types. This method should return null if no method matchs
// the criteria.
public sealed override MethodBase SelectMethod (BindingFlags bindingAttr, MethodBase[] match, Type[] types, ParameterModifier[] modifiers)
{
int i;
int j;
Type[] realTypes = new Type [types.Length];
for (i = 0; i < types.Length; i++)
{
realTypes[i] = types[i].UnderlyingSystemType;
if (!(realTypes[i].IsRuntimeImplemented() || realTypes[i] is SignatureType))
throw new ArgumentException(SR.Arg_MustBeType, nameof(types));
}
types = realTypes;
// We don't automatically jump out on exact match.
if (match == null || match.Length == 0)
throw new ArgumentException(SR.Arg_EmptyArray, nameof(match));
MethodBase[] candidates = (MethodBase[])match.Clone();
// Find all the methods that can be described by the types parameter.
// Remove all of them that cannot.
int CurIdx = 0;
for (i = 0; i < candidates.Length; i++)
{
ParameterInfo[] par = candidates[i].GetParametersNoCopy();
if (par.Length != types.Length)
continue;
for (j = 0; j < types.Length; j++)
{
Type pCls = par[j].ParameterType;
if (types[j].MatchesParameterTypeExactly(par[j]))
continue;
if (pCls == typeof(object))
continue;
Type type = types[j];
if (type is SignatureType signatureType)
{
if (!(candidates[i] is MethodInfo methodInfo))
break;
type = signatureType.TryResolveAgainstGenericMethod(methodInfo);
if (type == null)
break;
}
if (pCls.IsPrimitive)
{
if (!(type.UnderlyingSystemType.IsRuntimeImplemented()) ||
!CanChangePrimitive(type.UnderlyingSystemType, pCls.UnderlyingSystemType))
break;
}
else
{
if (!pCls.IsAssignableFrom(type))
break;
}
}
if (j == types.Length)
candidates[CurIdx++] = candidates[i];
}
if (CurIdx == 0)
return null;
if (CurIdx == 1)
return candidates[0];
// Walk all of the methods looking the most specific method to invoke
int currentMin = 0;
bool ambig = false;
int[] paramOrder = new int[types.Length];
for (i = 0; i < types.Length; i++)
paramOrder[i] = i;
for (i = 1; i < CurIdx; i++)
{
int newMin = FindMostSpecificMethod(candidates[currentMin], paramOrder, null, candidates[i], paramOrder, null, types, null);
if (newMin == 0)
ambig = true;
else
{
if (newMin == 2)
{
currentMin = i;
ambig = false;
currentMin = i;
}
}
}
if (ambig)
throw new AmbiguousMatchException(SR.Arg_AmbiguousMatchException);
return candidates[currentMin];
}
// CanChangePrimitive
// This will determine if the source can be converted to the target type
private static bool CanChangePrimitive(Type source, Type target)
{
return CanPrimitiveWiden(source, target);
}
// CanChangePrimitiveObjectToType
private static bool CanChangePrimitiveObjectToType(object source, Type type)
{
return CanPrimitiveWiden(source.GetType(), type);
}
private static bool CanPrimitiveWiden(Type source, Type target)
{
Primitives widerCodes = _primitiveConversions[(int)(Type.GetTypeCode(source))];
Primitives targetCode = (Primitives)(1 << (int)(Type.GetTypeCode(target)));
return 0 != (widerCodes & targetCode);
}
[Flags]
private enum Primitives
{
Boolean = 1 << (int)TypeCode.Boolean,
Char = 1 << (int)TypeCode.Char,
SByte = 1 << (int)TypeCode.SByte,
Byte = 1 << (int)TypeCode.Byte,
Int16 = 1 << (int)TypeCode.Int16,
UInt16 = 1 << (int)TypeCode.UInt16,
Int32 = 1 << (int)TypeCode.Int32,
UInt32 = 1 << (int)TypeCode.UInt32,
Int64 = 1 << (int)TypeCode.Int64,
UInt64 = 1 << (int)TypeCode.UInt64,
Single = 1 << (int)TypeCode.Single,
Double = 1 << (int)TypeCode.Double,
Decimal = 1 << (int)TypeCode.Decimal,
DateTime = 1 << (int)TypeCode.DateTime,
String = 1 << (int)TypeCode.String,
}
private static Primitives[] _primitiveConversions = new Primitives[]
{
/* Empty */ 0, // not primitive
/* Object */ 0, // not primitive
/* DBNull */ 0, // not exposed.
/* Boolean */ Primitives.Boolean,
/* Char */ Primitives.Char | Primitives.UInt16 | Primitives.UInt32 | Primitives.Int32 | Primitives.UInt64 | Primitives.Int64 | Primitives.Single | Primitives.Double,
/* SByte */ Primitives.SByte | Primitives.Int16 | Primitives.Int32 | Primitives.Int64 | Primitives.Single | Primitives.Double,
/* Byte */ Primitives.Byte | Primitives.Char | Primitives.UInt16 | Primitives.Int16 | Primitives.UInt32 | Primitives.Int32 | Primitives.UInt64 | Primitives.Int64 | Primitives.Single | Primitives.Double,
/* Int16 */ Primitives.Int16 | Primitives.Int32 | Primitives.Int64 | Primitives.Single | Primitives.Double,
/* UInt16 */ Primitives.UInt16 | Primitives.UInt32 | Primitives.Int32 | Primitives.UInt64 | Primitives.Int64 | Primitives.Single | Primitives.Double,
/* Int32 */ Primitives.Int32 | Primitives.Int64 | Primitives.Single | Primitives.Double,
/* UInt32 */ Primitives.UInt32 | Primitives.UInt64 | Primitives.Int64 | Primitives.Single | Primitives.Double,
/* Int64 */ Primitives.Int64 | Primitives.Single | Primitives.Double,
/* UInt64 */ Primitives.UInt64 | Primitives.Single | Primitives.Double,
/* Single */ Primitives.Single | Primitives.Double,
/* Double */ Primitives.Double,
/* Decimal */ Primitives.Decimal,
/* DateTime */ Primitives.DateTime,
/* [Unused] */ 0,
/* String */ Primitives.String,
};
}
}

View File

@@ -0,0 +1,56 @@
using System;
using System.Security.AccessControl;
namespace System.IO
{
public partial class Directory
{
public static DirectorySecurity GetAccessControl(string path, AccessControlSections includeSections)
{
return new DirectorySecurity (path, includeSections);
}
public static DirectorySecurity GetAccessControl (string path)
{
// AccessControlSections.Audit requires special permissions.
return GetAccessControl (path,
AccessControlSections.Owner |
AccessControlSections.Group |
AccessControlSections.Access);
}
public static void SetAccessControl(string path, DirectorySecurity directorySecurity)
{
if (directorySecurity == null)
throw new ArgumentNullException(nameof(directorySecurity));
String fullPath = Path.GetFullPath(path);
directorySecurity.PersistModifications(fullPath);
}
// Used by System.Environment
internal static string InsecureGetCurrentDirectory()
{
MonoIOError error;
string result = MonoIO.GetCurrentDirectory(out error);
if (error != MonoIOError.ERROR_SUCCESS)
throw MonoIO.GetException(error);
return result;
}
internal static void InsecureSetCurrentDirectory(string path)
{
if (path == null)
throw new ArgumentNullException ("path");
if (path.Trim ().Length == 0)
throw new ArgumentException ("path string must not be an empty string or whitespace string");
MonoIOError error;
if (!Exists (path))
throw new DirectoryNotFoundException ("Directory \"" +
path + "\" not found.");
MonoIO.SetCurrentDirectory (path, out error);
if (error != MonoIOError.ERROR_SUCCESS)
throw MonoIO.GetException (path, error);
}
}
}

View File

@@ -0,0 +1,26 @@
using System;
using System.Runtime.Serialization;
using System.Security.AccessControl;
namespace System.IO
{
public partial class DirectoryInfo
{
private DirectoryInfo(SerializationInfo info, StreamingContext context) : base(info, context) { }
public DirectorySecurity GetAccessControl()
{
return Directory.GetAccessControl(FullPath, AccessControlSections.Access | AccessControlSections.Owner | AccessControlSections.Group);
}
public DirectorySecurity GetAccessControl(AccessControlSections includeSections)
{
return Directory.GetAccessControl(FullPath, includeSections);
}
public void SetAccessControl(DirectorySecurity directorySecurity)
{
Directory.SetAccessControl(FullPath, directorySecurity);
}
}
}

View File

@@ -2,10 +2,10 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
internal static partial class Interop
namespace System.IO
{
internal static partial class Libraries
internal static partial class DriveInfoInternal
{
internal const string Advapi32 = "advapi32.dll";
internal static string[] GetLogicalDrives() => Environment.GetLogicalDrivesInternal ();
}
}

View File

@@ -0,0 +1,31 @@
using System;
using System.Security.AccessControl;
namespace System.IO
{
public partial class File
{
public static FileSecurity GetAccessControl (string path)
{
// AccessControlSections.Audit requires special permissions.
return GetAccessControl (path,
AccessControlSections.Owner |
AccessControlSections.Group |
AccessControlSections.Access);
}
public static FileSecurity GetAccessControl (string path, AccessControlSections includeSections)
{
return new FileSecurity (path, includeSections);
}
public static void SetAccessControl (string path,
FileSecurity fileSecurity)
{
if (null == fileSecurity)
throw new ArgumentNullException ("fileSecurity");
fileSecurity.PersistModifications (path);
}
}
}

View File

@@ -0,0 +1,39 @@
using System;
using System.Runtime.Serialization;
using System.Security.AccessControl;
namespace System.IO
{
public partial class FileInfo
{
private FileInfo(SerializationInfo info, StreamingContext context) : base(info, context) { }
public FileSecurity GetAccessControl()
{
return File.GetAccessControl(FullPath, AccessControlSections.Access | AccessControlSections.Owner | AccessControlSections.Group);
}
public FileSecurity GetAccessControl(AccessControlSections includeSections)
{
return File.GetAccessControl(FullPath, includeSections);
}
public void SetAccessControl(FileSecurity fileSecurity)
{
File.SetAccessControl(FullPath, fileSecurity);
}
// Reference source code in Mono still uses this
internal FileInfo(string fullPath, bool ignoreThis)
{
_name = Path.GetFileName(fullPath);
OriginalPath = _name;
FullPath = fullPath;
}
public override String Name {
get { return _name; }
}
}
}

View File

@@ -0,0 +1,5 @@
namespace System.Reflection {
partial class MethodInfo {
internal virtual int GenericParameterCount => GetGenericArguments ().Length;
}
}

View File

@@ -0,0 +1,16 @@
// Helper class providing missing System.Linq functionality
// for CoreFX code
using System;
using System.Collections.Generic;
namespace System.IO
{
internal static class MonoLinqHelper
{
public static T[] ToArray<T>(this IEnumerable<T> source)
{
return EnumerableHelpers.ToArray<T> (source);
}
}
}

View File

@@ -0,0 +1,17 @@
namespace System.Security.Cryptography
{
partial class RandomNumberGenerator
{
public static void Fill (Span<byte> data)
{
FillSpan (data);
}
internal static unsafe void FillSpan (Span<byte> data)
{
if (data.Length > 0) {
fixed (byte* ptr = data) Interop.GetRandomBytes (ptr, data.Length);
}
}
}
}

View File

@@ -1 +1 @@
2198d9a8d7e614566f4b7cc49859d594b6827bfb
c924ca12f5eed8122fd0b8ca78a6b339fae2c971

View File

@@ -12,15 +12,15 @@ partial class SR
public const string PlatformNotSupported_Serialization = "This instance contains state that cannot be serialized and deserialized on this platform.";
public const string PrivilegeNotHeld_Default = "The process does not possess some privilege required for this operation.";
public const string PrivilegeNotHeld_Named = "The process does not possess the '{0}' privilege which is required for this operation.";
public const string CountdownEvent_Decrement_BelowZero = "CountdownEvent_Decrement_BelowZero";
public const string CountdownEvent_Increment_AlreadyZero = "CountdownEvent_Increment_AlreadyZero";
public const string CountdownEvent_Increment_AlreadyMax = "CountdownEvent_Increment_AlreadyMax";
public const string ArrayWithOffsetOverflow = "ArrayWithOffsetOverflow";
public const string Arg_NotIsomorphic = "Arg_NotIsomorphic";
public const string StructArrayTooLarge = "StructArrayTooLarge";
public const string IO_DriveNotFound = "IO_DriveNotFound";
public const string Argument_MustSupplyParent = "Argument_MustSupplyParent";
public const string Argument_MemberAndArray = "Argument_MemberAndArray";
public const string Argument_MustSupplyContainer = "Argument_MustSupplyContainer";
public const string Serialization_NoID = "Serialization_NoID";
public const string CountdownEvent_Decrement_BelowZero = "Invalid attempt made to decrement the event's count below zero.";
public const string CountdownEvent_Increment_AlreadyZero = "The event is already signaled and cannot be incremented.";
public const string CountdownEvent_Increment_AlreadyMax = "The increment operation would cause the CurrentCount to overflow.";
public const string ArrayWithOffsetOverflow = "ArrayWithOffset: offset exceeds array size.";
public const string Arg_NotIsomorphic = "Object contains non-primitive or non-blittable data.";
public const string StructArrayTooLarge = "Array size exceeds addressing limitations.";
public const string IO_DriveNotFound = "Could not find the drive. The drive might not be ready or might not be mapped.";
public const string Argument_MustSupplyParent = "When supplying the ID of a containing object, the FieldInfo that identifies the current field within that object must also be supplied.";
public const string Argument_MemberAndArray = "Cannot supply both a MemberInfo and an Array to indicate the parent of a value type.";
public const string Argument_MustSupplyContainer = "When supplying a FieldInfo for fixing up a nested type, a valid ID for that containing object must also be supplied.";
public const string Serialization_NoID = "Object has never been assigned an objectID";
}

View File

@@ -0,0 +1,15 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System.Runtime.Serialization;
namespace System
{
[Serializable]
partial class TimeZone
{
// copied from old System/TimeZone.cs
internal static void ClearCachedData () => currentTimeZone = null;
}
}

View File

@@ -0,0 +1,69 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
namespace System
{
partial class TimeZoneInfo
{
//
// TransitionTimeToDateTime -
//
// Helper function that converts a year and TransitionTime into a DateTime
//
static internal DateTime TransitionTimeToDateTime(Int32 year, TransitionTime transitionTime) {
DateTime value;
DateTime timeOfDay = transitionTime.TimeOfDay;
if (transitionTime.IsFixedDateRule) {
// create a DateTime from the passed in year and the properties on the transitionTime
// if the day is out of range for the month then use the last day of the month
Int32 day = DateTime.DaysInMonth(year, transitionTime.Month);
value = new DateTime(year, transitionTime.Month, (day < transitionTime.Day) ? day : transitionTime.Day,
timeOfDay.Hour, timeOfDay.Minute, timeOfDay.Second, timeOfDay.Millisecond);
}
else {
if (transitionTime.Week <= 4) {
//
// Get the (transitionTime.Week)th Sunday.
//
value = new DateTime(year, transitionTime.Month, 1,
timeOfDay.Hour, timeOfDay.Minute, timeOfDay.Second, timeOfDay.Millisecond);
int dayOfWeek = (int)value.DayOfWeek;
int delta = (int)transitionTime.DayOfWeek - dayOfWeek;
if (delta < 0) {
delta += 7;
}
delta += 7 * (transitionTime.Week - 1);
if (delta > 0) {
value = value.AddDays(delta);
}
}
else {
//
// If TransitionWeek is greater than 4, we will get the last week.
//
Int32 daysInMonth = DateTime.DaysInMonth(year, transitionTime.Month);
value = new DateTime(year, transitionTime.Month, daysInMonth,
timeOfDay.Hour, timeOfDay.Minute, timeOfDay.Second, timeOfDay.Millisecond);
// This is the day of week for the last day of the month.
int dayOfWeek = (int)value.DayOfWeek;
int delta = dayOfWeek - (int)transitionTime.DayOfWeek;
if (delta < 0) {
delta += 7;
}
if (delta > 0) {
value = value.AddDays(-delta);
}
}
}
return value;
}
} // TimezoneInfo
} // namespace System