From: Santiago Fernandez Madero Date: Thu, 11 Apr 2019 22:45:02 +0000 (-0700) Subject: Merge remote-tracking branch 'dotnet/master' into merge-master-nullable X-Git-Tag: accepted/tizen/unified/20190813.215958~46^2~27^2~10^2~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=3bebe9316471d4e49d56ffd44417b77a53a0723a;p=platform%2Fupstream%2Fcoreclr.git Merge remote-tracking branch 'dotnet/master' into merge-master-nullable --- 3bebe9316471d4e49d56ffd44417b77a53a0723a diff --cc src/System.Private.CoreLib/shared/System/Activator.RuntimeType.cs index 224abdb,270aa6a..cc4ef6f --- a/src/System.Private.CoreLib/shared/System/Activator.RuntimeType.cs +++ b/src/System.Private.CoreLib/shared/System/Activator.RuntimeType.cs @@@ -2,9 -2,9 +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. +#nullable enable using System.Reflection; using System.Globalization; + using System.Runtime.Loader; using System.Runtime.Remoting; using System.Threading; diff --cc src/System.Private.CoreLib/shared/System/Environment.Win32.cs index f58cdcf,90e1ca9..bc32146 --- a/src/System.Private.CoreLib/shared/System/Environment.Win32.cs +++ b/src/System.Private.CoreLib/shared/System/Environment.Win32.cs @@@ -15,7 -14,9 +15,9 @@@ namespace Syste { public static partial class Environment { + internal static bool IsWindows8OrAbove => WindowsVersion.IsWindows8OrAbove; + - private static string GetEnvironmentVariableFromRegistry(string variable, bool fromMachine) + private static string? GetEnvironmentVariableFromRegistry(string variable, bool fromMachine) { Debug.Assert(variable != null); diff --cc src/System.Private.CoreLib/shared/System/Reflection/AssemblyName.cs index 7ea9b59,89a6217..7542e5a --- a/src/System.Private.CoreLib/shared/System/Reflection/AssemblyName.cs +++ b/src/System.Private.CoreLib/shared/System/Reflection/AssemblyName.cs @@@ -2,10 -2,8 +2,9 @@@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#nullable enable using System.Configuration.Assemblies; using System.IO; - using System.Runtime.CompilerServices; using System.Runtime.Serialization; using System.Text; using CultureInfo = System.Globalization.CultureInfo; @@@ -171,17 -158,10 +159,10 @@@ namespace System.Reflectio if (assemblyFile == null) throw new ArgumentNullException(nameof(assemblyFile)); - // Assembly.GetNameInternal() will not demand path discovery - // permission, so do that first. - string fullPath = Path.GetFullPath(assemblyFile); - return nGetFileInformation(fullPath); + return GetFileInformationCore(assemblyFile); } - // The public key that is used to verify an assemblies - // inclusion into the namespace. If the public key associated - // with the namespace cannot verify the assembly the assembly - // will fail to load. - public byte[] GetPublicKey() + public byte[]? GetPublicKey() { return _publicKey; } @@@ -297,104 -277,7 +278,7 @@@ return refName.Equals(defName, StringComparison.OrdinalIgnoreCase); } - [MethodImplAttribute(MethodImplOptions.InternalCall)] - internal extern void nInit(out RuntimeAssembly? assembly, bool raiseResolveEvent); - - internal void nInit() - { - RuntimeAssembly? dummy = null; - nInit(out dummy, false); - } - - internal void SetProcArchIndex(PortableExecutableKinds pek, ImageFileMachine ifm) - { - ProcessorArchitecture = CalculateProcArchIndex(pek, ifm, _flags); - } - - internal static ProcessorArchitecture CalculateProcArchIndex(PortableExecutableKinds pek, ImageFileMachine ifm, AssemblyNameFlags flags) - { - if (((uint)flags & 0xF0) == 0x70) - return ProcessorArchitecture.None; - - if ((pek & System.Reflection.PortableExecutableKinds.PE32Plus) == System.Reflection.PortableExecutableKinds.PE32Plus) - { - switch (ifm) - { - case System.Reflection.ImageFileMachine.IA64: - return ProcessorArchitecture.IA64; - case System.Reflection.ImageFileMachine.AMD64: - return ProcessorArchitecture.Amd64; - case System.Reflection.ImageFileMachine.I386: - if ((pek & System.Reflection.PortableExecutableKinds.ILOnly) == System.Reflection.PortableExecutableKinds.ILOnly) - return ProcessorArchitecture.MSIL; - break; - } - } - else - { - if (ifm == System.Reflection.ImageFileMachine.I386) - { - if ((pek & System.Reflection.PortableExecutableKinds.Required32Bit) == System.Reflection.PortableExecutableKinds.Required32Bit) - return ProcessorArchitecture.X86; - - if ((pek & System.Reflection.PortableExecutableKinds.ILOnly) == System.Reflection.PortableExecutableKinds.ILOnly) - return ProcessorArchitecture.MSIL; - - return ProcessorArchitecture.X86; - } - if (ifm == System.Reflection.ImageFileMachine.ARM) - { - return ProcessorArchitecture.Arm; - } - } - return ProcessorArchitecture.None; - } - - internal void Init(string? name, - byte[]? publicKey, - byte[]? publicKeyToken, - Version? version, - CultureInfo? cultureInfo, - AssemblyHashAlgorithm hashAlgorithm, - AssemblyVersionCompatibility versionCompatibility, - string? codeBase, - AssemblyNameFlags flags, - StrongNameKeyPair? keyPair) // Null if ref, matching Assembly if def - { - _name = name; - - if (publicKey != null) - { - _publicKey = new byte[publicKey.Length]; - Array.Copy(publicKey, 0, _publicKey, 0, publicKey.Length); - } - - if (publicKeyToken != null) - { - _publicKeyToken = new byte[publicKeyToken.Length]; - Array.Copy(publicKeyToken, 0, _publicKeyToken, 0, publicKeyToken.Length); - } - - if (version != null) - _version = (Version)version.Clone(); - - _cultureInfo = cultureInfo; - _hashAlgorithm = hashAlgorithm; - _versionCompatibility = versionCompatibility; - _codeBase = codeBase; - _flags = flags; - _strongNameKeyPair = keyPair; - } - - // This call opens and closes the file, but does not add the - // assembly to the domain. - [MethodImplAttribute(MethodImplOptions.InternalCall)] - internal static extern AssemblyName nGetFileInformation(string s); - - [MethodImplAttribute(MethodImplOptions.InternalCall)] - private extern byte[] nGetPublicKeyToken(); - - internal static string EscapeCodeBase(string codebase) + internal static string EscapeCodeBase(string? codebase) { if (codebase == null) return string.Empty; diff --cc src/System.Private.CoreLib/shared/System/Runtime/CompilerServices/RuntimeHelpers.cs index 902d4e4,6925d97..5528139 --- a/src/System.Private.CoreLib/shared/System/Runtime/CompilerServices/RuntimeHelpers.cs +++ b/src/System.Private.CoreLib/shared/System/Runtime/CompilerServices/RuntimeHelpers.cs @@@ -2,19 -2,19 +2,20 @@@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#nullable enable using System.Runtime.Serialization; + using Internal.Runtime.CompilerServices; namespace System.Runtime.CompilerServices { public static partial class RuntimeHelpers { - public delegate void TryCode(object userData); + public delegate void TryCode(object? userData); - public delegate void CleanupCode(object userData, bool exceptionThrown); + public delegate void CleanupCode(object? userData, bool exceptionThrown); /// - /// GetSubArray helper method for the compiler to slice an array using a range. + /// Slices the specified array using the specified range. /// public static T[] GetSubArray(T[] array, Range range) { diff --cc src/System.Private.CoreLib/shared/System/Runtime/Loader/AssemblyLoadContext.cs index 1ba1c6d,4efd5de..8cabd5c --- a/src/System.Private.CoreLib/shared/System/Runtime/Loader/AssemblyLoadContext.cs +++ b/src/System.Private.CoreLib/shared/System/Runtime/Loader/AssemblyLoadContext.cs @@@ -2,8 -2,8 +2,9 @@@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#nullable enable using System.Collections.Generic; + using System.ComponentModel; using System.Diagnostics; using System.IO; using System.Reflection; @@@ -41,6 -39,14 +40,14 @@@ namespace System.Runtime.Loade // synchronization primitive to protect against usage of this instance while unloading private readonly object _unloadLock; + private event Func _resolvingUnmanagedDll; + + private event Func _resolving; + + private event Action _unloading; + - private readonly string _name; ++ private readonly string? _name; + // Contains the reference to VM's representation of the AssemblyLoadContext private readonly IntPtr _nativeAssemblyLoadContext; @@@ -56,12 -71,12 +72,12 @@@ { } - private protected AssemblyLoadContext(bool representsTPALoadContext, bool isCollectible, string name) + private protected AssemblyLoadContext(bool representsTPALoadContext, bool isCollectible, string? name) { // Initialize the VM side of AssemblyLoadContext if not already done. - IsCollectible = isCollectible; + _isCollectible = isCollectible; - Name = name; + _name = name; // The _unloadLock needs to be assigned after the IsCollectible to ensure proper behavior of the finalizer // even in case the following allocation fails or the thread is aborted between these two lines. @@@ -104,7 -119,7 +120,7 @@@ private void RaiseUnloadEvent() { // Ensure that we raise the Unload event only once - Interlocked.Exchange(ref Unloading, null!)?.Invoke(this); // TODO-NULLABLE: https://github.com/dotnet/roslyn/issues/26761 - Interlocked.Exchange(ref _unloading, null)?.Invoke(this); ++ Interlocked.Exchange(ref _unloading, null!)?.Invoke(this); // TODO-NULLABLE: https://github.com/dotnet/roslyn/issues/26761 } private void InitiateUnload() @@@ -181,9 -226,9 +227,9 @@@ public static AssemblyLoadContext Default => DefaultAssemblyLoadContext.s_loadContext; - public bool IsCollectible { get; } + public bool IsCollectible { get { return _isCollectible;} } - public string? Name { get; } - public string Name { get { return _name;} } ++ public string? Name { get { return _name;} } public override string ToString() => "\"" + Name + "\" " + GetType().ToString() + " #" + _id; diff --cc src/System.Private.CoreLib/shared/System/Threading/TimerQueue.Windows.cs index 0000000,0bd0cc4..923add5 mode 000000,100644..100644 --- a/src/System.Private.CoreLib/shared/System/Threading/TimerQueue.Windows.cs +++ b/src/System.Private.CoreLib/shared/System/Threading/TimerQueue.Windows.cs @@@ -1,0 -1,40 +1,41 @@@ + // 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. + ++#nullable enable + using System.Runtime.InteropServices; + + namespace System.Threading + { + internal partial class TimerQueue + { + private static int TickCount + { + get + { + // We need to keep our notion of time synchronized with the calls to SleepEx that drive + // the underlying native timer. In Win8, SleepEx does not count the time the machine spends + // sleeping/hibernating. Environment.TickCount (GetTickCount) *does* count that time, + // so we will get out of sync with SleepEx if we use that method. + // + // So, on Win8, we use QueryUnbiasedInterruptTime instead; this does not count time spent + // in sleep/hibernate mode. + if (Environment.IsWindows8OrAbove) + { + ulong time100ns; + + bool result = Interop.Kernel32.QueryUnbiasedInterruptTime(out time100ns); + if (!result) - Marshal.ThrowExceptionForHR(Marshal.GetLastWin32Error()); ++ Marshal.ThrowExceptionForHR(Marshal.GetLastWin32Error())!; + + // convert to 100ns to milliseconds, and truncate to 32 bits. + return (int)(uint)(time100ns / 10000); + } + else + { + return Environment.TickCount; + } + } + } + } + } diff --cc src/System.Private.CoreLib/src/System/Reflection/Assembly.CoreCLR.cs index 9335713,42736a9..fd8420d --- a/src/System.Private.CoreLib/src/System/Reflection/Assembly.CoreCLR.cs +++ b/src/System.Private.CoreLib/src/System/Reflection/Assembly.CoreCLR.cs @@@ -35,9 -38,9 +35,9 @@@ namespace System.Reflectio // Locate an assembly by its name. The name can be strong or // weak. The assembly is loaded into the domain of the caller. - internal static Assembly Load(AssemblyName assemblyRef, ref StackCrawlMark stackMark, IntPtr ptrLoadContextBinder) + internal static Assembly Load(AssemblyName assemblyRef, ref StackCrawlMark stackMark, AssemblyLoadContext assemblyLoadContext) { - AssemblyName modifiedAssemblyRef = null; + AssemblyName? modifiedAssemblyRef = null; if (assemblyRef.CodeBase != null) { modifiedAssemblyRef = (AssemblyName)assemblyRef.Clone(); diff --cc src/System.Private.CoreLib/src/System/Reflection/AssemblyName.CoreCLR.cs index 0000000,1f1c6f0..7b6e5b9 mode 000000,100644..100644 --- a/src/System.Private.CoreLib/src/System/Reflection/AssemblyName.CoreCLR.cs +++ b/src/System.Private.CoreLib/src/System/Reflection/AssemblyName.CoreCLR.cs @@@ -1,0 -1,111 +1,112 @@@ + // 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. + ++#nullable enable + using System.Configuration.Assemblies; + using System.Globalization; + using System.IO; + using System.Runtime.CompilerServices; + using System.Runtime.Serialization; + + namespace System.Reflection + { + public sealed partial class AssemblyName : ICloneable, IDeserializationCallback, ISerializable + { + public AssemblyName(string assemblyName) + { + if (assemblyName == null) + throw new ArgumentNullException(nameof(assemblyName)); + if ((assemblyName.Length == 0) || + (assemblyName[0] == '\0')) + throw new ArgumentException(SR.Format_StringZeroLength); + + _name = assemblyName; + nInit(out RuntimeAssembly dummy, false); + } + - internal AssemblyName(string name, - byte[] publicKey, - byte[] publicKeyToken, - Version version, - CultureInfo cultureInfo, ++ internal AssemblyName(string? name, ++ byte[]? publicKey, ++ byte[]? publicKeyToken, ++ Version? version, ++ CultureInfo? cultureInfo, + AssemblyHashAlgorithm hashAlgorithm, + AssemblyVersionCompatibility versionCompatibility, - string codeBase, ++ string? codeBase, + AssemblyNameFlags flags, - StrongNameKeyPair keyPair) // Null if ref, matching Assembly if def ++ StrongNameKeyPair? keyPair) // Null if ref, matching Assembly if def + { + _name = name; + _publicKey = publicKey; + _publicKeyToken = publicKeyToken; + _version = version; + _cultureInfo = cultureInfo; + _hashAlgorithm = hashAlgorithm; + _versionCompatibility = versionCompatibility; + _codeBase = codeBase; + _flags = flags; + _strongNameKeyPair = keyPair; + } + + [MethodImpl(MethodImplOptions.InternalCall)] - internal extern void nInit(out RuntimeAssembly assembly, bool raiseResolveEvent); ++ internal extern void nInit(out RuntimeAssembly? assembly, bool raiseResolveEvent); + + // This call opens and closes the file, but does not add the + // assembly to the domain. + [MethodImpl(MethodImplOptions.InternalCall)] + internal static extern AssemblyName nGetFileInformation(string s); + + internal static AssemblyName GetFileInformationCore(string assemblyFile) + { + string fullPath = Path.GetFullPath(assemblyFile); + return nGetFileInformation(fullPath); + } + + [MethodImpl(MethodImplOptions.InternalCall)] + private extern byte[] ComputePublicKeyToken(); + + internal void SetProcArchIndex(PortableExecutableKinds pek, ImageFileMachine ifm) + { + ProcessorArchitecture = CalculateProcArchIndex(pek, ifm, _flags); + } + + internal static ProcessorArchitecture CalculateProcArchIndex(PortableExecutableKinds pek, ImageFileMachine ifm, AssemblyNameFlags flags) + { + if (((uint)flags & 0xF0) == 0x70) + return ProcessorArchitecture.None; + + if ((pek & PortableExecutableKinds.PE32Plus) == PortableExecutableKinds.PE32Plus) + { + switch (ifm) + { + case ImageFileMachine.IA64: + return ProcessorArchitecture.IA64; + case ImageFileMachine.AMD64: + return ProcessorArchitecture.Amd64; + case ImageFileMachine.I386: + if ((pek & PortableExecutableKinds.ILOnly) == PortableExecutableKinds.ILOnly) + return ProcessorArchitecture.MSIL; + break; + } + } + else + { + if (ifm == ImageFileMachine.I386) + { + if ((pek & PortableExecutableKinds.Required32Bit) == PortableExecutableKinds.Required32Bit) + return ProcessorArchitecture.X86; + + if ((pek & PortableExecutableKinds.ILOnly) == PortableExecutableKinds.ILOnly) + return ProcessorArchitecture.MSIL; + + return ProcessorArchitecture.X86; + } + if (ifm == ImageFileMachine.ARM) + { + return ProcessorArchitecture.Arm; + } + } + return ProcessorArchitecture.None; + } + } + } diff --cc src/System.Private.CoreLib/src/System/Reflection/RuntimeAssembly.cs index 0720ae9,64622f5..a2c7b8e --- a/src/System.Private.CoreLib/src/System/Reflection/RuntimeAssembly.cs +++ b/src/System.Private.CoreLib/src/System/Reflection/RuntimeAssembly.cs @@@ -6,9 -5,12 +6,10 @@@ using System.Collections.Generic; using System.Diagnostics; using CultureInfo = System.Globalization.CultureInfo; -using System.Security; using System.IO; -using StringBuilder = System.Text.StringBuilder; using System.Configuration.Assemblies; using StackCrawlMark = System.Threading.StackCrawlMark; + using System.Runtime.Loader; using System.Runtime.InteropServices; using System.Runtime.CompilerServices; using System.Runtime.Serialization; @@@ -85,11 -87,9 +86,9 @@@ namespace System.Reflectio // is returned. public override AssemblyName GetName(bool copiedName) { - AssemblyName an = new AssemblyName(); - - string codeBase = GetCodeBase(copiedName); + string? codeBase = GetCodeBase(copiedName); - an.Init(GetSimpleName(), + var an = new AssemblyName(GetSimpleName(), GetPublicKey(), null, // public key token GetVersion(), @@@ -150,21 -150,30 +149,30 @@@ [DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)] private static extern void GetType(RuntimeAssembly assembly, - string name, - bool throwOnError, - bool ignoreCase, - ObjectHandleOnStack type, - ObjectHandleOnStack keepAlive); + string name, + bool throwOnError, + bool ignoreCase, + ObjectHandleOnStack type, + ObjectHandleOnStack keepAlive, + ObjectHandleOnStack assemblyLoadContext); - public override Type GetType(string name, bool throwOnError, bool ignoreCase) + public override Type? GetType(string name, bool throwOnError, bool ignoreCase) { // throw on null strings regardless of the value of "throwOnError" if (name == null) throw new ArgumentNullException(nameof(name)); - RuntimeType type = null; - object keepAlive = null; + RuntimeType? type = null; + object? keepAlive = null; - GetType(GetNativeHandle(), name, throwOnError, ignoreCase, JitHelpers.GetObjectHandleOnStack(ref type), JitHelpers.GetObjectHandleOnStack(ref keepAlive)); + AssemblyLoadContext assemblyLoadContextStack = AssemblyLoadContext.CurrentContextualReflectionContext; + + GetType(GetNativeHandle(), + name, + throwOnError, + ignoreCase, + JitHelpers.GetObjectHandleOnStack(ref type), + JitHelpers.GetObjectHandleOnStack(ref keepAlive), + JitHelpers.GetObjectHandleOnStack(ref assemblyLoadContextStack)); GC.KeepAlive(keepAlive); return type; @@@ -294,9 -303,9 +302,9 @@@ return CustomAttributeData.GetCustomAttributesInternal(this); } - internal static RuntimeAssembly InternalLoad(string assemblyString, ref StackCrawlMark stackMark) + internal static RuntimeAssembly InternalLoad(string assemblyString, ref StackCrawlMark stackMark, AssemblyLoadContext assemblyLoadContext = null) { - RuntimeAssembly assembly; + RuntimeAssembly? assembly; AssemblyName an = CreateAssemblyName(assemblyString, out assembly); if (assembly != null) @@@ -347,18 -356,18 +355,18 @@@ assemblyRef.ProcessorArchitecture = ProcessorArchitecture.None; } - string codeBase = VerifyCodeBase(assemblyRef.CodeBase); + string? codeBase = VerifyCodeBase(assemblyRef.CodeBase); - return nLoad(assemblyRef, codeBase, null, ref stackMark, true, ptrLoadContextBinder); + return nLoad(assemblyRef, codeBase, null, ref stackMark, true, assemblyLoadContext); } [MethodImplAttribute(MethodImplOptions.InternalCall)] private static extern RuntimeAssembly nLoad(AssemblyName fileName, - string codeBase, - RuntimeAssembly assemblyContext, + string? codeBase, + RuntimeAssembly? assemblyContext, ref StackCrawlMark stackMark, bool throwOnFileNotFound, - IntPtr ptrLoadContextBinder); + AssemblyLoadContext assemblyLoadContext = null); public override bool ReflectionOnly { @@@ -648,7 -657,7 +656,7 @@@ // This stack crawl mark is never used because the requesting assembly is explicitly specified, // so the value could be anything. StackCrawlMark unused = default; - RuntimeAssembly? retAssembly = nLoad(an, null, this, ref unused, throwOnFileNotFound, IntPtr.Zero); - RuntimeAssembly retAssembly = nLoad(an, null, this, ref unused, throwOnFileNotFound); ++ RuntimeAssembly? retAssembly = nLoad(an, null, this, ref unused, throwOnFileNotFound); if (retAssembly == this) { diff --cc src/System.Private.CoreLib/src/System/Runtime/Loader/AssemblyLoadContext.CoreCLR.cs index 065ff40,c95043b..73511d3 --- a/src/System.Private.CoreLib/src/System/Runtime/Loader/AssemblyLoadContext.CoreCLR.cs +++ b/src/System.Private.CoreLib/src/System/Runtime/Loader/AssemblyLoadContext.CoreCLR.cs @@@ -101,11 -100,11 +101,11 @@@ namespace System.Runtime.Loade return context.ResolveUsingEvent(assemblyName); } - private Assembly GetFirstResolvedAssembly(AssemblyName assemblyName) + private Assembly? GetFirstResolvedAssembly(AssemblyName assemblyName) { - Assembly resolvedAssembly = null; + Assembly? resolvedAssembly = null; - Func assemblyResolveHandler = Resolving; + Func assemblyResolveHandler = _resolving; if (assemblyResolveHandler != null) {