Imported Upstream version 4.0.0~alpha1

Former-commit-id: 806294f5ded97629b74c85c09952f2a74fe182d9
This commit is contained in:
Jo Shields
2015-04-07 09:35:12 +01:00
parent 283343f570
commit 3c1f479b9d
22469 changed files with 2931443 additions and 869343 deletions

View File

@@ -0,0 +1,66 @@
using System;
namespace System.Runtime
{
[AttributeUsage(AttributeTargets.Assembly, Inherited = false)]
public sealed class AssemblyTargetedPatchBandAttribute : Attribute
{
private String m_targetedPatchBand;
public AssemblyTargetedPatchBandAttribute(String targetedPatchBand)
{
m_targetedPatchBand = targetedPatchBand;
}
public String TargetedPatchBand
{
get { return m_targetedPatchBand; }
}
}
// This attribute seems particularly prone to accidental inclusion in bcl.small
// We would only want to do so intentionally (if targeted patching were enabled there)
#if !FEATURE_CORECLR
//============================================================================================================
// [TargetedPatchingOptOutAttribute("Performance critical to inline across NGen image boundaries")] -
// Sacrifices cheap servicing of a method body in order to allow unrestricted inlining. Certain types of
// trivial methods (e.g. simple property getters) are automatically attributed by ILCA.EXE during the build.
// For other performance critical methods, it should be added manually.
//============================================================================================================
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Constructor, AllowMultiple = false, Inherited = false)]
public sealed class TargetedPatchingOptOutAttribute : Attribute
{
private String m_reason;
public TargetedPatchingOptOutAttribute(String reason)
{
m_reason = reason;
}
public String Reason
{
get { return m_reason; }
}
private TargetedPatchingOptOutAttribute() { }
}
#endif
//============================================================================================================
// [ForceTokenStabilization] - Using this CA forces ILCA.EXE to stabilize the attached type, method or field.
// We use this to identify private helper methods invoked by IL stubs.
//
// NOTE: Attaching this to a type is NOT equivalent to attaching it to all of its methods!
//============================================================================================================
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Interface | AttributeTargets.Delegate |
AttributeTargets.Method | AttributeTargets.Constructor |
AttributeTargets.Field
, AllowMultiple = false, Inherited = false)]
sealed class ForceTokenStabilizationAttribute : Attribute
{
public ForceTokenStabilizationAttribute() { }
}
}

View File

@@ -0,0 +1,59 @@
// ==++==
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// ==--==
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
//
// RuntimeHelpers
// This class defines entry point for multi-core JIT API
//
// Date: Oct 2010
//
namespace System.Runtime {
using System;
using System.Reflection;
using System.Security;
using System.Security.Permissions;
using System.Runtime;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Runtime.CompilerServices;
#if FEATURE_MULTICOREJIT
public static class ProfileOptimization
{
[DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)]
[SecurityCritical]
[ResourceExposure(ResourceScope.None)]
[SuppressUnmanagedCodeSecurity]
internal static extern void InternalSetProfileRoot(string directoryPath);
[DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)]
[SecurityCritical]
[ResourceExposure(ResourceScope.None)]
[SuppressUnmanagedCodeSecurity]
internal static extern void InternalStartProfile(string profile);
[SecurityCritical]
public static void SetProfileRoot(string directoryPath)
{
InternalSetProfileRoot(directoryPath);
}
[SecurityCritical]
public static void StartProfile(string profile)
{
InternalStartProfile(profile);
}
}
#endif
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,19 @@
// ==++==
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// ==--==
using System;
namespace System.Runtime.CompilerServices
{
[Serializable, AttributeUsage(AttributeTargets.Method, Inherited = false, AllowMultiple = false)]
public sealed class AsyncStateMachineAttribute : StateMachineAttribute
{
public AsyncStateMachineAttribute(Type stateMachineType)
: base(stateMachineType)
{
}
}
}

View File

@@ -0,0 +1,18 @@
// ==++==
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// ==--==
using System;
namespace System.Runtime.CompilerServices
{
[AttributeUsage(AttributeTargets.Parameter, Inherited = false)]
public sealed class CallerFilePathAttribute : Attribute
{
public CallerFilePathAttribute()
{
}
}
}

