Imported Upstream version 4.6.0.125

Former-commit-id: a2155e9bd80020e49e72e86c44da02a8ac0e57a4
This commit is contained in:
Xamarin Public Jenkins (auto-signing)
2016-08-03 10:59:49 +00:00
parent a569aebcfd
commit e79aa3c0ed
17047 changed files with 3137615 additions and 392334 deletions

View File

@@ -0,0 +1,17 @@
//------------------------------------------------------------------------------
// <copyright file="BitmapSuffixInSameAssemblyAttribute.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
namespace System.Drawing {
using System;
/// <summary>
/// Opt-In flag to look for resources in the another assembly with the "bitmapSuffix" config setting
/// i.e. System.dll -> System<.VisualStudio.11.0>.dll
/// </summary>
[AttributeUsage(AttributeTargets.Assembly)]
internal class BitmapSuffixInSatelliteAssemblyAttribute : Attribute {
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,57 @@
//------------------------------------------------------------------------------
// <copyright file="CompatibleComparer.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
/*
* This class is used to create hashcodes that are Everett Compatible.
*
* Copyright (c) 2004 Microsoft Corporation
*/
namespace System.Collections.Specialized {
using Microsoft.Win32;
using System.Collections;
using System.Runtime.Serialization;
using System.Globalization;
internal class BackCompatibleStringComparer : IEqualityComparer {
static internal IEqualityComparer Default = new BackCompatibleStringComparer();
internal BackCompatibleStringComparer() {
}
//This comes from VS# 434837 and is specifically written to get backcompat
public static int GetHashCode(string obj) {
unsafe {
fixed (char* src = obj) {
int hash = 5381;
int c;
char* szStr = src;
while ((c = *szStr) != 0) {
hash = ((hash << 5) + hash) ^ c;
++szStr;
}
return hash;
}
}
}
bool IEqualityComparer.Equals(Object a, Object b) {
return Object.Equals(a, b);
}
public virtual int GetHashCode(Object o) {
String obj = o as string;
if (obj == null) {
return o.GetHashCode();
}
return BackCompatibleStringComparer.GetHashCode(obj);
}
}
}

View File

@@ -0,0 +1,28 @@
//------------------------------------------------------------------------------
// <copyright file="PrivilegedConfigurationManager.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
#if CONFIGURATION_DEP
namespace System.Configuration {
using System.Collections.Specialized;
using System.Security;
using System.Security.Permissions;
[ConfigurationPermission(SecurityAction.Assert, Unrestricted=true)]
internal static class PrivilegedConfigurationManager {
internal static ConnectionStringSettingsCollection ConnectionStrings {
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
get {
return ConfigurationManager.ConnectionStrings;
}
}
internal static object GetSection(string sectionName) {
return ConfigurationManager.GetSection(sectionName);
}
}
}
#endif

View File

@@ -0,0 +1,257 @@
//------------------------------------------------------------------------------
// <copyright file="SecurityUtils.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
/*
*/
#if WINFORMS_NAMESPACE
namespace System.Windows.Forms
#elif DRAWING_NAMESPACE
namespace System.Drawing
#elif WINFORMS_PUBLIC_GRAPHICS_LIBRARY
namespace System.Internal
#elif SYSTEM_NAMESPACE
namespace System
#elif SYSTEM_WEB
namespace System.Web
#elif SYSTEM_DATA_LINQ
namespace System.Data.Linq
#else
namespace System.Windows.Forms
#endif
{
using System;
using System.Reflection;
using System.Diagnostics.CodeAnalysis;
using System.Security;
using System.Security.Permissions;
/// <devdoc>
/// Useful methods to securely call 'dangerous' managed APIs (especially reflection).
/// See http://wiki/default.aspx/Microsoft.Projects.DotNetClient.SecurityConcernsAroundReflection
/// for more information specifically about why we need to be careful about reflection invocations.
/// </devdoc>
internal static class SecurityUtils {
private static volatile ReflectionPermission memberAccessPermission = null;
private static volatile ReflectionPermission restrictedMemberAccessPermission = null;
private static ReflectionPermission MemberAccessPermission
{
get {
if (memberAccessPermission == null) {
memberAccessPermission = new ReflectionPermission(ReflectionPermissionFlag.MemberAccess);
}
return memberAccessPermission;
}
}
private static ReflectionPermission RestrictedMemberAccessPermission {
get {
if (restrictedMemberAccessPermission == null) {
restrictedMemberAccessPermission = new ReflectionPermission(ReflectionPermissionFlag.RestrictedMemberAccess);
}
return restrictedMemberAccessPermission;
}
}
private static void DemandReflectionAccess(Type type) {
#if FEATURE_MONO_CAS
try {
MemberAccessPermission.Demand();
}
catch (SecurityException) {
DemandGrantSet(type.Assembly);
}
#endif
}
[SecuritySafeCritical]
private static void DemandGrantSet(Assembly assembly) {
#if FEATURE_MONO_CAS
PermissionSet targetGrantSet = assembly.PermissionSet;
targetGrantSet.AddPermission(RestrictedMemberAccessPermission);
targetGrantSet.Demand();
#endif
}
private static bool HasReflectionPermission(Type type) {
try {
DemandReflectionAccess(type);
return true;
}
catch (SecurityException) {
}
return false;
}
/// <devdoc>
/// This helper method provides safe access to Activator.CreateInstance.
/// NOTE: This overload will work only with public .ctors.
/// </devdoc>
internal static object SecureCreateInstance(Type type) {
return SecureCreateInstance(type, null, false);
}
/// <devdoc>
/// This helper method provides safe access to Activator.CreateInstance.
/// Set allowNonPublic to true if you want non public ctors to be used.
/// </devdoc>
internal static object SecureCreateInstance(Type type, object[] args, bool allowNonPublic) {
if (type == null) {
throw new ArgumentNullException("type");
}
BindingFlags flags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.CreateInstance;
// if it's an internal type, we demand reflection permission.
if (!type.IsVisible) {
DemandReflectionAccess(type);
}
else if (allowNonPublic && !HasReflectionPermission(type)) {
// Someone is trying to instantiate a public type in *our* assembly, but does not
// have full reflection permission. We shouldn't pass BindingFlags.NonPublic in this case.
// The reason we don't directly demand the permission here is because we don't know whether
// a public or non-public .ctor will be invoked. We want to allow the public .ctor case to
// succeed.
allowNonPublic = false;
}
if (allowNonPublic) {
flags |= BindingFlags.NonPublic;
}
return Activator.CreateInstance(type, flags, null, args, null);
}
#if (!WINFORMS_NAMESPACE)
/// <devdoc>
/// This helper method provides safe access to Activator.CreateInstance.
/// NOTE: This overload will work only with public .ctors.
/// </devdoc>
internal static object SecureCreateInstance(Type type, object[] args) {
return SecureCreateInstance(type, args, false);
}
/// <devdoc>
/// Helper method to safely invoke a .ctor. You should prefer SecureCreateInstance to this.
/// Set allowNonPublic to true if you want non public ctors to be used.
/// </devdoc>
internal static object SecureConstructorInvoke(Type type, Type[] argTypes, object[] args, bool allowNonPublic) {
return SecureConstructorInvoke(type, argTypes, args, allowNonPublic, BindingFlags.Default);
}
/// <devdoc>
/// Helper method to safely invoke a .ctor. You should prefer SecureCreateInstance to this.
/// Set allowNonPublic to true if you want non public ctors to be used.
/// The 'extraFlags' parameter is used to pass in any other flags you need,
/// besides Public, NonPublic and Instance.
/// </devdoc>
internal static object SecureConstructorInvoke(Type type, Type[] argTypes, object[] args,
bool allowNonPublic, BindingFlags extraFlags) {
if (type == null) {
throw new ArgumentNullException("type");
}
// if it's an internal type, we demand reflection permission.
if (!type.IsVisible) {
DemandReflectionAccess(type);
}
else if (allowNonPublic && !HasReflectionPermission(type)) {
// Someone is trying to invoke a ctor on a public type, but does not
// have full reflection permission. We shouldn't pass BindingFlags.NonPublic in this case.
allowNonPublic = false;
}
BindingFlags flags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | extraFlags;
if (!allowNonPublic) {
flags &= ~BindingFlags.NonPublic;
}
ConstructorInfo ctor = type.GetConstructor(flags, null, argTypes, null);
if (ctor != null) {
return ctor.Invoke(args);
}
return null;
}
private static bool GenericArgumentsAreVisible(MethodInfo method) {
if (method.IsGenericMethod) {
Type[] parameterTypes = method.GetGenericArguments();
foreach (Type type in parameterTypes) {
if (!type.IsVisible) {
return false;
}
}
}
return true;
}
/// <devdoc>
/// This helper method provides safe access to FieldInfo's GetValue method.
/// </devdoc>
internal static object FieldInfoGetValue(FieldInfo field, object target) {
Type type = field.DeclaringType;
if (type == null) {
// Type is null for Global fields.
if (!field.IsPublic) {
DemandGrantSet(field.Module.Assembly);
}
} else if (!(type != null && type.IsVisible && field.IsPublic)) {
DemandReflectionAccess(type);
}
return field.GetValue(target);
}
/// <devdoc>
/// This helper method provides safe access to MethodInfo's Invoke method.
/// </devdoc>
internal static object MethodInfoInvoke(MethodInfo method, object target, object[] args) {
Type type = method.DeclaringType;
if (type == null) {
// Type is null for Global methods. In this case we would need to demand grant set on
// the containing assembly for internal methods.
if (!(method.IsPublic && GenericArgumentsAreVisible(method))) {
DemandGrantSet(method.Module.Assembly);
}
} else if (!(type.IsVisible && method.IsPublic && GenericArgumentsAreVisible(method))) {
// this demand is required for internal types in system.dll and its friend assemblies.
DemandReflectionAccess(type);
}
return method.Invoke(target, args);
}
/// <devdoc>
/// This helper method provides safe access to ConstructorInfo's Invoke method.
/// Constructors can't be generic, so we don't check if argument types are visible
/// </devdoc>
internal static object ConstructorInfoInvoke(ConstructorInfo ctor, object[] args) {
Type type = ctor.DeclaringType;
if ((type != null) && !(type.IsVisible && ctor.IsPublic)) {
DemandReflectionAccess(type);
}
return ctor.Invoke(args);
}
/// <devdoc>
/// This helper method provides safe access to Array.CreateInstance.
/// </devdoc>
internal static object ArrayCreateInstance(Type type, int length) {
if (!type.IsVisible) {
DemandReflectionAccess(type);
}
return Array.CreateInstance(type, length);
}
#endif
}
}

View File

@@ -0,0 +1,227 @@
//------------------------------------------------------------------------------
// <copyright file="WeakHashtable.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
namespace System.ComponentModel {
using System;
using System.Collections;
using System.Security.Permissions;
/// <devdoc>
/// This is a hashtable that stores object keys as weak references.
/// It monitors memory usage and will periodically scavenge the
/// hash table to clean out dead references.
/// </devdoc>
[HostProtection(SharedState = true)]
internal sealed class WeakHashtable : Hashtable
{
private static IEqualityComparer _comparer = new WeakKeyComparer();
private long _lastGlobalMem;
private int _lastHashCount;
internal WeakHashtable() : base(_comparer)
{
}
/// <devdoc>
/// Override of clear that performs a scavenge.
/// </devdoc>
public override void Clear()
{
base.Clear();
}
/// <devdoc>
/// Override of remove that performs a scavenge.
/// </devdoc>
public override void Remove(object key)
{
base.Remove(key);
}
/// <devdoc>
/// Override of Item that wraps a weak reference around the
/// key and performs a scavenge.
/// </devdoc>
public void SetWeak(object key, object value)
{
ScavengeKeys();
this[new EqualityWeakReference(key)] = value;
}
/// <devdoc>
/// This method checks to see if it is necessary to
/// scavenge keys, and if it is it performs a scan
/// of all keys to see which ones are no longer valid.
/// To determine if we need to scavenge keys we need to
/// try to track the current GC memory. Our rule of
/// thumb is that if GC memory is decreasing and our
/// key count is constant we need to scavenge. We
/// will need to see if this is too often for extreme
/// use cases like the CompactFramework (they add
/// custom type data for every object at design time).
/// </devdoc>
private void ScavengeKeys()
{
int hashCount = Count;
if (hashCount == 0)
{
return;
}
if (_lastHashCount == 0)
{
_lastHashCount = hashCount;
return;
}
long globalMem = GC.GetTotalMemory(false);
if (_lastGlobalMem == 0)
{
_lastGlobalMem = globalMem;
return;
}
float memDelta = (float)(globalMem - _lastGlobalMem) / (float)_lastGlobalMem;
float hashDelta = (float)(hashCount - _lastHashCount) / (float)_lastHashCount;
if (memDelta < 0 && hashDelta >= 0)
{
// Perform a scavenge through our keys, looking
// for dead references.
//
ArrayList cleanupList = null;
foreach(object o in Keys)
{
WeakReference wr = o as WeakReference;
if (wr != null && !wr.IsAlive)
{
if (cleanupList == null)
{
cleanupList = new ArrayList();
}
cleanupList.Add(wr);
}
}
if (cleanupList != null)
{
foreach(object o in cleanupList)
{
Remove(o);
}
}
}
_lastGlobalMem = globalMem;
_lastHashCount = hashCount;
}
private class WeakKeyComparer : IEqualityComparer
{
bool IEqualityComparer.Equals(Object x, Object y)
{
if (x == null)
{
return y == null;
}
if (y != null && x.GetHashCode() == y.GetHashCode())
{
WeakReference wX = x as WeakReference;
WeakReference wY = y as WeakReference;
if (wX != null)
{
if (!wX.IsAlive)
{
return false;
}
x = wX.Target;
}
if (wY != null)
{
if (!wY.IsAlive)
{
return false;
}
y = wY.Target;
}
return object.ReferenceEquals(x, y);
}
return false;
}
int IEqualityComparer.GetHashCode (Object obj)
{
return obj.GetHashCode();
}
}
/// <devdoc>
/// A subclass of WeakReference that overrides GetHashCode and
/// Equals so that the weak reference returns the same equality
/// semantics as the object it wraps. This will always return
/// the object's hash code and will return True for a Equals
/// comparison of the object it is wrapping. If the object
/// it is wrapping has finalized, Equals always returns false.
/// </devdoc>
private sealed class EqualityWeakReference : WeakReference
{
private int _hashCode;
internal EqualityWeakReference(object o) : base(o)
{
_hashCode = o.GetHashCode();
}
public override bool Equals(object o)
{
if (o == null)
{
return false;
}
if (o.GetHashCode() != _hashCode)
{
return false;
}
if (o == this || (IsAlive && object.ReferenceEquals(o, Target)))
{
return true;
}
return false;
}
public override int GetHashCode()
{
return _hashCode;
}
}
/* The folowing code has been removed to prevent FXCOP violation
It is left here incase it needs to be resurected
/// <devdoc>
/// Override of add that wraps a weak reference around the
/// key and performs a scavenge.
/// </devdoc>
public void AddWeak(object key, object value)
{
ScavengeKeys();
base.Add(new EqualityWeakReference(key), value);
}
*/
}
}

View File

@@ -0,0 +1,85 @@
//------------------------------------------------------------------------------
// <copyright file="ExternDll.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
namespace System {
internal static class ExternDll {
#if FEATURE_PAL && !SILVERLIGHT
#if !PLATFORM_UNIX
internal const String DLLPREFIX = "";
internal const String DLLSUFFIX = ".dll";
#else // !PLATFORM_UNIX
#if __APPLE__
internal const String DLLPREFIX = "lib";
internal const String DLLSUFFIX = ".dylib";
#elif _AIX
internal const String DLLPREFIX = "lib";
internal const String DLLSUFFIX = ".a";
#elif __hppa__ || IA64
internal const String DLLPREFIX = "lib";
internal const String DLLSUFFIX = ".sl";
#else
internal const String DLLPREFIX = "lib";
internal const String DLLSUFFIX = ".so";
#endif
#endif // !PLATFORM_UNIX
public const string Kernel32 = DLLPREFIX + "rotor_pal" + DLLSUFFIX;
public const string User32 = DLLPREFIX + "rotor_pal" + DLLSUFFIX;
public const string Mscoree = DLLPREFIX + "sscoree" + DLLSUFFIX;
#elif FEATURE_PAL && SILVERLIGHT
public const string Kernel32 = "coreclr";
public const string User32 = "coreclr";
#else
public const string Activeds = "activeds.dll";
public const string Advapi32 = "advapi32.dll";
public const string Comctl32 = "comctl32.dll";
public const string Comdlg32 = "comdlg32.dll";
public const string Gdi32 = "gdi32.dll";
public const string Gdiplus = "gdiplus.dll";
public const string Hhctrl = "hhctrl.ocx";
public const string Imm32 = "imm32.dll";
public const string Kernel32 = "kernel32.dll";
public const string Loadperf = "Loadperf.dll";
public const string Mscoree = "mscoree.dll";
public const string Clr = "clr.dll";
public const string Msi = "msi.dll";
public const string Mqrt = "mqrt.dll";
public const string Ntdll = "ntdll.dll";
public const string Ole32 = "ole32.dll";
public const string Oleacc = "oleacc.dll";
public const string Oleaut32 = "oleaut32.dll";
public const string Olepro32 = "olepro32.dll";
public const string PerfCounter = "perfcounter.dll";
public const string Powrprof = "Powrprof.dll";
public const string Psapi = "psapi.dll";
public const string Shell32 = "shell32.dll";
public const string User32 = "user32.dll";
public const string Uxtheme = "uxtheme.dll";
public const string WinMM = "winmm.dll";
public const string Winspool = "winspool.drv";
public const string Wtsapi32 = "wtsapi32.dll";
public const string Version = "version.dll";
public const string Vsassert = "vsassert.dll";
public const string Fxassert = "Fxassert.dll";
public const string Shlwapi = "shlwapi.dll";
public const string Crypt32 = "crypt32.dll";
// system.data specific
internal const string Odbc32 = "odbc32.dll";
internal const string SNI = "System.Data.dll";
// system.data.oracleclient specific
internal const string OciDll = "oci.dll";
internal const string OraMtsDll = "oramts.dll";
#endif //!FEATURE_PAL
}
}

View File

@@ -0,0 +1,105 @@
//------------------------------------------------------------------------------
// <copyright file="HResults.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
/*
These HRESULTs are used for mapping managed exceptions to COM error codes
and vice versa through COM Interop. For background on COM error codes see
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/com/error_9td2.asp.
FACILITY_URT is defined as 0x13 (0x8013xxxx). The facility range is reserved
for the .NET Framework SDK teams.
Within that range, the following subranges have been allocated for different
feature areas:
0x10yy for Execution Engine
0x11yy for Metadata, TypeLib Export, and CLDB
0x12yy for MetaData Validator
0x13yy for Debugger and Profiler errors
0x14yy for Security
0x15yy for BCL
0x1600 - 0x161F for Reflection
0x1620 - 0x163F for System.IO
0x1640 - 0x165F for Security
0x1660 - 0x16FF for BCL
0x17yy for shim
0x18yy for IL Verifier
0x19yy for .NET Framework
0x1Ayy for .NET Framework
0x1Byy for MetaData Validator
0x30yy for VSA errors
CLR HRESULTs are defined in corerror.h. If you make any modifications to
the range allocations described above, please make sure the corerror.h file
gets updated.
*/
namespace System {
using System;
internal static class HResults{
internal const int Configuration = unchecked((int)0x80131902);
// Xml
internal const int Xml = unchecked((int)0x80131940);
internal const int XmlSchema = unchecked((int)0x80131941);
internal const int XmlXslt = unchecked((int)0x80131942);
internal const int XmlXPath = unchecked((int)0x80131943);
// DataSet
internal const int Data = unchecked((int)0x80131920);
internal const int DataDeletedRowInaccessible = unchecked((int)0x80131921);
internal const int DataDuplicateName = unchecked((int)0x80131922);
internal const int DataInRowChangingEvent = unchecked((int)0x80131923);
internal const int DataInvalidConstraint = unchecked((int)0x80131924);
internal const int DataMissingPrimaryKey = unchecked((int)0x80131925);
internal const int DataNoNullAllowed = unchecked((int)0x80131926);
internal const int DataReadOnly = unchecked((int)0x80131927);
internal const int DataRowNotInTable = unchecked((int)0x80131928);
internal const int DataVersionNotFound = unchecked((int)0x80131929);
internal const int DataConstraint = unchecked((int)0x8013192A);
internal const int StrongTyping = unchecked((int)0x8013192B);
// Managed Providers
internal const int SqlType = unchecked((int)0x80131930);
internal const int SqlNullValue = unchecked((int)0x80131931);
internal const int SqlTruncate = unchecked((int)0x80131932);
internal const int AdapterMapping = unchecked((int)0x80131933);
internal const int DataAdapter = unchecked((int)0x80131934);
internal const int DBConcurrency = unchecked((int)0x80131935);
internal const int OperationAborted = unchecked((int)0x80131936);
internal const int InvalidUdt = unchecked((int)0x80131937);
internal const int Metadata = unchecked((int)0x80131939);
internal const int InvalidQuery = unchecked((int)0x8013193A);
internal const int CommandCompilation = unchecked((int)0x8013193B);
internal const int CommandExecution = unchecked((int)0x8013193C);
internal const int SqlException = unchecked((int)0x80131904); // System.Data.SqlClient.SqlClientException
internal const int OdbcException = unchecked((int)0x80131937); // System.Data.Odbc.OdbcException
internal const int OracleException = unchecked((int)0x80131938); // System.Data.OracleClient.OracleException
internal const int ConnectionPlanException = unchecked((int)0x8013193d); // System.Data.SqlClient.ConnectionPlanException
// Configuration encryption
internal const int NteBadKeySet = unchecked((int)0x80090016);
// Win32
internal const int Win32AccessDenied = unchecked((int)0x80070005);
internal const int Win32InvalidHandle = unchecked((int)0x80070006);
#if !FEATURE_PAL || MONO
internal const int License = unchecked((int)0x80131901);
internal const int InternalBufferOverflow = unchecked((int)0x80131905);
internal const int ServiceControllerTimeout = unchecked((int)0x80131906);
internal const int Install = unchecked((int)0x80131907);
// Win32
internal const int EFail = unchecked((int)0x80004005);
#endif
}
}

View File

@@ -0,0 +1,25 @@
namespace System {
using System;
using System.Collections;
using System.Globalization;
[Serializable]
internal class InvariantComparer : IComparer {
private CompareInfo m_compareInfo;
internal static readonly InvariantComparer Default = new InvariantComparer();
internal InvariantComparer() {
m_compareInfo = CultureInfo.InvariantCulture.CompareInfo;
}
public int Compare(Object a, Object b) {
String sa = a as String;
String sb = b as String;
if (sa != null && sb != null)
return m_compareInfo.Compare(sa, sb);
else
return Comparer.Default.Compare(a,b);
}
}
}