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 875b02cfab598..a5d0498436454 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 @@ internal void Insert(ref T[] list, string? name, MemberListType listType) { bool lockTaken = false; - RuntimeHelpers.PrepareConstrainedRegions(); try { Monitor.Enter(this, ref lockTaken); @@ -1576,7 +1575,6 @@ internal MethodInfo GetGenericMethodInfo(RuntimeMethodHandleInternal genericMeth 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 7dc91700ddd63..c2d72e3915cae 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 @@ internal void SetHandle(IntPtr handle) internal void SetWaitObject(WaitHandle waitObject) { - // needed for DangerousAddRef - RuntimeHelpers.PrepareConstrainedRegions(); - m_internalWaitObject = waitObject; if (waitObject != null) { @@ -61,8 +58,6 @@ internal bool Unregister( ) { 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 @@ public static bool BindHandle(SafeHandle osHandle) 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 586c0cbea28fe..8016bb28c4be2 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.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 @@ private void ReleaseLocks(ref bool thisLockTaken, ref bool sessionHandleLockTake 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 @@ private static void ReleaseLock(object lockObject, ref bool lockTaken) 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 ef508648226b8..ecdb454203bf4 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 @@ protected void Initialize(SafeBuffer buffer, long offset, long length, FileAcces unsafe { byte* pointer = null; - RuntimeHelpers.PrepareConstrainedRegions(); try { buffer.AcquirePointer(ref pointer); @@ -260,7 +258,6 @@ public override void CopyTo(ReadOnlySpanAction callback, object? { byte* pointer = null; - RuntimeHelpers.PrepareConstrainedRegions(); try { _buffer.AcquirePointer(ref pointer); @@ -490,7 +487,6 @@ internal int ReadCore(Span buffer) { byte* pointer = null; - RuntimeHelpers.PrepareConstrainedRegions(); try { _buffer.AcquirePointer(ref pointer); @@ -606,7 +602,6 @@ public override int ReadByte() unsafe { byte* pointer = null; - RuntimeHelpers.PrepareConstrainedRegions(); try { _buffer.AcquirePointer(ref pointer); @@ -786,7 +781,6 @@ internal unsafe void WriteCore(ReadOnlySpan buffer) } byte* pointer = null; - RuntimeHelpers.PrepareConstrainedRegions(); try { _buffer.AcquirePointer(ref pointer); @@ -920,7 +914,6 @@ public override void WriteByte(byte value) 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 191e2fed58cd8..d6c29347d425d 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 @@ public MemoryFailPoint(int sizeInMegabytes) 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 @@ public MemoryFailPoint(int sizeInMegabytes) if (LastKnownFreeAddressSpace < 0) CheckForFreeAddressSpace(segmentSize, true); - RuntimeHelpers.PrepareConstrainedRegions(); - AddMemoryFailPointReservation((long)size); _mustSubtractReservation = true; } @@ -317,8 +310,6 @@ private void Dispose(bool disposing) // within the GC heap. if (_mustSubtractReservation) { - RuntimeHelpers.PrepareConstrainedRegions(); - AddMemoryFailPointReservation(-((long)_reservedMemory)); _mustSubtractReservation = false; }