View File

@@ -0,0 +1,18 @@
// ==++==
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// ==--==
using System;
namespace System.Runtime.CompilerServices
{
[AttributeUsage(AttributeTargets.Parameter, Inherited = false)]
public sealed class CallerLineNumberAttribute : Attribute
{
public CallerLineNumberAttribute()
{
}
}
}

View File

@@ -0,0 +1,18 @@
// ==++==
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// ==--==
using System;
namespace System.Runtime.CompilerServices
{
[AttributeUsage(AttributeTargets.Parameter, Inherited = false)]
public sealed class CallerMemberNameAttribute : Attribute
{
public CallerMemberNameAttribute()
{
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,30 @@
// ==++==
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// ==--==
// =+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
//
// IAsyncStateMachine.cs
//
// <OWNER>[....]</OWNER>
//
// Represents state machines generated for asynchronous methods.
//
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
namespace System.Runtime.CompilerServices
{
/// <summary>
/// Represents state machines generated for asynchronous methods.
/// This type is intended for compiler use only.
/// </summary>
public interface IAsyncStateMachine
{
/// <summary>Moves the state machine to its next state.</summary>
void MoveNext();
/// <summary>Configures the state machine with a heap-allocated replica.</summary>
/// <param name="stateMachine">The heap-allocated replica.</param>
void SetStateMachine(IAsyncStateMachine stateMachine);
}
}

View File

@@ -0,0 +1,43 @@
// ==++==
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// ==--==
// =+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=
//
// INotifyCompletion.cs
//
// <OWNER>[....]</OWNER>
//
// Interfaces used to represent instances that notify listeners of their completion via continuations.
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
using System;
using System.Security;
namespace System.Runtime.CompilerServices
{
/// <summary>
/// Represents an operation that will schedule continuations when the operation completes.
/// </summary>
public interface INotifyCompletion
{
/// <summary>Schedules the continuation action to be invoked when the instance completes.</summary>
/// <param name="continuation">The action to invoke when the operation completes.</param>
/// <exception cref="System.ArgumentNullException">The <paramref name="continuation"/> argument is null (Nothing in Visual Basic).</exception>
void OnCompleted(Action continuation);
}
/// <summary>
/// Represents an awaiter used to schedule continuations when an await operation completes.
/// </summary>
public interface ICriticalNotifyCompletion : INotifyCompletion
{
/// <summary>Schedules the continuation action to be invoked when the instance completes.</summary>
/// <param name="continuation">The action to invoke when the operation completes.</param>
/// <exception cref="System.ArgumentNullException">The <paramref name="continuation"/> argument is null (Nothing in Visual Basic).</exception>
/// <remarks>Unlike OnCompleted, UnsafeOnCompleted need not propagate ExecutionContext information.</remarks>
[SecurityCritical]
void UnsafeOnCompleted(Action continuation);
}
}

View File

@@ -0,0 +1,19 @@
// ==++==
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// ==--==
using System;
namespace System.Runtime.CompilerServices
{
[Serializable, AttributeUsage(AttributeTargets.Method, Inherited = false, AllowMultiple = false)]
public sealed class IteratorStateMachineAttribute : StateMachineAttribute
{
public IteratorStateMachineAttribute(Type stateMachineType)
: base(stateMachineType)
{
}
}
}

View File

@@ -0,0 +1,40 @@
// ==++==
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// ==--==
/*============================================================
**
** Attribute: ReferenceAssemblyAttribute
**
** Purpose: Identifies an assembly as being a "reference
** assembly", meaning it contains public surface area but
** no usable implementation. Reference assemblies
** should be loadable for introspection, but not execution.
**
============================================================*/
namespace System.Runtime.CompilerServices
{
using System;
[Serializable]
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple=false)]
public sealed class ReferenceAssemblyAttribute : Attribute
{
private String _description; // Maybe ".NET FX v4.0 SP1, partial trust"?
public ReferenceAssemblyAttribute()
{
}
public ReferenceAssemblyAttribute(String description)
{
_description = description;
}
public String Description
{
get { return _description; }
}
}
}

View File

@@ -0,0 +1,50 @@
// ==++==
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// ==--==
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
/*=============================================================================
**
** Class: RuntimeCompatibilityAttribute
**
**
** Purpose: Mark up the program to indicate various legacy or new opt-in behaviors.
**
**
=============================================================================*/
namespace System.Runtime.CompilerServices
{
using System;
[Serializable]
[AttributeUsage(AttributeTargets.Assembly, Inherited=false, AllowMultiple=false)]
public sealed class RuntimeCompatibilityAttribute : Attribute
{
// fields
private bool m_wrapNonExceptionThrows;
// constructors
public RuntimeCompatibilityAttribute() {
// legacy behavior is the default, and m_wrapNonExceptionThrows is implicitly
// false thanks to the CLR's guarantee of zeroed memory.
}
// properties
// If a non-CLSCompliant exception (i.e. one that doesn't derive from System.Exception) is
// thrown, should it be wrapped up in a System.Runtime.CompilerServices.RuntimeWrappedException
// instance when presented to catch handlers?
public bool WrapNonExceptionThrows {
get {
return m_wrapNonExceptionThrows;
}
set {
m_wrapNonExceptionThrows = value;
}
}
}
}

View File

@@ -0,0 +1,54 @@
// ==++==
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// ==--==
/*=============================================================================
**
** Class: RuntimeWrappedException
**
**
** Purpose: The exception class uses to wrap all non-CLS compliant exceptions.
**
**
=============================================================================*/
namespace System.Runtime.CompilerServices {
using System;
using System.Runtime.Serialization;
using System.Runtime.Remoting;
using System.Security.Permissions;
using System.Diagnostics.Contracts;
[Serializable]
public sealed class RuntimeWrappedException : Exception
{
private RuntimeWrappedException(Object thrownObject)
: base(Environment.GetResourceString("RuntimeWrappedException")) {
SetErrorCode(System.__HResults.COR_E_RUNTIMEWRAPPED);
m_wrappedException = thrownObject;
}
public Object WrappedException {
get { return m_wrappedException; }
}
private Object m_wrappedException;
[System.Security.SecurityCritical] // auto-generated_required
public override void GetObjectData(SerializationInfo info, StreamingContext context) {
if (info==null) {
throw new ArgumentNullException("info");
}
Contract.EndContractBlock();
base.GetObjectData(info, context);
info.AddValue("WrappedException", m_wrappedException, typeof(Object));
}
internal RuntimeWrappedException(SerializationInfo info, StreamingContext context)
: base(info, context) {
m_wrappedException = info.GetValue("WrappedException", typeof(Object));
}
}
}

View File

@@ -0,0 +1,21 @@
// ==++==
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// ==--==
using System;
namespace System.Runtime.CompilerServices
{
[Serializable, AttributeUsage(AttributeTargets.Method, Inherited = false, AllowMultiple = false)]
public class StateMachineAttribute : Attribute
{
public Type StateMachineType { get; private set; }
public StateMachineAttribute(Type stateMachineType)
{
this.StateMachineType = stateMachineType;
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,36 @@
// ==++==
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// ==--==
namespace System.Runtime.CompilerServices
{
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Enum | AttributeTargets.Interface | AttributeTargets.Delegate, Inherited = false, AllowMultiple = false)]
public sealed class TypeForwardedFromAttribute : Attribute
{
string assemblyFullName;
private TypeForwardedFromAttribute()
{
// Disallow default constructor
}
public TypeForwardedFromAttribute(string assemblyFullName)
{
if (String.IsNullOrEmpty(assemblyFullName))
{
throw new ArgumentNullException("assemblyFullName");
}
this.assemblyFullName = assemblyFullName;
}
public string AssemblyFullName
{
get {
return assemblyFullName;
}
}
}
}

View File

@@ -0,0 +1,48 @@
// ==++==
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// ==--==
using System;
using System.Reflection;
namespace System.Runtime.CompilerServices
{
using System;
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple=true, Inherited=false)]
public sealed class TypeForwardedToAttribute : Attribute
{
private Type _destination;
public TypeForwardedToAttribute(Type destination)
{
_destination = destination;
}
public Type Destination
{
get {
return _destination;
}
}
#if false
[System.Security.SecurityCritical]
internal static TypeForwardedToAttribute[] GetCustomAttribute(RuntimeAssembly assembly)
{
Type[] types = null;
RuntimeAssembly.GetForwardedTypes(assembly.GetNativeHandle(), JitHelpers.GetObjectHandleOnStack(ref types));
TypeForwardedToAttribute[] attributes = new TypeForwardedToAttribute[types.Length];
for (int i = 0; i < types.Length; ++i)
attributes[i] = new TypeForwardedToAttribute(types[i]);
return attributes;
}
#endif
}
}

