diff options
Diffstat (limited to 'src/mscorlib/src/System/Threading/WaitHandle.cs')
-rw-r--r-- | src/mscorlib/src/System/Threading/WaitHandle.cs | 83 |
1 files changed, 14 insertions, 69 deletions
diff --git a/src/mscorlib/src/System/Threading/WaitHandle.cs b/src/mscorlib/src/System/Threading/WaitHandle.cs index 9980c822a6..7638c8b35b 100644 --- a/src/mscorlib/src/System/Threading/WaitHandle.cs +++ b/src/mscorlib/src/System/Threading/WaitHandle.cs @@ -27,12 +27,8 @@ namespace System.Threading using System.Diagnostics.CodeAnalysis; using Win32Native = Microsoft.Win32.Win32Native; -[System.Runtime.InteropServices.ComVisible(true)] -#if FEATURE_REMOTING + [System.Runtime.InteropServices.ComVisible(true)] public abstract class WaitHandle : MarshalByRefObject, IDisposable { -#else // FEATURE_REMOTING - public abstract class WaitHandle : IDisposable { -#endif // FEATURE_REMOTING public const int WaitTimeout = 0x102; private const int MAX_WAITHANDLES = 64; @@ -41,12 +37,10 @@ namespace System.Threading private IntPtr waitHandle; // !!! DO NOT MOVE THIS FIELD. (See defn of WAITHANDLEREF in object.h - has hardcoded access to this field.) #pragma warning restore 414 - [System.Security.SecurityCritical] // auto-generated internal volatile SafeWaitHandle safeWaitHandle; internal bool hasThreadAffinity; - [System.Security.SecuritySafeCritical] // auto-generated private static IntPtr GetInvalidHandle() { return Win32Native.INVALID_HANDLE_VALUE; @@ -70,7 +64,6 @@ namespace System.Threading Init(); } - [System.Security.SecuritySafeCritical] // auto-generated private void Init() { safeWaitHandle = null; @@ -82,13 +75,7 @@ namespace System.Threading [Obsolete("Use the SafeWaitHandle property instead.")] public virtual IntPtr Handle { - [System.Security.SecuritySafeCritical] // auto-generated get { return safeWaitHandle == null ? InvalidHandle : safeWaitHandle.DangerousGetHandle();} - - [System.Security.SecurityCritical] // auto-generated_required -#if !FEATURE_CORECLR - [SecurityPermissionAttribute(SecurityAction.InheritanceDemand, Flags=SecurityPermissionFlag.UnmanagedCode)] -#endif set { if (value == InvalidHandle) @@ -113,13 +100,8 @@ namespace System.Threading } } - public SafeWaitHandle SafeWaitHandle { - [System.Security.SecurityCritical] // auto-generated_required -#if !FEATURE_CORECLR - [SecurityPermissionAttribute(SecurityAction.InheritanceDemand, Flags=SecurityPermissionFlag.UnmanagedCode)] -#endif [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)] get { @@ -129,11 +111,7 @@ namespace System.Threading } return safeWaitHandle; } - - [System.Security.SecurityCritical] // auto-generated_required -#if !FEATURE_CORECLR - [SecurityPermissionAttribute(SecurityAction.InheritanceDemand, Flags=SecurityPermissionFlag.UnmanagedCode)] -#endif + [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)] set { @@ -168,7 +146,6 @@ namespace System.Threading // FileStream, which will then call Sethandle, which requires a link time // security check.). While security has fixed that problem, we still // don't need to do a linktime check here. - [System.Security.SecurityCritical] // auto-generated internal void SetHandleInternal(SafeWaitHandle handle) { safeWaitHandle = handle; @@ -179,7 +156,7 @@ namespace System.Threading { if (millisecondsTimeout < -1) { - throw new ArgumentOutOfRangeException("millisecondsTimeout", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegOrNegative1")); + throw new ArgumentOutOfRangeException(nameof(millisecondsTimeout), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegOrNegative1")); } Contract.EndContractBlock(); return WaitOne((long)millisecondsTimeout,exitContext); @@ -190,7 +167,7 @@ namespace System.Threading long tm = (long)timeout.TotalMilliseconds; if (-1 > tm || (long) Int32.MaxValue < tm) { - throw new ArgumentOutOfRangeException("timeout", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegOrNegative1")); + throw new ArgumentOutOfRangeException(nameof(timeout), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegOrNegative1")); } return WaitOne(tm,exitContext); } @@ -211,14 +188,12 @@ namespace System.Threading return WaitOne(timeout, false); } - [System.Security.SecuritySafeCritical] // auto-generated [SuppressMessage("Microsoft.Concurrency", "CA8001", Justification = "Reviewed for thread-safety.")] private bool WaitOne(long timeout, bool exitContext) { return InternalWaitOne(safeWaitHandle, timeout, hasThreadAffinity, exitContext); } - [System.Security.SecurityCritical] // auto-generated internal static bool InternalWaitOne(SafeHandle waitableSafeHandle, long millisecondsTimeout, bool hasThreadAffinity, bool exitContext) { if (waitableSafeHandle == null) @@ -238,7 +213,6 @@ namespace System.Threading return (ret != WaitTimeout); } - [System.Security.SecurityCritical] internal bool WaitOneWithoutFAS() { // version of waitone without fast application switch (FAS) support @@ -258,7 +232,6 @@ namespace System.Threading return (ret != WaitTimeout); } - [System.Security.SecurityCritical] // auto-generated [MethodImplAttribute(MethodImplOptions.InternalCall)] private static extern int WaitOneNative(SafeHandle waitableSafeHandle, uint millisecondsTimeout, bool hasThreadAffinity, bool exitContext); @@ -271,17 +244,15 @@ namespace System.Threading ** (if in a synchronized context) is exited before the wait and reacquired ========================================================================*/ - [System.Security.SecurityCritical] // auto-generated [MethodImplAttribute(MethodImplOptions.InternalCall)] [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)] private static extern int WaitMultiple(WaitHandle[] waitHandles, int millisecondsTimeout, bool exitContext, bool WaitAll); - [System.Security.SecuritySafeCritical] // auto-generated public static bool WaitAll(WaitHandle[] waitHandles, int millisecondsTimeout, bool exitContext) { if (waitHandles == null) { - throw new ArgumentNullException("waitHandles", Environment.GetResourceString("ArgumentNull_Waithandles")); + throw new ArgumentNullException(nameof(waitHandles), Environment.GetResourceString("ArgumentNull_Waithandles")); } if(waitHandles.Length == 0) { @@ -294,11 +265,7 @@ namespace System.Threading // in CoreCLR, and ArgumentNullException in the desktop CLR. This is ugly, but so is breaking // user code. // -#if FEATURE_CORECLR throw new ArgumentException(Environment.GetResourceString("Argument_EmptyWaithandleArray")); -#else - throw new ArgumentNullException("waitHandles", Environment.GetResourceString("Argument_EmptyWaithandleArray")); -#endif } if (waitHandles.Length > MAX_WAITHANDLES) { @@ -306,7 +273,7 @@ namespace System.Threading } if (-1 > millisecondsTimeout) { - throw new ArgumentOutOfRangeException("millisecondsTimeout", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegOrNegative1")); + throw new ArgumentOutOfRangeException(nameof(millisecondsTimeout), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegOrNegative1")); } Contract.EndContractBlock(); WaitHandle[] internalWaitHandles = new WaitHandle[waitHandles.Length]; @@ -317,11 +284,6 @@ namespace System.Threading if (waitHandle == null) throw new ArgumentNullException("waitHandles[" + i + "]", Environment.GetResourceString("ArgumentNull_ArrayElement")); -#if FEATURE_REMOTING - if (RemotingServices.IsTransparentProxy(waitHandle)) - throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_WaitOnTransparentProxy")); -#endif - internalWaitHandles[i] = waitHandle; } #if _DEBUG @@ -354,7 +316,7 @@ namespace System.Threading long tm = (long)timeout.TotalMilliseconds; if (-1 > tm || (long) Int32.MaxValue < tm) { - throw new ArgumentOutOfRangeException("timeout", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegOrNegative1")); + throw new ArgumentOutOfRangeException(nameof(timeout), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegOrNegative1")); } return WaitAll(waitHandles,(int)tm, exitContext); } @@ -388,13 +350,12 @@ namespace System.Threading ** (if in a synchronized context) is exited before the wait and reacquired ========================================================================*/ - [System.Security.SecuritySafeCritical] // auto-generated [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)] public static int WaitAny(WaitHandle[] waitHandles, int millisecondsTimeout, bool exitContext) { if (waitHandles==null) { - throw new ArgumentNullException("waitHandles", Environment.GetResourceString("ArgumentNull_Waithandles")); + throw new ArgumentNullException(nameof(waitHandles), Environment.GetResourceString("ArgumentNull_Waithandles")); } if(waitHandles.Length == 0) { @@ -406,7 +367,7 @@ namespace System.Threading } if (-1 > millisecondsTimeout) { - throw new ArgumentOutOfRangeException("millisecondsTimeout", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegOrNegative1")); + throw new ArgumentOutOfRangeException(nameof(millisecondsTimeout), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegOrNegative1")); } Contract.EndContractBlock(); WaitHandle[] internalWaitHandles = new WaitHandle[waitHandles.Length]; @@ -417,11 +378,6 @@ namespace System.Threading if (waitHandle == null) throw new ArgumentNullException("waitHandles[" + i + "]", Environment.GetResourceString("ArgumentNull_ArrayElement")); -#if FEATURE_REMOTING - if (RemotingServices.IsTransparentProxy(waitHandle)) - throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_WaitOnTransparentProxy")); -#endif - internalWaitHandles[i] = waitHandle; } #if _DEBUG @@ -459,7 +415,7 @@ namespace System.Threading long tm = (long)timeout.TotalMilliseconds; if (-1 > tm || (long) Int32.MaxValue < tm) { - throw new ArgumentOutOfRangeException("timeout", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegOrNegative1")); + throw new ArgumentOutOfRangeException(nameof(timeout), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegOrNegative1")); } return WaitAny(waitHandles,(int)tm, exitContext); } @@ -491,7 +447,6 @@ namespace System.Threading == ==================================================*/ - [System.Security.SecurityCritical] // auto-generated [MethodImplAttribute(MethodImplOptions.InternalCall)] private static extern int SignalAndWaitOne(SafeWaitHandle waitHandleToSignal,SafeWaitHandle waitHandleToWaitOn, int millisecondsTimeout, bool hasThreadAffinity, bool exitContext); @@ -519,13 +474,12 @@ namespace System.Threading long tm = (long)timeout.TotalMilliseconds; if (-1 > tm || (long) Int32.MaxValue < tm) { - throw new ArgumentOutOfRangeException("timeout", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegOrNegative1")); + throw new ArgumentOutOfRangeException(nameof(timeout), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegOrNegative1")); } return SignalAndWait(toSignal,toWaitOn,(int)tm,exitContext); #endif } - [System.Security.SecuritySafeCritical] // auto-generated [SuppressMessage("Microsoft.Concurrency", "CA8001", Justification = "Reviewed for thread-safety.")] public static bool SignalAndWait( WaitHandle toSignal, @@ -538,15 +492,15 @@ namespace System.Threading #else if(null == toSignal) { - throw new ArgumentNullException("toSignal"); + throw new ArgumentNullException(nameof(toSignal)); } if(null == toWaitOn) { - throw new ArgumentNullException("toWaitOn"); + throw new ArgumentNullException(nameof(toWaitOn)); } if (-1 > millisecondsTimeout) { - throw new ArgumentOutOfRangeException("millisecondsTimeout", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegOrNegative1")); + throw new ArgumentOutOfRangeException(nameof(millisecondsTimeout), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegOrNegative1")); } Contract.EndContractBlock(); @@ -554,14 +508,6 @@ namespace System.Threading int ret = SignalAndWaitOne(toSignal.safeWaitHandle,toWaitOn.safeWaitHandle,millisecondsTimeout, toWaitOn.hasThreadAffinity,exitContext); -#if !FEATURE_CORECLR - if(WAIT_FAILED != ret && toSignal.hasThreadAffinity) - { - Thread.EndCriticalRegion(); - Thread.EndThreadAffinity(); - } -#endif - if(WAIT_ABANDONED == ret) { ThrowAbandonedMutexException(); @@ -599,7 +545,6 @@ namespace System.Threading GC.SuppressFinalize(this); } - [System.Security.SecuritySafeCritical] // auto-generated protected virtual void Dispose(bool explicitDisposing) { if (safeWaitHandle != null) |