Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions src/coreclr/System.Private.CoreLib/src/System/Array.CoreCLR.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,17 +94,16 @@ private static unsafe void Copy(Array sourceArray, int sourceIndex, Array destin
if (sourceArray.GetType() != destinationArray.GetType() && sourceArray.Rank != destinationArray.Rank)
throw new RankException(SR.Rank_MustMatch);

if (length < 0)
throw new ArgumentOutOfRangeException(nameof(length), SR.ArgumentOutOfRange_NeedNonNegNum);
ArgumentOutOfRangeException.ThrowIfNegative(length);

int srcLB = sourceArray.GetLowerBound(0);
if (sourceIndex < srcLB || sourceIndex - srcLB < 0)
throw new ArgumentOutOfRangeException(nameof(sourceIndex), SR.ArgumentOutOfRange_ArrayLB);
ArgumentOutOfRangeException.ThrowIfLessThan(sourceIndex, srcLB);
ArgumentOutOfRangeException.ThrowIfNegative(sourceIndex - srcLB, nameof(sourceIndex));
sourceIndex -= srcLB;

int dstLB = destinationArray.GetLowerBound(0);
if (destinationIndex < dstLB || destinationIndex - dstLB < 0)
throw new ArgumentOutOfRangeException(nameof(destinationIndex), SR.ArgumentOutOfRange_ArrayLB);
ArgumentOutOfRangeException.ThrowIfLessThan(destinationIndex, dstLB);
ArgumentOutOfRangeException.ThrowIfNegative(destinationIndex - dstLB, nameof(destinationIndex));
destinationIndex -= dstLB;

if ((uint)(sourceIndex + length) > sourceArray.NativeLength)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ public void CopyTo(Array array, int index)
if (array.Rank != 1)
throw new ArgumentException(SR.Arg_RankMultiDimNotSupported);

if (index < 0)
throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_NeedNonNegNum);
ArgumentOutOfRangeException.ThrowIfNegative(index);

if (array.Length - index < this.Count)
throw new ArgumentException(SR.ArgumentOutOfRange_IndexMustBeLessOrEqual, nameof(index));
Expand Down
55 changes: 13 additions & 42 deletions src/coreclr/System.Private.CoreLib/src/System/GC.CoreCLR.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,33 +136,21 @@ internal enum GC_ALLOC_FLAGS

public static void AddMemoryPressure(long bytesAllocated)
{
if (bytesAllocated <= 0)
ArgumentOutOfRangeException.ThrowIfNegativeOrZero(bytesAllocated);
if (IntPtr.Size == 4)
{
throw new ArgumentOutOfRangeException(nameof(bytesAllocated),
SR.ArgumentOutOfRange_NeedPosNum);
}

if ((4 == IntPtr.Size) && (bytesAllocated > int.MaxValue))
{
throw new ArgumentOutOfRangeException(nameof(bytesAllocated),
SR.ArgumentOutOfRange_MustBeNonNegInt32);
ArgumentOutOfRangeException.ThrowIfGreaterThan(bytesAllocated, int.MaxValue);
}

_AddMemoryPressure((ulong)bytesAllocated);
}