View File

@@ -0,0 +1,166 @@
// ==++==
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// ==--==
// =+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
//
// YieldAwaitable.cs
//
// <OWNER>[....]</OWNER>
//
// Compiler-targeted type for switching back into the current execution context, e.g.
//
// await Task.Yield();
// =====================
// var $awaiter = Task.Yield().GetAwaiter();
// if (!$awaiter.IsCompleted)
// {
// $builder.AwaitUnsafeOnCompleted(ref $awaiter, ref this);
// return;
// Label:
// }
// $awaiter.GetResult();
//
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
using System;
using System.Security;
using System.Diagnostics;
using System.Diagnostics.Contracts;
using System.Diagnostics.Tracing;
using System.Threading;
using System.Threading.Tasks;
using System.Security.Permissions;
namespace System.Runtime.CompilerServices
{
// NOTE: YieldAwaitable currently has no state; while developers are encouraged to use Task.Yield() to produce one,
// no validation is performed to ensure that the developer isn't doing "await new YieldAwaitable()". Such validation
// would require additional, useless state to be stored, and as this is a type in the CompilerServices namespace, and
// as the above example isn't harmful, we take the cheaper approach of not validating anything.
/// <summary>Provides an awaitable context for switching into a target environment.</summary>
/// <remarks>This type is intended for compiler use only.</remarks>
public struct YieldAwaitable
{
/// <summary>Gets an awaiter for this <see cref="YieldAwaitable"/>.</summary>
/// <returns>An awaiter for this awaitable.</returns>
/// <remarks>This method is intended for compiler user rather than use directly in code.</remarks>
public YieldAwaiter GetAwaiter() { return new YieldAwaiter(); }
/// <summary>Provides an awaiter that switches into a target environment.</summary>
/// <remarks>This type is intended for compiler use only.</remarks>
[HostProtection(Synchronization = true, ExternalThreading = true)]
public struct YieldAwaiter : ICriticalNotifyCompletion
{
/// <summary>Gets whether a yield is not required.</summary>
/// <remarks>This property is intended for compiler user rather than use directly in code.</remarks>
public bool IsCompleted { get { return false; } } // yielding is always required for YieldAwaiter, hence false
/// <summary>Posts the <paramref name="continuation"/> back to the current context.</summary>
/// <param name="continuation">The action to invoke asynchronously.</param>
/// <exception cref="System.ArgumentNullException">The <paramref name="continuation"/> argument is null (Nothing in Visual Basic).</exception>
[SecuritySafeCritical]
public void OnCompleted(Action continuation)
{
QueueContinuation(continuation, flowContext: true);
}
/// <summary>Posts the <paramref name="continuation"/> back to the current context.</summary>
/// <param name="continuation">The action to invoke asynchronously.</param>
/// <exception cref="System.ArgumentNullException">The <paramref name="continuation"/> argument is null (Nothing in Visual Basic).</exception>
[SecurityCritical]
public void UnsafeOnCompleted(Action continuation)
{
QueueContinuation(continuation, flowContext: false);
}
/// <summary>Posts the <paramref name="continuation"/> back to the current context.</summary>
/// <param name="continuation">The action to invoke asynchronously.</param>
/// <param name="flowContext">true to flow ExecutionContext; false if flowing is not required.</param>
/// <exception cref="System.ArgumentNullException">The <paramref name="continuation"/> argument is null (Nothing in Visual Basic).</exception>
[SecurityCritical]
private static void QueueContinuation(Action continuation, bool flowContext)
{
// Validate arguments
if (continuation == null) throw new ArgumentNullException("continuation");
Contract.EndContractBlock();
#if !FEATURE_PAL && !FEATURE_CORECLR // PAL and CoreClr don't support eventing
if (TplEtwProvider.Log.IsEnabled())
{
continuation = OutputCorrelationEtwEvent(continuation);
}
#endif
// Get the current SynchronizationContext, and if there is one,
// post the continuation to it. However, treat the base type
// as if there wasn't a SynchronizationContext, since that's what it
// logically represents.
var syncCtx = SynchronizationContext.CurrentNoFlow;
if (syncCtx != null && syncCtx.GetType() != typeof(SynchronizationContext))
{
syncCtx.Post(s_sendOrPostCallbackRunAction, continuation);
}
else
{
// If we're targeting the default scheduler, queue to the thread pool, so that we go into the global
// queue. As we're going into the global queue, we might as well use QUWI, which for the global queue is
// just a tad faster than task, due to a smaller object getting allocated and less work on the execution path.
TaskScheduler scheduler = TaskScheduler.Current;
if (scheduler == TaskScheduler.Default)
{
if (flowContext)
{
ThreadPool.QueueUserWorkItem(s_waitCallbackRunAction, continuation);
}
else
{
ThreadPool.UnsafeQueueUserWorkItem(s_waitCallbackRunAction, continuation);
}
}
// We're targeting a custom scheduler, so queue a task.
else
{
Task.Factory.StartNew(continuation, default(CancellationToken), TaskCreationOptions.PreferFairness, scheduler);
}
}
}
#if !FEATURE_PAL && !FEATURE_CORECLR // PAL and CoreClr don't support eventing
private static Action OutputCorrelationEtwEvent(Action continuation)
{
int continuationId = Task.NewId();
Task currentTask = Task.InternalCurrent;
// fire the correlation ETW event
TplEtwProvider.Log.AwaitTaskContinuationScheduled(TaskScheduler.Current.Id, (currentTask != null) ? currentTask.Id : 0, continuationId);
return AsyncMethodBuilderCore.CreateContinuationWrapper(continuation, () =>
{
// ETW event for Task Wait End.
Guid prevActivityId = new Guid();
// Ensure the continuation runs under the correlated activity ID generated above
EventSource.SetCurrentThreadActivityId(TplEtwProvider.CreateGuidForTaskID(continuationId), out prevActivityId);
// Invoke the original continuation provided to OnCompleted.
continuation();
// Restore activity ID
EventSource.SetCurrentThreadActivityId(prevActivityId);
});
}
#endif
/// <summary>WaitCallback that invokes the Action supplied as object state.</summary>
private static readonly WaitCallback s_waitCallbackRunAction = RunAction;
/// <summary>SendOrPostCallback that invokes the Action supplied as object state.</summary>
private static readonly SendOrPostCallback s_sendOrPostCallbackRunAction = RunAction;
/// <summary>Runs an Action delegate provided as state.</summary>
/// <param name="state">The Action delegate to invoke.</param>
private static void RunAction(object state) { ((Action)state)(); }
/// <summary>Ends the await operation.</summary>
public void GetResult() {} // Nop. It exists purely because the compiler pattern demands it.
}
}
}

View File

@@ -0,0 +1,32 @@
// ==++==
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// ==--==
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
namespace System.Runtime.CompilerServices
{
using System;
[AttributeUsage(AttributeTargets.Field)]
[System.Runtime.InteropServices.ComVisible(true)]
public sealed class AccessedThroughPropertyAttribute : Attribute
{
private readonly string propertyName;
public AccessedThroughPropertyAttribute(string propertyName)
{
this.propertyName = propertyName;
}
public string PropertyName
{
get
{
return propertyName;
}
}
}
}

Some files were not shown because too many files have changed in this diff Show More