You've already forked linux-packaging-mono
acceptance-tests
data
debian
docs
external
ikvm-native
libgc
llvm
m4
man
mcs
build
class
Accessibility
Commons.Xml.Relaxng
Cscompmgd
CustomMarshalers
Facades
I18N
IBM.Data.DB2
ICSharpCode.SharpZipLib
Microsoft.Build
Microsoft.Build.Engine
Microsoft.Build.Framework
Microsoft.Build.Tasks
Microsoft.Build.Utilities
Microsoft.CSharp
Microsoft.NuGet.Build.Tasks
Microsoft.VisualC
Microsoft.Web.Infrastructure
MicrosoftAjaxLibrary
Mono.Btls.Interface
Mono.C5
Mono.CSharp
Mono.Cairo
Mono.Cecil
Mono.Cecil.Mdb
Mono.CodeContracts
Mono.CompilerServices.SymbolWriter
Mono.Data.Sqlite
Mono.Data.Tds
Mono.Debugger.Soft
Mono.Http
Mono.Management
Mono.Messaging
Mono.Messaging.RabbitMQ
Mono.Options
Mono.Parallel
Mono.Posix
Mono.Profiler.Log
Mono.Runtime.Tests
Mono.Security
Mono.Security.Win32
Mono.Simd
Mono.Tasklets
Mono.WebBrowser
Mono.XBuild.Tasks
Novell.Directory.Ldap
PEAPI
RabbitMQ.Client
SMDiagnostics
System
System.ComponentModel.Composition.4.5
System.ComponentModel.DataAnnotations
System.Configuration
System.Configuration.Install
System.Core
System.Data
System.Data.DataSetExtensions
System.Data.Entity
System.Data.Linq
System.Data.OracleClient
System.Data.Services
System.Data.Services.Client
System.Deployment
System.Design
System.DirectoryServices
System.DirectoryServices.Protocols
System.Drawing
System.Drawing.Design
System.Dynamic
System.EnterpriseServices
System.IO.Compression
System.IO.Compression.FileSystem
System.IdentityModel
System.IdentityModel.Selectors
System.Json
System.Json.Microsoft
System.Management
System.Messaging
System.Net
System.Net.Http
System.Net.Http.Formatting
System.Net.Http.WebRequest
System.Net.Http.WinHttpHandler
System.Numerics
System.Numerics.Vectors
System.Reactive.Core
System.Reactive.Debugger
System.Reactive.Experimental
System.Reactive.Interfaces
System.Reactive.Linq
System.Reactive.Observable.Aliases
System.Reactive.PlatformServices
System.Reactive.Providers
System.Reactive.Runtime.Remoting
System.Reactive.Windows.Forms
System.Reactive.Windows.Threading
System.Reflection.Context
System.Runtime.Caching
System.Runtime.CompilerServices.Unsafe
System.Runtime.DurableInstancing
System.Runtime.Remoting
System.Runtime.Serialization
System.Runtime.Serialization.Formatters.Soap
System.Security
System.ServiceModel
System.ServiceModel.Activation
System.ServiceModel.Discovery
System.ServiceModel.Internals
System.ServiceModel.Routing
System.ServiceModel.Web
System.ServiceProcess
System.Threading.Tasks.Dataflow
System.Transactions
System.Web
System.Web.Abstractions
System.Web.ApplicationServices
System.Web.DynamicData
System.Web.Extensions
System.Web.Extensions.Design
System.Web.Http
System.Web.Http.SelfHost
System.Web.Http.WebHost
System.Web.Mobile
System.Web.Mvc3
System.Web.Razor
System.Web.RegularExpressions
System.Web.Routing
System.Web.Services
System.Web.WebPages
System.Web.WebPages.Deployment
System.Web.WebPages.Razor
System.Windows
System.Windows.Forms
System.Windows.Forms.DataVisualization
System.Workflow.Activities
System.Workflow.ComponentModel
System.Workflow.Runtime
System.XML
System.Xaml
System.Xml.Linq
System.Xml.Serialization
SystemWebTestShim
WebMatrix.Data
WindowsBase
aot-compiler
corlib
dlr
doc
legacy
lib
monodoc
notes
reference-assemblies
referencesource
SMDiagnostics
System
System.Activities
System.Activities.Core.Presentation
System.Activities.DurableInstancing
System.Activities.Presentation
System.ComponentModel.DataAnnotations
System.Configuration
System.Core
System.Data
System.Data.DataSetExtensions
System.Data.Entity
System.Data.Entity.Design
System.Data.Linq
System.Data.SqlXml
System.IdentityModel
System.IdentityModel.Selectors
System.Net
System.Numerics
System.Runtime.Caching
System.Runtime.DurableInstancing
System.Runtime.Serialization
System.ServiceModel
System.ServiceModel.Activation
System.ServiceModel.Activities
System.ServiceModel.Channels
System.ServiceModel.Discovery
System.ServiceModel.Internals
System
Runtime
Collections
Diagnostics
Interop
ActionItem.cs
AssertHelper.cs
AsyncCompletionResult.cs
AsyncEventArgs.cs
AsyncEventArgsCallback.cs
AsyncResult.cs
AsyncWaitHandle.cs
BackoffTimeoutHelper.cs
BufferedOutputStream.cs
CallbackException.cs
CompletedAsyncResult.cs
ComputerNameFormat.cs
DiagnosticStrings.cs
DuplicateDetector.cs
ExceptionTrace.cs
FastAsyncCallback.cs
FatalException.cs
Fx.cs
FxCop.cs
HashHelper.cs
IAsyncEventArgs.cs
IOThreadCancellationTokenSource.cs
IOThreadScheduler.cs
IOThreadTimer.cs
InputQueue.cs
InternalBufferManager.cs
MruCache.cs
NameGenerator.cs
PartialTrustHelpers.cs
ReadOnlyDictionaryInternal.cs
ReadOnlyKeyedCollection.cs
ScheduleActionItemAsyncResult.cs
SignalGate.cs
SynchronizedPool.cs
TaskExtensions.cs
ThreadNeutralSemaphore.cs
Ticks.cs
TimeoutHelper.cs
TraceChannel.cs
TraceEventLevel.cs
TraceEventOpcode.cs
TraceLevelHelper.cs
TracePayload.cs
TypeHelper.cs
TypedAsyncResult.cs
UrlUtility.cs
WaitCallbackActionItem.cs
AssemblyInfo.cs
TraceCore.Designer.cs
System.ServiceModel.Routing
System.ServiceModel.WasHosting
System.ServiceModel.Web
System.Web
System.Web.ApplicationServices
System.Web.DataVisualization
System.Web.DynamicData
System.Web.Entity
System.Web.Entity.Design
System.Web.Extensions
System.Web.Mobile
System.Web.Routing
System.Web.Services
System.Workflow.Activities
System.Workflow.ComponentModel
System.Workflow.Runtime
System.WorkflowServices
System.Xaml.Hosting
System.Xml
System.Xml.Linq
XamlBuildTask
mscorlib
LICENSE.txt
PATENTS.TXT
README.Mono.md
README.md
test-helpers
LICENSE
Makefile
Open.snk
README
ecma.pub
mono.pub
mono.snk
msfinal.pub
reactive.pub
silverlight.pub
winfx.pub
winfx3.pub
docs
errors
ilasm
jay
mcs
nunit24
packages
tests
tools
AUTHORS
COPYING
INSTALL.txt
Makefile
MonoIcon.png
README
ScalableMonoIcon.svg
mkinstalldirs
mk
mono
msvc
po
runtime
samples
scripts
support
tools
COPYING.LIB
LICENSE
Makefile.am
Makefile.in
NEWS
README.md
acinclude.m4
aclocal.m4
autogen.sh
code_of_conduct.md
compile
config.guess
config.h.in
config.rpath
config.sub
configure.REMOVED.git-id
configure.ac.REMOVED.git-id
depcomp
install-sh
ltmain.sh.REMOVED.git-id
missing
mkinstalldirs
mono-uninstalled.pc.in
test-driver
winconfig.h
344 lines
13 KiB
C#
344 lines
13 KiB
C#
![]() |
//------------------------------------------------------------
|
||
|
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||
|
//------------------------------------------------------------
|
||
|
|
||
|
namespace System.Runtime
|
||
|
{
|
||
|
using System.Diagnostics;
|
||
|
using System.Runtime.Diagnostics;
|
||
|
using System.Security;
|
||
|
using System.Threading;
|
||
|
|
||
|
abstract class ActionItem
|
||
|
{
|
||
|
#if FEATURE_COMPRESSEDSTACK
|
||
|
[Fx.Tag.SecurityNote(Critical = "Stores the security context, used later in binding back into")]
|
||
|
[SecurityCritical]
|
||
|
SecurityContext context;
|
||
|
#endif
|
||
|
bool isScheduled;
|
||
|
|
||
|
bool lowPriority;
|
||
|
|
||
|
protected ActionItem()
|
||
|
{
|
||
|
}
|
||
|
|
||
|
public bool LowPriority
|
||
|
{
|
||
|
get
|
||
|
{
|
||
|
return this.lowPriority;
|
||
|
}
|
||
|
protected set
|
||
|
{
|
||
|
this.lowPriority = value;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public static void Schedule(Action<object> callback, object state)
|
||
|
{
|
||
|
Schedule(callback, state, false);
|
||
|
}
|
||
|
[Fx.Tag.SecurityNote(Critical = "Calls into critical method ScheduleCallback",
|
||
|
Safe = "Schedule invoke of the given delegate under the current context")]
|
||
|
[SecuritySafeCritical]
|
||
|
public static void Schedule(Action<object> callback, object state, bool lowPriority)
|
||
|
{
|
||
|
Fx.Assert(callback != null, "A null callback was passed for Schedule!");
|
||
|
|
||
|
if (PartialTrustHelpers.ShouldFlowSecurityContext ||
|
||
|
WaitCallbackActionItem.ShouldUseActivity ||
|
||
|
Fx.Trace.IsEnd2EndActivityTracingEnabled)
|
||
|
{
|
||
|
new DefaultActionItem(callback, state, lowPriority).Schedule();
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
ScheduleCallback(callback, state, lowPriority);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
[Fx.Tag.SecurityNote(Critical = "Called after applying the user context on the stack or (potentially) " +
|
||
|
"without any user context on the stack")]
|
||
|
[SecurityCritical]
|
||
|
protected abstract void Invoke();
|
||
|
|
||
|
[Fx.Tag.SecurityNote(Critical = "Access critical field context and critical property " +
|
||
|
"CallbackHelper.InvokeWithContextCallback, calls into critical method " +
|
||
|
"PartialTrustHelpers.CaptureSecurityContextNoIdentityFlow, calls into critical method ScheduleCallback; " +
|
||
|
"since the invoked method and the capturing of the security contex are de-coupled, can't " +
|
||
|
"be treated as safe")]
|
||
|
[SecurityCritical]
|
||
|
protected void Schedule()
|
||
|
{
|
||
|
if (isScheduled)
|
||
|
{
|
||
|
throw Fx.Exception.AsError(new InvalidOperationException(InternalSR.ActionItemIsAlreadyScheduled));
|
||
|
}
|
||
|
|
||
|
this.isScheduled = true;
|
||
|
#if FEATURE_COMPRESSEDSTACK
|
||
|
if (PartialTrustHelpers.ShouldFlowSecurityContext)
|
||
|
{
|
||
|
this.context = PartialTrustHelpers.CaptureSecurityContextNoIdentityFlow();
|
||
|
}
|
||
|
if (this.context != null)
|
||
|
{
|
||
|
ScheduleCallback(CallbackHelper.InvokeWithContextCallback);
|
||
|
}
|
||
|
else
|
||
|
#endif
|
||
|
{
|
||
|
ScheduleCallback(CallbackHelper.InvokeWithoutContextCallback);
|
||
|
}
|
||
|
}
|
||
|
#if FEATURE_COMPRESSEDSTACK
|
||
|
[Fx.Tag.SecurityNote(Critical = "Access critical field context and critical property " +
|
||
|
"CallbackHelper.InvokeWithContextCallback, calls into critical method ScheduleCallback; " +
|
||
|
"since nothing is known about the given context, can't be treated as safe")]
|
||
|
[SecurityCritical]
|
||
|
protected void ScheduleWithContext(SecurityContext context)
|
||
|
{
|
||
|
if (context == null)
|
||
|
{
|
||
|
throw Fx.Exception.ArgumentNull("context");
|
||
|
}
|
||
|
if (isScheduled)
|
||
|
{
|
||
|
throw Fx.Exception.AsError(new InvalidOperationException(InternalSR.ActionItemIsAlreadyScheduled));
|
||
|
}
|
||
|
|
||
|
this.isScheduled = true;
|
||
|
this.context = context.CreateCopy();
|
||
|
ScheduleCallback(CallbackHelper.InvokeWithContextCallback);
|
||
|
}
|
||
|
#endif
|
||
|
|
||
|
[Fx.Tag.SecurityNote(Critical = "Access critical property CallbackHelper.InvokeWithoutContextCallback, " +
|
||
|
"Calls into critical method ScheduleCallback; not bound to a security context")]
|
||
|
[SecurityCritical]
|
||
|
protected void ScheduleWithoutContext()
|
||
|
{
|
||
|
if (isScheduled)
|
||
|
{
|
||
|
throw Fx.Exception.AsError(new InvalidOperationException(InternalSR.ActionItemIsAlreadyScheduled));
|
||
|
}
|
||
|
|
||
|
this.isScheduled = true;
|
||
|
ScheduleCallback(CallbackHelper.InvokeWithoutContextCallback);
|
||
|
}
|
||
|
|
||
|
[Fx.Tag.SecurityNote(Critical = "Calls into critical methods IOThreadScheduler.ScheduleCallbackNoFlow, " +
|
||
|
"IOThreadScheduler.ScheduleCallbackLowPriNoFlow")]
|
||
|
[SecurityCritical]
|
||
|
static void ScheduleCallback(Action<object> callback, object state, bool lowPriority)
|
||
|
{
|
||
|
Fx.Assert(callback != null, "Cannot schedule a null callback");
|
||
|
if (lowPriority)
|
||
|
{
|
||
|
IOThreadScheduler.ScheduleCallbackLowPriNoFlow(callback, state);
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
IOThreadScheduler.ScheduleCallbackNoFlow(callback, state);
|
||
|
}
|
||
|
}
|
||
|
#if FEATURE_COMPRESSEDSTACK
|
||
|
[Fx.Tag.SecurityNote(Critical = "Extract the security context stored and reset the critical field")]
|
||
|
[SecurityCritical]
|
||
|
SecurityContext ExtractContext()
|
||
|
{
|
||
|
Fx.Assert(this.context != null, "Cannot bind to a null context; context should have been set by now");
|
||
|
Fx.Assert(this.isScheduled, "Context is extracted only while the object is scheduled");
|
||
|
SecurityContext result = this.context;
|
||
|
this.context = null;
|
||
|
return result;
|
||
|
}
|
||
|
#endif
|
||
|
[Fx.Tag.SecurityNote(Critical = "Calls into critical static method ScheduleCallback")]
|
||
|
[SecurityCritical]
|
||
|
void ScheduleCallback(Action<object> callback)
|
||
|
{
|
||
|
ScheduleCallback(callback, this, this.lowPriority);
|
||
|
}
|
||
|
|
||
|
[SecurityCritical]
|
||
|
static class CallbackHelper
|
||
|
{
|
||
|
#if FEATURE_COMPRESSEDSTACK
|
||
|
[Fx.Tag.SecurityNote(Critical = "Stores a delegate to a critical method")]
|
||
|
static Action<object> invokeWithContextCallback;
|
||
|
#endif
|
||
|
[Fx.Tag.SecurityNote(Critical = "Stores a delegate to a critical method")]
|
||
|
static Action<object> invokeWithoutContextCallback;
|
||
|
[Fx.Tag.SecurityNote(Critical = "Stores a delegate to a critical method")]
|
||
|
static ContextCallback onContextAppliedCallback;
|
||
|
|
||
|
#if FEATURE_COMPRESSEDSTACK
|
||
|
[Fx.Tag.SecurityNote(Critical = "Provides access to a critical field; Initialize it with " +
|
||
|
"a delegate to a critical method")]
|
||
|
public static Action<object> InvokeWithContextCallback
|
||
|
{
|
||
|
get
|
||
|
{
|
||
|
if (invokeWithContextCallback == null)
|
||
|
{
|
||
|
invokeWithContextCallback = new Action<object>(InvokeWithContext);
|
||
|
}
|
||
|
return invokeWithContextCallback;
|
||
|
}
|
||
|
}
|
||
|
#endif
|
||
|
[Fx.Tag.SecurityNote(Critical = "Provides access to a critical field; Initialize it with " +
|
||
|
"a delegate to a critical method")]
|
||
|
public static Action<object> InvokeWithoutContextCallback
|
||
|
{
|
||
|
get
|
||
|
{
|
||
|
if (invokeWithoutContextCallback == null)
|
||
|
{
|
||
|
invokeWithoutContextCallback = new Action<object>(InvokeWithoutContext);
|
||
|
}
|
||
|
return invokeWithoutContextCallback;
|
||
|
}
|
||
|
}
|
||
|
[Fx.Tag.SecurityNote(Critical = "Provides access to a critical field; Initialize it with " +
|
||
|
"a delegate to a critical method")]
|
||
|
public static ContextCallback OnContextAppliedCallback
|
||
|
{
|
||
|
get
|
||
|
{
|
||
|
if (onContextAppliedCallback == null)
|
||
|
{
|
||
|
onContextAppliedCallback = new ContextCallback(OnContextApplied);
|
||
|
}
|
||
|
return onContextAppliedCallback;
|
||
|
}
|
||
|
}
|
||
|
#if FEATURE_COMPRESSEDSTACK
|
||
|
[Fx.Tag.SecurityNote(Critical = "Called by the scheduler without any user context on the stack")]
|
||
|
static void InvokeWithContext(object state)
|
||
|
{
|
||
|
SecurityContext context = ((ActionItem)state).ExtractContext();
|
||
|
SecurityContext.Run(context, OnContextAppliedCallback, state);
|
||
|
}
|
||
|
#endif
|
||
|
[Fx.Tag.SecurityNote(Critical = "Called by the scheduler without any user context on the stack")]
|
||
|
static void InvokeWithoutContext(object state)
|
||
|
{
|
||
|
((ActionItem)state).Invoke();
|
||
|
((ActionItem)state).isScheduled = false;
|
||
|
}
|
||
|
[Fx.Tag.SecurityNote(Critical = "Called after applying the user context on the stack")]
|
||
|
static void OnContextApplied(object o)
|
||
|
{
|
||
|
((ActionItem)o).Invoke();
|
||
|
((ActionItem)o).isScheduled = false;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
class DefaultActionItem : ActionItem
|
||
|
{
|
||
|
[Fx.Tag.SecurityNote(Critical = "Stores a delegate that will be called later, at a particular context")]
|
||
|
[SecurityCritical]
|
||
|
Action<object> callback;
|
||
|
[Fx.Tag.SecurityNote(Critical = "Stores an object that will be passed to the delegate that will be " +
|
||
|
"called later, at a particular context")]
|
||
|
[SecurityCritical]
|
||
|
object state;
|
||
|
|
||
|
bool flowLegacyActivityId;
|
||
|
Guid activityId;
|
||
|
EventTraceActivity eventTraceActivity;
|
||
|
|
||
|
[Fx.Tag.SecurityNote(Critical = "Access critical fields callback and state",
|
||
|
Safe = "Doesn't leak information or resources")]
|
||
|
[SecuritySafeCritical]
|
||
|
public DefaultActionItem(Action<object> callback, object state, bool isLowPriority)
|
||
|
{
|
||
|
Fx.Assert(callback != null, "Shouldn't instantiate an object to wrap a null callback");
|
||
|
base.LowPriority = isLowPriority;
|
||
|
this.callback = callback;
|
||
|
this.state = state;
|
||
|
if (WaitCallbackActionItem.ShouldUseActivity)
|
||
|
{
|
||
|
this.flowLegacyActivityId = true;
|
||
|
this.activityId = EtwDiagnosticTrace.ActivityId;
|
||
|
}
|
||
|
if (Fx.Trace.IsEnd2EndActivityTracingEnabled)
|
||
|
{
|
||
|
this.eventTraceActivity = EventTraceActivity.GetFromThreadOrCreate();
|
||
|
if (TraceCore.ActionItemScheduledIsEnabled(Fx.Trace))
|
||
|
{
|
||
|
TraceCore.ActionItemScheduled(Fx.Trace, this.eventTraceActivity);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
|
[Fx.Tag.SecurityNote(Critical = "Implements a the critical abstract ActionItem.Invoke method, " +
|
||
|
"Access critical fields callback and state")]
|
||
|
[SecurityCritical]
|
||
|
protected override void Invoke()
|
||
|
{
|
||
|
if (this.flowLegacyActivityId || Fx.Trace.IsEnd2EndActivityTracingEnabled)
|
||
|
{
|
||
|
TraceAndInvoke();
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
this.callback(this.state);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
[Fx.Tag.SecurityNote(Critical = "Implements a the critical abstract Trace method, " +
|
||
|
"Access critical fields callback and state")]
|
||
|
[SecurityCritical]
|
||
|
void TraceAndInvoke()
|
||
|
{
|
||
|
//
|
||
|
if (this.flowLegacyActivityId)
|
||
|
{
|
||
|
Guid currentActivityId = EtwDiagnosticTrace.ActivityId;
|
||
|
try
|
||
|
{
|
||
|
EtwDiagnosticTrace.ActivityId = this.activityId;
|
||
|
this.callback(this.state);
|
||
|
}
|
||
|
finally
|
||
|
{
|
||
|
EtwDiagnosticTrace.ActivityId = currentActivityId;
|
||
|
}
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
Guid previous = Guid.Empty;
|
||
|
bool restoreActivityId = false;
|
||
|
try
|
||
|
{
|
||
|
if (this.eventTraceActivity != null)
|
||
|
{
|
||
|
previous = Trace.CorrelationManager.ActivityId;
|
||
|
restoreActivityId = true;
|
||
|
Trace.CorrelationManager.ActivityId = this.eventTraceActivity.ActivityId;
|
||
|
if (TraceCore.ActionItemCallbackInvokedIsEnabled(Fx.Trace))
|
||
|
{
|
||
|
TraceCore.ActionItemCallbackInvoked(Fx.Trace, this.eventTraceActivity);
|
||
|
}
|
||
|
}
|
||
|
this.callback(this.state);
|
||
|
}
|
||
|
finally
|
||
|
{
|
||
|
if (restoreActivityId)
|
||
|
{
|
||
|
Trace.CorrelationManager.ActivityId = previous;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|