public static void RemoveMemoryPressure(long bytesAllocated)
{
if (bytesAllocated <= 0)
{
throw new ArgumentOutOfRangeException(nameof(bytesAllocated),
SR.ArgumentOutOfRange_NeedPosNum);
}

if ((4 == IntPtr.Size) && (bytesAllocated > int.MaxValue))
ArgumentOutOfRangeException.ThrowIfNegativeOrZero(bytesAllocated);
if (IntPtr.Size == 4)
{
throw new ArgumentOutOfRangeException(nameof(bytesAllocated),
SR.ArgumentOutOfRange_MustBeNonNegInt32);
ArgumentOutOfRangeException.ThrowIfGreaterThan(bytesAllocated, int.MaxValue);
}

_RemoveMemoryPressure((ulong)bytesAllocated);
Expand Down Expand Up @@ -202,10 +190,7 @@ public static void Collect(int generation, GCCollectionMode mode, bool blocking)

public static void Collect(int generation, GCCollectionMode mode, bool blocking, bool compacting)
{
if (generation < 0)
{
throw new ArgumentOutOfRangeException(nameof(generation), SR.ArgumentOutOfRange_GenericPositive);
}
ArgumentOutOfRangeException.ThrowIfNegative(generation);

if ((mode < GCCollectionMode.Default) || (mode > GCCollectionMode.Aggressive))
{
Expand Down Expand Up @@ -253,10 +238,7 @@ public static void Collect(int generation, GCCollectionMode mode, bool blocking,

public static int CollectionCount(int generation)
{
if (generation < 0)
{
throw new ArgumentOutOfRangeException(nameof(generation), SR.ArgumentOutOfRange_GenericPositive);
}
ArgumentOutOfRangeException.ThrowIfNegative(generation);
return _CollectionCount(generation, 0);
}

Expand Down Expand Up @@ -447,8 +429,7 @@ public static GCNotificationStatus WaitForFullGCApproach()

public static GCNotificationStatus WaitForFullGCApproach(int millisecondsTimeout)
{
if (millisecondsTimeout < -1)
throw new ArgumentOutOfRangeException(nameof(millisecondsTimeout), SR.ArgumentOutOfRange_NeedNonNegOrNegative1);
ArgumentOutOfRangeException.ThrowIfLessThan(millisecondsTimeout, -1);

return (GCNotificationStatus)_WaitForFullGCApproach(millisecondsTimeout);
}
Expand All @@ -460,8 +441,7 @@ public static GCNotificationStatus WaitForFullGCComplete()

public static GCNotificationStatus WaitForFullGCComplete(int millisecondsTimeout)
{
if (millisecondsTimeout < -1)
throw new ArgumentOutOfRangeException(nameof(millisecondsTimeout), SR.ArgumentOutOfRange_NeedNonNegOrNegative1);
ArgumentOutOfRangeException.ThrowIfLessThan(millisecondsTimeout, -1);
return (GCNotificationStatus)_WaitForFullGCComplete(millisecondsTimeout);
}

Expand All @@ -483,22 +463,13 @@ private enum EndNoGCRegionStatus

private static bool StartNoGCRegionWorker(long totalSize, bool hasLohSize, long lohSize, bool disallowFullBlockingGC)
{
if (totalSize <= 0)
{
throw new ArgumentOutOfRangeException(nameof(totalSize), SR.ArgumentOutOfRange_MustBePositive);
}
ArgumentOutOfRangeException.ThrowIfNegativeOrZero(totalSize);

if (hasLohSize)
{
if (lohSize <= 0)
{
throw new ArgumentOutOfRangeException(nameof(lohSize), SR.ArgumentOutOfRange_MustBePositive);
}
ArgumentOutOfRangeException.ThrowIfNegativeOrZero(lohSize);

if (lohSize > totalSize)
{
throw new ArgumentOutOfRangeException(nameof(lohSize), SR.ArgumentOutOfRange_NoGCLohSizeGreaterTotalSize);
}
ArgumentOutOfRangeException.ThrowIfGreaterThan(lohSize, totalSize);
}

StartNoGCRegionStatus status = (StartNoGCRegionStatus)_StartNoGCRegion(totalSize, hasLohSize, lohSize, disallowFullBlockingGC);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -907,8 +907,7 @@ public void SetCode(byte[]? code, int maxStackSize)
[CLSCompliant(false)]
public unsafe void SetCode(byte* code, int codeSize, int maxStackSize)
{
if (codeSize < 0)
throw new ArgumentOutOfRangeException(nameof(codeSize), SR.ArgumentOutOfRange_GenericPositive);
ArgumentOutOfRangeException.ThrowIfNegative(codeSize);
if (codeSize > 0)
ArgumentNullException.ThrowIfNull(code);

Expand All @@ -924,8 +923,7 @@ public void SetExceptions(byte[]? exceptions)
[CLSCompliant(false)]
public unsafe void SetExceptions(byte* exceptions, int exceptionsSize)
{
if (exceptionsSize < 0)
throw new ArgumentOutOfRangeException(nameof(exceptionsSize), SR.ArgumentOutOfRange_GenericPositive);
ArgumentOutOfRangeException.ThrowIfNegative(exceptionsSize);

if (exceptionsSize > 0)
ArgumentNullException.ThrowIfNull(exceptions);
Expand All @@ -941,9 +939,7 @@ public void SetLocalSignature(byte[]? localSignature)
[CLSCompliant(false)]
public unsafe void SetLocalSignature(byte* localSignature, int signatureSize)
{
if (signatureSize < 0)
throw new ArgumentOutOfRangeException(nameof(signatureSize), SR.ArgumentOutOfRange_GenericPositive);

ArgumentOutOfRangeException.ThrowIfNegative(signatureSize);
if (signatureSize > 0)
ArgumentNullException.ThrowIfNull(localSignature);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ private int GetReplaceBufferCapacity(int requiredCapacity)

internal unsafe void ReplaceBufferInternal(char* newBuffer, int newLength)
{
if (newLength > m_MaxCapacity)
throw new ArgumentOutOfRangeException("capacity", SR.ArgumentOutOfRange_Capacity);
ArgumentOutOfRangeException.ThrowIfGreaterThan(newLength, m_MaxCapacity, "capacity");

if (newLength > m_ChunkChars.Length)
{
Expand All @@ -42,8 +41,7 @@ internal unsafe void ReplaceBufferInternal(char* newBuffer, int newLength)

internal void ReplaceBufferUtf8Internal(ReadOnlySpan<byte> source)
{
if (source.Length > m_MaxCapacity)
throw new ArgumentOutOfRangeException("capacity", SR.ArgumentOutOfRange_Capacity);
ArgumentOutOfRangeException.ThrowIfGreaterThan(source.Length, m_MaxCapacity, "capacity");

int numChars = Encoding.UTF8.GetCharCount(source);
if (numChars > m_ChunkChars.Length)
Expand All @@ -58,8 +56,7 @@ internal void ReplaceBufferUtf8Internal(ReadOnlySpan<byte> source)

internal unsafe void ReplaceBufferAnsiInternal(sbyte* newBuffer, int newLength)
{
if (newLength > m_MaxCapacity)
throw new ArgumentOutOfRangeException("capacity", SR.ArgumentOutOfRange_Capacity);
ArgumentOutOfRangeException.ThrowIfGreaterThan(newLength, m_MaxCapacity, "capacity");

if (newLength > m_ChunkChars.Length)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,7 @@ public static bool IsEntered(object obj)
public static bool Wait(object obj, int millisecondsTimeout)
{
ArgumentNullException.ThrowIfNull(obj);
if (millisecondsTimeout < -1)
throw new ArgumentOutOfRangeException(nameof(millisecondsTimeout), SR.ArgumentOutOfRange_NeedNonNegOrNegative1);
ArgumentOutOfRangeException.ThrowIfLessThan(millisecondsTimeout, -1);

return ObjWait(millisecondsTimeout, obj);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,7 @@ public static void Collect(int generation, GCCollectionMode mode, bool blocking)

public static void Collect(int generation, GCCollectionMode mode, bool blocking, bool compacting)
{
if (generation < 0)
{
throw new ArgumentOutOfRangeException(nameof(generation), SR.ArgumentOutOfRange_GenericPositive);
}
ArgumentOutOfRangeException.ThrowIfNegative(generation);

if ((mode < GCCollectionMode.Default) || (mode > GCCollectionMode.Aggressive))
{
Expand Down Expand Up @@ -224,12 +221,7 @@ public static GCNotificationStatus WaitForFullGCApproach()
/// <returns>The status of a registered full GC notification</returns>
public static GCNotificationStatus WaitForFullGCApproach(int millisecondsTimeout)
{
if (millisecondsTimeout < -1)
{
throw new ArgumentOutOfRangeException(
nameof(millisecondsTimeout),
SR.ArgumentOutOfRange_NeedNonNegOrNegative1);
}
ArgumentOutOfRangeException.ThrowIfLessThan(millisecondsTimeout, -1);

return (GCNotificationStatus)RuntimeImports.RhWaitForFullGCApproach(millisecondsTimeout);
}
Expand All @@ -252,12 +244,7 @@ public static GCNotificationStatus WaitForFullGCComplete()
/// <returns></returns>
public static GCNotificationStatus WaitForFullGCComplete(int millisecondsTimeout)
{
if (millisecondsTimeout < -1)
{
throw new ArgumentOutOfRangeException(
nameof(millisecondsTimeout),
SR.ArgumentOutOfRange_NeedNonNegOrNegative1);
}
ArgumentOutOfRangeException.ThrowIfLessThan(millisecondsTimeout, -1);

return (GCNotificationStatus)RuntimeImports.RhWaitForFullGCComplete(millisecondsTimeout);
}
Expand Down Expand Up @@ -341,22 +328,10 @@ public static bool TryStartNoGCRegion(long totalSize, long lohSize, bool disallo

private static bool StartNoGCRegionWorker(long totalSize, bool hasLohSize, long lohSize, bool disallowFullBlockingGC)
{
if (totalSize <= 0)
{
throw new ArgumentOutOfRangeException(
nameof(totalSize),
SR.Format(SR.ArgumentOutOfRange_MustBePositive, nameof(totalSize)));
}

ArgumentOutOfRangeException.ThrowIfNegativeOrZero(totalSize);
if (hasLohSize)
{
if (lohSize <= 0)
{
throw new ArgumentOutOfRangeException(
nameof(lohSize),
SR.Format(SR.ArgumentOutOfRange_MustBePositive, nameof(lohSize)));
}

ArgumentOutOfRangeException.ThrowIfNegativeOrZero(lohSize);
if (lohSize > totalSize)
{
throw new ArgumentOutOfRangeException(nameof(lohSize), SR.ArgumentOutOfRange_NoGCLohSizeGreaterTotalSize);
Expand Down Expand Up @@ -445,8 +420,7 @@ public static int MaxGeneration

public static int CollectionCount(int generation)
{
if (generation < 0)
throw new ArgumentOutOfRangeException(nameof(generation), SR.ArgumentOutOfRange_GenericPositive);
ArgumentOutOfRangeException.ThrowIfNegative(generation);

return RuntimeImports.RhGetGcCollectionCount(generation, false);
}
Expand Down Expand Up @@ -527,18 +501,9 @@ private static long InterlockedAddMemoryPressure(ref long pAugend, long addend)
/// <param name="bytesAllocated"></param>
public static void AddMemoryPressure(long bytesAllocated)
{
if (bytesAllocated <= 0)
{
throw new ArgumentOutOfRangeException(nameof(bytesAllocated),
SR.ArgumentOutOfRange_NeedPosNum);
}

ArgumentOutOfRangeException.ThrowIfNegativeOrZero(bytesAllocated);
#if !TARGET_64BIT
if (bytesAllocated > int.MaxValue)
{
throw new ArgumentOutOfRangeException(nameof(bytesAllocated),
SR.ArgumentOutOfRange_MustBeNonNegInt32);
}
ArgumentOutOfRangeException.ThrowIfGreaterThan(bytesAllocated, int.MaxValue);
#endif

CheckCollectionCount();
Expand Down Expand Up @@ -654,18 +619,9 @@ public static unsafe IReadOnlyDictionary<string, object> GetConfigurationVariabl

public static void RemoveMemoryPressure(long bytesAllocated)
{
if (bytesAllocated <= 0)
{
throw new ArgumentOutOfRangeException(nameof(bytesAllocated),
SR.ArgumentOutOfRange_NeedPosNum);
}

ArgumentOutOfRangeException.ThrowIfNegativeOrZero(bytesAllocated);
#if !TARGET_64BIT
if (bytesAllocated > int.MaxValue)
{
throw new ArgumentOutOfRangeException(nameof(bytesAllocated),
SR.ArgumentOutOfRange_MustBeNonNegInt32);
}
ArgumentOutOfRangeException.ThrowIfGreaterThan(bytesAllocated, int.MaxValue);
#endif

CheckCollectionCount();
Expand Down
5 changes: 1 addition & 4 deletions src/libraries/Common/src/Interop/FreeBSD/Interop.Process.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,7 @@ public static unsafe string GetProcPath(int pid)
public static unsafe ProcessInfo GetProcessInfoById(int pid)
{
// Negative PIDs are invalid
if (pid < 0)
{
throw new ArgumentOutOfRangeException(nameof(pid));
}
ArgumentOutOfRangeException.ThrowIfNegative(pid);

ProcessInfo info;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,7 @@ private static unsafe partial int proc_pidinfo(
internal static unsafe proc_taskallinfo? GetProcessInfoById(int pid)
{
// Negative PIDs are invalid
if (pid < 0)
{
throw new ArgumentOutOfRangeException(nameof(pid));
}
ArgumentOutOfRangeException.ThrowIfNegative(pid);

// Get the process information for the specified pid
int size = sizeof(proc_taskallinfo);
Expand Down
Loading