-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathStackGuard.cs
28 lines (24 loc) · 927 Bytes
/
StackGuard.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
using System.Diagnostics;
using System.Runtime.CompilerServices;
namespace Acornima.Helpers;
// Based on: https://github.com/dotnet/roslyn/blob/VSCode-CSharp-2.18.15/src/Compilers/Core/Portable/InternalUtilities/StackGuard.cs
internal static class StackGuard
{
public const int MaxUncheckedRecursionDepth = 20;
#if DEBUG
[DebuggerStepThrough]
#endif
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void EnsureSufficientExecutionStack(int recursionDepth)
{
if (recursionDepth > MaxUncheckedRecursionDepth)
{
// Makes sure that
// * on 32-bit platforms at least 64 kB
// * on 64-bit platforms at least 128 kB
// of stack space is available.
// See also: https://github.com/dotnet/runtime/blob/v8.0.2/src/coreclr/vm/threads.cpp#L6352
RuntimeHelpers.EnsureSufficientExecutionStack();
}
}
}