From 8f9920832f07ed2cceb766b44f593b1ba2417036 Mon Sep 17 00:00:00 2001 From: Roman Marusyk Date: Mon, 16 Mar 2020 16:39:37 +0200 Subject: [PATCH] Remove calls to empty RuntimeHelpers.PrepareConstrainedRegions() (#33191) Fixes #33179 --- .../src/System/RuntimeType.CoreCLR.cs | 2 -- .../src/System/Threading/ThreadPool.CoreCLR.cs | 6 ---- .../System/Net/Windows/WebSockets/WebSocketBase.cs | 38 ++++++---------------- .../src/System/IO/UnmanagedMemoryStream.cs | 7 ---- .../src/System/Runtime/MemoryFailPoint.cs | 9 ----- 5 files changed, 10 insertions(+), 52 deletions(-) diff --git a/src/coreclr/src/System.Private.CoreLib/src/System/RuntimeType.CoreCLR.cs b/src/coreclr/src/System.Private.CoreLib/src/System/RuntimeType.CoreCLR.cs index 7c1c75f..734c969 100644 --- a/src/coreclr/src/System.Private.CoreLib/src/System/RuntimeType.CoreCLR.cs +++ b/src/coreclr/src/System.Private.CoreLib/src/System/RuntimeType.CoreCLR.cs @@ -367,7 +367,6 @@ namespace System { bool lockTaken = false; - RuntimeHelpers.PrepareConstrainedRegions(); try { Monitor.Enter(this, ref lockTaken); @@ -1576,7 +1575,6 @@ namespace System Interlocked.CompareExchange(ref s_methodInstantiationsLock!, new object(), null); bool lockTaken = false; - RuntimeHelpers.PrepareConstrainedRegions(); try { Monitor.Enter(s_methodInstantiationsLock, ref lockTaken); diff --git a/src/coreclr/src/System.Private.CoreLib/src/System/Threading/ThreadPool.CoreCLR.cs b/src/coreclr/src/System.Private.CoreLib/src/System/Threading/ThreadPool.CoreCLR.cs index 7dc9170..c2d72e3 100644 --- a/src/coreclr/src/System.Private.CoreLib/src/System/Threading/ThreadPool.CoreCLR.cs +++ b/src/coreclr/src/System.Private.CoreLib/src/System/Threading/ThreadPool.CoreCLR.cs @@ -46,9 +46,6 @@ namespace System.Threading internal void SetWaitObject(WaitHandle waitObject) { - // needed for DangerousAddRef - RuntimeHelpers.PrepareConstrainedRegions(); - m_internalWaitObject = waitObject; if (waitObject != null) { @@ -61,8 +58,6 @@ namespace System.Threading ) { bool result = false; - // needed for DangerousRelease - RuntimeHelpers.PrepareConstrainedRegions(); // lock(this) cannot be used reliably in Cer since thin lock could be // promoted to syncblock and that is not a guaranteed operation @@ -383,7 +378,6 @@ namespace System.Threading bool ret = false; bool mustReleaseSafeHandle = false; - RuntimeHelpers.PrepareConstrainedRegions(); try { osHandle.DangerousAddRef(ref mustReleaseSafeHandle); diff --git a/src/libraries/System.Net.HttpListener/src/System/Net/Windows/WebSockets/WebSocketBase.cs b/src/libraries/System.Net.HttpListener/src/System/Net/Windows/WebSockets/WebSocketBase.cs index 586c0cb..8016bb2 100644 --- a/src/libraries/System.Net.HttpListener/src/System/Net/Windows/WebSockets/WebSocketBase.cs +++ b/src/libraries/System.Net.HttpListener/src/System/Net/Windows/WebSockets/WebSocketBase.cs @@ -8,7 +8,6 @@ using System.Diagnostics; using System.Globalization; using System.IO; using System.Net.Sockets; -using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Text; using System.Threading; @@ -1018,26 +1017,16 @@ namespace System.Net.WebSockets Debug.Assert(_thisLock != null, "'_thisLock' MUST NOT be NULL."); Debug.Assert(SessionHandle != null, "'SessionHandle' MUST NOT be NULL."); - if (thisLockTaken || sessionHandleLockTaken) + if (thisLockTaken) { - RuntimeHelpers.PrepareConstrainedRegions(); - try - { - } - finally - { - if (thisLockTaken) - { - Monitor.Exit(_thisLock); - thisLockTaken = false; - } + Monitor.Exit(_thisLock); + thisLockTaken = false; + } - if (sessionHandleLockTaken) - { - Monitor.Exit(SessionHandle); - sessionHandleLockTaken = false; - } - } + if (sessionHandleLockTaken) + { + Monitor.Exit(SessionHandle); + sessionHandleLockTaken = false; } } @@ -1104,15 +1093,8 @@ namespace System.Net.WebSockets Debug.Assert(lockObject != null, "'lockObject' MUST NOT be NULL."); if (lockTaken) { - RuntimeHelpers.PrepareConstrainedRegions(); - try - { - } - finally - { - Monitor.Exit(lockObject); - lockTaken = false; - } + Monitor.Exit(lockObject); + lockTaken = false; } } diff --git a/src/libraries/System.Private.CoreLib/src/System/IO/UnmanagedMemoryStream.cs b/src/libraries/System.Private.CoreLib/src/System/IO/UnmanagedMemoryStream.cs index ef50864..ecdb454 100644 --- a/src/libraries/System.Private.CoreLib/src/System/IO/UnmanagedMemoryStream.cs +++ b/src/libraries/System.Private.CoreLib/src/System/IO/UnmanagedMemoryStream.cs @@ -4,7 +4,6 @@ using System.Buffers; using System.Diagnostics; -using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Threading; using System.Threading.Tasks; @@ -128,7 +127,6 @@ namespace System.IO unsafe { byte* pointer = null; - RuntimeHelpers.PrepareConstrainedRegions(); try { buffer.AcquirePointer(ref pointer); @@ -260,7 +258,6 @@ namespace System.IO { byte* pointer = null; - RuntimeHelpers.PrepareConstrainedRegions(); try { _buffer.AcquirePointer(ref pointer); @@ -490,7 +487,6 @@ namespace System.IO { byte* pointer = null; - RuntimeHelpers.PrepareConstrainedRegions(); try { _buffer.AcquirePointer(ref pointer); @@ -606,7 +602,6 @@ namespace System.IO unsafe { byte* pointer = null; - RuntimeHelpers.PrepareConstrainedRegions(); try { _buffer.AcquirePointer(ref pointer); @@ -786,7 +781,6 @@ namespace System.IO } byte* pointer = null; - RuntimeHelpers.PrepareConstrainedRegions(); try { _buffer.AcquirePointer(ref pointer); @@ -920,7 +914,6 @@ namespace System.IO unsafe { byte* pointer = null; - RuntimeHelpers.PrepareConstrainedRegions(); try { _buffer.AcquirePointer(ref pointer); diff --git a/src/libraries/System.Private.CoreLib/src/System/Runtime/MemoryFailPoint.cs b/src/libraries/System.Private.CoreLib/src/System/Runtime/MemoryFailPoint.cs index 191e2fe..d6c29347 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Runtime/MemoryFailPoint.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Runtime/MemoryFailPoint.cs @@ -14,7 +14,6 @@ ===========================================================*/ using System.Threading; -using System.Runtime.CompilerServices; using System.Runtime.ConstrainedExecution; using System.Diagnostics; @@ -235,10 +234,6 @@ namespace System.Runtime if (!needPageFile) continue; - // Attempt to grow the OS's page file. Note that we ignore - // any allocation routines from the host intentionally. - RuntimeHelpers.PrepareConstrainedRegions(); - // This shouldn't overflow due to the if clauses above. UIntPtr numBytes = new UIntPtr(segmentSize); GrowPageFileIfNecessaryAndPossible(numBytes); @@ -286,8 +281,6 @@ namespace System.Runtime if (LastKnownFreeAddressSpace < 0) CheckForFreeAddressSpace(segmentSize, true); - RuntimeHelpers.PrepareConstrainedRegions(); - AddMemoryFailPointReservation((long)size); _mustSubtractReservation = true; } @@ -317,8 +310,6 @@ namespace System.Runtime // within the GC heap. if (_mustSubtractReservation) { - RuntimeHelpers.PrepareConstrainedRegions(); - AddMemoryFailPointReservation(-((long)_reservedMemory)); _mustSubtractReservation = false; } -- 2.7.4