From c02fb4d6eebf4579ad63e2a3758f84a80cb0be4e Mon Sep 17 00:00:00 2001 From: Hamish Arblaster Date: Tue, 6 Feb 2024 09:55:54 +1100 Subject: [PATCH 01/19] Change stack size - Change stack size to 4MB on 64-bit desktop - Add tests to check stack size --- eng/native/configurecompiler.cmake | 2 +- src/coreclr/pal/src/init/pal.cpp | 10 ++++- .../ref/System.Reflection.Metadata.cs | 2 +- .../PortableExecutable/PEHeaderBuilder.cs | 16 +++---- src/native/libs/System.Native/pal_threading.c | 8 ++++ .../ForeignThreadExceptionsNative.cpp | 4 +- .../coreclr/GitHub_87879/test87879.cs | 39 +++++++++++++++++ .../coreclr/GitHub_87879/test87879.csproj | 11 +++++ .../DesktopStackSize/DesktopStackSize.cs | 42 +++++++++++++++++++ .../DesktopStackSize/DesktopStackSize.csproj | 12 ++++++ 10 files changed, 133 insertions(+), 13 deletions(-) create mode 100644 src/tests/Regressions/coreclr/GitHub_87879/test87879.cs create mode 100644 src/tests/Regressions/coreclr/GitHub_87879/test87879.csproj create mode 100644 src/tests/nativeaot/DesktopStackSize/DesktopStackSize.cs create mode 100644 src/tests/nativeaot/DesktopStackSize/DesktopStackSize.csproj diff --git a/eng/native/configurecompiler.cmake b/eng/native/configurecompiler.cmake index 166fd52ab96562..9fba9c2f5a7d48 100644 --- a/eng/native/configurecompiler.cmake +++ b/eng/native/configurecompiler.cmake @@ -102,7 +102,7 @@ if (MSVC) if (CLR_CMAKE_ENABLE_SANITIZERS) set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /STACK:0x800000") else() - set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /STACK:0x180000") + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /STACK:0x400000") endif() if(EXISTS ${CLR_SOURCELINK_FILE_PATH}) diff --git a/src/coreclr/pal/src/init/pal.cpp b/src/coreclr/pal/src/init/pal.cpp index c88febfc261622..e560e00a4fc7e3 100644 --- a/src/coreclr/pal/src/init/pal.cpp +++ b/src/coreclr/pal/src/init/pal.cpp @@ -288,12 +288,20 @@ InitializeDefaultStackSize() } } +#ifdef HOST_OSX + // Match Windows stack size + if (g_defaultStackSize == 0) + { + g_defaultStackSize = 4096 * 1024; + } +#endif + #ifdef ENSURE_PRIMARY_STACK_SIZE if (g_defaultStackSize == 0) { // Set the default minimum stack size for MUSL to the same value as we // use on Windows. - g_defaultStackSize = 1536 * 1024; + g_defaultStackSize = 4096 * 1024; } #endif // ENSURE_PRIMARY_STACK_SIZE } diff --git a/src/libraries/System.Reflection.Metadata/ref/System.Reflection.Metadata.cs b/src/libraries/System.Reflection.Metadata/ref/System.Reflection.Metadata.cs index d656738565288c..0cc7573633775b 100644 --- a/src/libraries/System.Reflection.Metadata/ref/System.Reflection.Metadata.cs +++ b/src/libraries/System.Reflection.Metadata/ref/System.Reflection.Metadata.cs @@ -3400,7 +3400,7 @@ internal PEHeader() { } } public sealed partial class PEHeaderBuilder { - public PEHeaderBuilder(System.Reflection.PortableExecutable.Machine machine = System.Reflection.PortableExecutable.Machine.Unknown, int sectionAlignment = 8192, int fileAlignment = 512, ulong imageBase = (ulong)4194304, byte majorLinkerVersion = (byte)48, byte minorLinkerVersion = (byte)0, ushort majorOperatingSystemVersion = (ushort)4, ushort minorOperatingSystemVersion = (ushort)0, ushort majorImageVersion = (ushort)0, ushort minorImageVersion = (ushort)0, ushort majorSubsystemVersion = (ushort)4, ushort minorSubsystemVersion = (ushort)0, System.Reflection.PortableExecutable.Subsystem subsystem = System.Reflection.PortableExecutable.Subsystem.WindowsCui, System.Reflection.PortableExecutable.DllCharacteristics dllCharacteristics = System.Reflection.PortableExecutable.DllCharacteristics.DynamicBase | System.Reflection.PortableExecutable.DllCharacteristics.NoSeh | System.Reflection.PortableExecutable.DllCharacteristics.NxCompatible | System.Reflection.PortableExecutable.DllCharacteristics.TerminalServerAware, System.Reflection.PortableExecutable.Characteristics imageCharacteristics = System.Reflection.PortableExecutable.Characteristics.Dll, ulong sizeOfStackReserve = (ulong)1048576, ulong sizeOfStackCommit = (ulong)4096, ulong sizeOfHeapReserve = (ulong)1048576, ulong sizeOfHeapCommit = (ulong)4096) { } + public PEHeaderBuilder(System.Reflection.PortableExecutable.Machine machine = System.Reflection.PortableExecutable.Machine.Unknown, int sectionAlignment = 8192, int fileAlignment = 512, ulong imageBase = (ulong)4194304, byte majorLinkerVersion = (byte)48, byte minorLinkerVersion = (byte)0, ushort majorOperatingSystemVersion = (ushort)4, ushort minorOperatingSystemVersion = (ushort)0, ushort majorImageVersion = (ushort)0, ushort minorImageVersion = (ushort)0, ushort majorSubsystemVersion = (ushort)4, ushort minorSubsystemVersion = (ushort)0, System.Reflection.PortableExecutable.Subsystem subsystem = System.Reflection.PortableExecutable.Subsystem.WindowsCui, System.Reflection.PortableExecutable.DllCharacteristics dllCharacteristics = System.Reflection.PortableExecutable.DllCharacteristics.DynamicBase | System.Reflection.PortableExecutable.DllCharacteristics.NoSeh | System.Reflection.PortableExecutable.DllCharacteristics.NxCompatible | System.Reflection.PortableExecutable.DllCharacteristics.TerminalServerAware, System.Reflection.PortableExecutable.Characteristics imageCharacteristics = System.Reflection.PortableExecutable.Characteristics.Dll, ulong sizeOfStackReserve = (ulong)0, ulong sizeOfStackCommit = (ulong)0, ulong sizeOfHeapReserve = (ulong)0, ulong sizeOfHeapCommit = (ulong)0) { } public System.Reflection.PortableExecutable.DllCharacteristics DllCharacteristics { get { throw null; } } public int FileAlignment { get { throw null; } } public ulong ImageBase { get { throw null; } } diff --git a/src/libraries/System.Reflection.Metadata/src/System/Reflection/PortableExecutable/PEHeaderBuilder.cs b/src/libraries/System.Reflection.Metadata/src/System/Reflection/PortableExecutable/PEHeaderBuilder.cs index b32a92677704d4..dce6457ae7c6da 100644 --- a/src/libraries/System.Reflection.Metadata/src/System/Reflection/PortableExecutable/PEHeaderBuilder.cs +++ b/src/libraries/System.Reflection.Metadata/src/System/Reflection/PortableExecutable/PEHeaderBuilder.cs @@ -59,10 +59,10 @@ public PEHeaderBuilder( Subsystem subsystem = Subsystem.WindowsCui, DllCharacteristics dllCharacteristics = DllCharacteristics.DynamicBase | DllCharacteristics.NxCompatible | DllCharacteristics.NoSeh | DllCharacteristics.TerminalServerAware, Characteristics imageCharacteristics = Characteristics.Dll, - ulong sizeOfStackReserve = 0x00100000, - ulong sizeOfStackCommit = 0x1000, - ulong sizeOfHeapReserve = 0x00100000, - ulong sizeOfHeapCommit = 0x1000) + ulong sizeOfStackReserve = 0, + ulong sizeOfStackCommit = 0, + ulong sizeOfHeapReserve = 0, + ulong sizeOfHeapCommit = 0) { if (fileAlignment < 512 || fileAlignment > 64 * 1024 || BitArithmetic.CountBits(fileAlignment) != 1) { @@ -89,10 +89,10 @@ public PEHeaderBuilder( Subsystem = subsystem; DllCharacteristics = dllCharacteristics; ImageCharacteristics = imageCharacteristics; - SizeOfStackReserve = sizeOfStackReserve; - SizeOfStackCommit = sizeOfStackCommit; - SizeOfHeapReserve = sizeOfHeapReserve; - SizeOfHeapCommit = sizeOfHeapCommit; + SizeOfStackReserve = sizeOfStackReserve == 0 ? (Is32Bit ? 0x1000u : 0x4000u) : sizeOfStackReserve; + SizeOfStackCommit = sizeOfStackCommit == 0 ? (Is32Bit ? 0x1000000u : 0x4000000u) : sizeOfStackCommit; + SizeOfHeapReserve = sizeOfHeapReserve == 0 ? 0x100000u : sizeOfHeapReserve; + SizeOfHeapCommit = sizeOfHeapCommit == 0 ? (Is32Bit ? 0x1000u : 0x2000u) : sizeOfHeapCommit; } public static PEHeaderBuilder CreateExecutableHeader() diff --git a/src/native/libs/System.Native/pal_threading.c b/src/native/libs/System.Native/pal_threading.c index c96c7e8abd558c..6e98ecb33a8089 100644 --- a/src/native/libs/System.Native/pal_threading.c +++ b/src/native/libs/System.Native/pal_threading.c @@ -233,6 +233,14 @@ int32_t SystemNative_CreateThread(uintptr_t stackSize, void *(*startAddress)(voi error = pthread_attr_setdetachstate(&attrs, PTHREAD_CREATE_DETACHED); assert(error == 0); +#ifdef HOST_OSX + // Match Windows stack size + if (stackSize == 0) + { + stackSize = 4096 * 1024; + } +#endif + if (stackSize > 0) { if (stackSize < (uintptr_t)PTHREAD_STACK_MIN) diff --git a/src/tests/Exceptions/ForeignThread/ForeignThreadExceptionsNative.cpp b/src/tests/Exceptions/ForeignThread/ForeignThreadExceptionsNative.cpp index d56d8d597c3f16..675094bfa74b3c 100644 --- a/src/tests/Exceptions/ForeignThread/ForeignThreadExceptionsNative.cpp +++ b/src/tests/Exceptions/ForeignThread/ForeignThreadExceptionsNative.cpp @@ -49,8 +49,8 @@ extern "C" DLL_EXPORT void InvokeCallbackOnNewThread(PFNACTION1 callback) int st = pthread_attr_init(&attr); AbortIfFail(st); - // set stack size to 1.5MB - st = pthread_attr_setstacksize(&attr, 0x180000); + // set stack size to 4.0MB + st = pthread_attr_setstacksize(&attr, 0x400000); AbortIfFail(st); pthread_t t; diff --git a/src/tests/Regressions/coreclr/GitHub_87879/test87879.cs b/src/tests/Regressions/coreclr/GitHub_87879/test87879.cs new file mode 100644 index 00000000000000..834d006db935f9 --- /dev/null +++ b/src/tests/Regressions/coreclr/GitHub_87879/test87879.cs @@ -0,0 +1,39 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System; +using System.Threading; +using System.Runtime.CompilerServices; + +class Program +{ + [SkipLocalsInit] + static int Main() + { + //determine the expected available stack size (4MB or 1MB), minus a little bit (384kB) for overhead. + var expectedSize = (IntPtr.Size == 8 ? 0x4_00000 : 0x1_00000) - 0x60000; + + //allocate 4MB, minus a little bit (512kB) for overhead + Span bytes = stackalloc byte[expectedSize]; + Consume(bytes); + Console.WriteLine("Main thread succeeded."); + + //repeat on a secondary thread + Thread t = new Thread([SkipLocalsInit] () => + { + Span bytes = stackalloc byte[expectedSize]; + Consume(bytes); + }); + t.Start(); + t.Join(); + Console.WriteLine("Secondary thread succeeded."); + + //success + return 100; + } + + [MethodImpl(MethodImplOptions.NoInlining)] + static void Consume(Span bytes) + { + } +} diff --git a/src/tests/Regressions/coreclr/GitHub_87879/test87879.csproj b/src/tests/Regressions/coreclr/GitHub_87879/test87879.csproj new file mode 100644 index 00000000000000..eada0c0465a6ee --- /dev/null +++ b/src/tests/Regressions/coreclr/GitHub_87879/test87879.csproj @@ -0,0 +1,11 @@ + + + Exe + true + true + false + + + + + diff --git a/src/tests/nativeaot/DesktopStackSize/DesktopStackSize.cs b/src/tests/nativeaot/DesktopStackSize/DesktopStackSize.cs new file mode 100644 index 00000000000000..92743186717703 --- /dev/null +++ b/src/tests/nativeaot/DesktopStackSize/DesktopStackSize.cs @@ -0,0 +1,42 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System; +using System.Threading; +using System.Runtime.CompilerServices; + +namespace DesktopStackSize +{ + class Program + { + [SkipLocalsInit] + static int Main() + { + //determine the expected available stack size (4MB or 1MB), minus a little bit (384kB) for overhead. + var expectedSize = (IntPtr.Size == 8 ? 0x4_00000 : 0x1_00000) - 0x60000; + + //allocate 4MB, minus a little bit (512kB) for overhead + Span bytes = stackalloc byte[expectedSize]; + Consume(bytes); + Console.WriteLine("Main thread succeeded."); + + //repeat on a secondary thread + Thread t = new Thread([SkipLocalsInit] () => + { + Span bytes = stackalloc byte[expectedSize]; + Consume(bytes); + }); + t.Start(); + t.Join(); + Console.WriteLine("Secondary thread succeeded."); + + //success + return 100; + } + + [MethodImpl(MethodImplOptions.NoInlining)] + static void Consume(Span bytes) + { + } + } +} diff --git a/src/tests/nativeaot/DesktopStackSize/DesktopStackSize.csproj b/src/tests/nativeaot/DesktopStackSize/DesktopStackSize.csproj new file mode 100644 index 00000000000000..b5800015514e8e --- /dev/null +++ b/src/tests/nativeaot/DesktopStackSize/DesktopStackSize.csproj @@ -0,0 +1,12 @@ + + + Exe + true + true + false + + + + + + From 2dbbfc9a5e64ca0c7c59a1c7c503a7acaedfe7f3 Mon Sep 17 00:00:00 2001 From: Hamish Arblaster Date: Tue, 6 Feb 2024 12:05:57 +1100 Subject: [PATCH 02/19] Fix test --- src/tests/Regressions/coreclr/GitHub_87879/test87879.cs | 9 ++++++--- .../Regressions/coreclr/GitHub_87879/test87879.csproj | 3 ++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/tests/Regressions/coreclr/GitHub_87879/test87879.cs b/src/tests/Regressions/coreclr/GitHub_87879/test87879.cs index 834d006db935f9..4ca24208a8265d 100644 --- a/src/tests/Regressions/coreclr/GitHub_87879/test87879.cs +++ b/src/tests/Regressions/coreclr/GitHub_87879/test87879.cs @@ -4,11 +4,14 @@ using System; using System.Threading; using System.Runtime.CompilerServices; +using Xunit; -class Program +namespace test87879; + +class test87879 { - [SkipLocalsInit] - static int Main() + [Fact, SkipLocalsInit] + public static int TestEntryPoint() { //determine the expected available stack size (4MB or 1MB), minus a little bit (384kB) for overhead. var expectedSize = (IntPtr.Size == 8 ? 0x4_00000 : 0x1_00000) - 0x60000; diff --git a/src/tests/Regressions/coreclr/GitHub_87879/test87879.csproj b/src/tests/Regressions/coreclr/GitHub_87879/test87879.csproj index eada0c0465a6ee..adca282bebe1ca 100644 --- a/src/tests/Regressions/coreclr/GitHub_87879/test87879.csproj +++ b/src/tests/Regressions/coreclr/GitHub_87879/test87879.csproj @@ -1,6 +1,7 @@ - Exe + + true true true false From 78e71351cdf40cc9b358159ab6a95a0f915bb9cb Mon Sep 17 00:00:00 2001 From: Hamish Arblaster Date: Tue, 6 Feb 2024 12:07:14 +1100 Subject: [PATCH 03/19] Revert changes to PEHeaderBuilder --- .../ref/System.Reflection.Metadata.cs | 5 +---- .../PortableExecutable/PEHeaderBuilder.cs | 18 +++++++++--------- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/src/libraries/System.Reflection.Metadata/ref/System.Reflection.Metadata.cs b/src/libraries/System.Reflection.Metadata/ref/System.Reflection.Metadata.cs index 0cc7573633775b..61314bfb7fd06c 100644 --- a/src/libraries/System.Reflection.Metadata/ref/System.Reflection.Metadata.cs +++ b/src/libraries/System.Reflection.Metadata/ref/System.Reflection.Metadata.cs @@ -3293,9 +3293,6 @@ public enum Machine : ushort Arm64 = (ushort)43620, LoongArch32 = (ushort)25138, LoongArch64 = (ushort)25188, - RiscV32 = (ushort)20530, - RiscV64 = (ushort)20580, - RiscV128 = (ushort)20776, } public partial class ManagedPEBuilder : System.Reflection.PortableExecutable.PEBuilder { @@ -3400,7 +3397,7 @@ internal PEHeader() { } } public sealed partial class PEHeaderBuilder { - public PEHeaderBuilder(System.Reflection.PortableExecutable.Machine machine = System.Reflection.PortableExecutable.Machine.Unknown, int sectionAlignment = 8192, int fileAlignment = 512, ulong imageBase = (ulong)4194304, byte majorLinkerVersion = (byte)48, byte minorLinkerVersion = (byte)0, ushort majorOperatingSystemVersion = (ushort)4, ushort minorOperatingSystemVersion = (ushort)0, ushort majorImageVersion = (ushort)0, ushort minorImageVersion = (ushort)0, ushort majorSubsystemVersion = (ushort)4, ushort minorSubsystemVersion = (ushort)0, System.Reflection.PortableExecutable.Subsystem subsystem = System.Reflection.PortableExecutable.Subsystem.WindowsCui, System.Reflection.PortableExecutable.DllCharacteristics dllCharacteristics = System.Reflection.PortableExecutable.DllCharacteristics.DynamicBase | System.Reflection.PortableExecutable.DllCharacteristics.NoSeh | System.Reflection.PortableExecutable.DllCharacteristics.NxCompatible | System.Reflection.PortableExecutable.DllCharacteristics.TerminalServerAware, System.Reflection.PortableExecutable.Characteristics imageCharacteristics = System.Reflection.PortableExecutable.Characteristics.Dll, ulong sizeOfStackReserve = (ulong)0, ulong sizeOfStackCommit = (ulong)0, ulong sizeOfHeapReserve = (ulong)0, ulong sizeOfHeapCommit = (ulong)0) { } + public PEHeaderBuilder(System.Reflection.PortableExecutable.Machine machine = System.Reflection.PortableExecutable.Machine.Unknown, int sectionAlignment = 8192, int fileAlignment = 512, ulong imageBase = (ulong)4194304, byte majorLinkerVersion = (byte)48, byte minorLinkerVersion = (byte)0, ushort majorOperatingSystemVersion = (ushort)4, ushort minorOperatingSystemVersion = (ushort)0, ushort majorImageVersion = (ushort)0, ushort minorImageVersion = (ushort)0, ushort majorSubsystemVersion = (ushort)4, ushort minorSubsystemVersion = (ushort)0, System.Reflection.PortableExecutable.Subsystem subsystem = System.Reflection.PortableExecutable.Subsystem.WindowsCui, System.Reflection.PortableExecutable.DllCharacteristics dllCharacteristics = System.Reflection.PortableExecutable.DllCharacteristics.DynamicBase | System.Reflection.PortableExecutable.DllCharacteristics.NoSeh | System.Reflection.PortableExecutable.DllCharacteristics.NxCompatible | System.Reflection.PortableExecutable.DllCharacteristics.TerminalServerAware, System.Reflection.PortableExecutable.Characteristics imageCharacteristics = System.Reflection.PortableExecutable.Characteristics.Dll, ulong sizeOfStackReserve = (ulong)1048576, ulong sizeOfStackCommit = (ulong)4096, ulong sizeOfHeapReserve = (ulong)1048576, ulong sizeOfHeapCommit = (ulong)4096) { } public System.Reflection.PortableExecutable.DllCharacteristics DllCharacteristics { get { throw null; } } public int FileAlignment { get { throw null; } } public ulong ImageBase { get { throw null; } } diff --git a/src/libraries/System.Reflection.Metadata/src/System/Reflection/PortableExecutable/PEHeaderBuilder.cs b/src/libraries/System.Reflection.Metadata/src/System/Reflection/PortableExecutable/PEHeaderBuilder.cs index dce6457ae7c6da..bd7f249b32e900 100644 --- a/src/libraries/System.Reflection.Metadata/src/System/Reflection/PortableExecutable/PEHeaderBuilder.cs +++ b/src/libraries/System.Reflection.Metadata/src/System/Reflection/PortableExecutable/PEHeaderBuilder.cs @@ -59,10 +59,10 @@ public PEHeaderBuilder( Subsystem subsystem = Subsystem.WindowsCui, DllCharacteristics dllCharacteristics = DllCharacteristics.DynamicBase | DllCharacteristics.NxCompatible | DllCharacteristics.NoSeh | DllCharacteristics.TerminalServerAware, Characteristics imageCharacteristics = Characteristics.Dll, - ulong sizeOfStackReserve = 0, - ulong sizeOfStackCommit = 0, - ulong sizeOfHeapReserve = 0, - ulong sizeOfHeapCommit = 0) + ulong sizeOfStackReserve = 0x00100000, + ulong sizeOfStackCommit = 0x1000, + ulong sizeOfHeapReserve = 0x00100000, + ulong sizeOfHeapCommit = 0x1000) { if (fileAlignment < 512 || fileAlignment > 64 * 1024 || BitArithmetic.CountBits(fileAlignment) != 1) { @@ -89,10 +89,10 @@ public PEHeaderBuilder( Subsystem = subsystem; DllCharacteristics = dllCharacteristics; ImageCharacteristics = imageCharacteristics; - SizeOfStackReserve = sizeOfStackReserve == 0 ? (Is32Bit ? 0x1000u : 0x4000u) : sizeOfStackReserve; - SizeOfStackCommit = sizeOfStackCommit == 0 ? (Is32Bit ? 0x1000000u : 0x4000000u) : sizeOfStackCommit; - SizeOfHeapReserve = sizeOfHeapReserve == 0 ? 0x100000u : sizeOfHeapReserve; - SizeOfHeapCommit = sizeOfHeapCommit == 0 ? (Is32Bit ? 0x1000u : 0x2000u) : sizeOfHeapCommit; + SizeOfStackReserve = sizeOfStackReserve; + SizeOfStackCommit = sizeOfStackCommit; + SizeOfHeapReserve = sizeOfHeapReserve; + SizeOfHeapCommit = sizeOfHeapCommit; } public static PEHeaderBuilder CreateExecutableHeader() @@ -105,7 +105,7 @@ public static PEHeaderBuilder CreateLibraryHeader() return new PEHeaderBuilder(imageCharacteristics: Characteristics.ExecutableImage | Characteristics.Dll); } - internal bool Is32Bit => Machine != Machine.Amd64 && Machine != Machine.IA64 && Machine != Machine.Arm64 && Machine != (Machine)0x5064; /* TODO: update with RiscV64 */ + internal bool Is32Bit => Machine != Machine.Amd64 && Machine != Machine.IA64 && Machine != Machine.Arm64; internal int ComputeSizeOfPEHeaders(int sectionCount) => PEBuilder.DosHeaderSize + From bc404d80306287c82d1316c469ef7a4d7e6c5f68 Mon Sep 17 00:00:00 2001 From: Hamish Arblaster Date: Tue, 6 Feb 2024 12:09:08 +1100 Subject: [PATCH 04/19] Revert the part of the reversion that wasn't a reversion? --- .../ref/System.Reflection.Metadata.cs | 3 +++ .../System/Reflection/PortableExecutable/PEHeaderBuilder.cs | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/libraries/System.Reflection.Metadata/ref/System.Reflection.Metadata.cs b/src/libraries/System.Reflection.Metadata/ref/System.Reflection.Metadata.cs index 61314bfb7fd06c..d656738565288c 100644 --- a/src/libraries/System.Reflection.Metadata/ref/System.Reflection.Metadata.cs +++ b/src/libraries/System.Reflection.Metadata/ref/System.Reflection.Metadata.cs @@ -3293,6 +3293,9 @@ public enum Machine : ushort Arm64 = (ushort)43620, LoongArch32 = (ushort)25138, LoongArch64 = (ushort)25188, + RiscV32 = (ushort)20530, + RiscV64 = (ushort)20580, + RiscV128 = (ushort)20776, } public partial class ManagedPEBuilder : System.Reflection.PortableExecutable.PEBuilder { diff --git a/src/libraries/System.Reflection.Metadata/src/System/Reflection/PortableExecutable/PEHeaderBuilder.cs b/src/libraries/System.Reflection.Metadata/src/System/Reflection/PortableExecutable/PEHeaderBuilder.cs index bd7f249b32e900..b32a92677704d4 100644 --- a/src/libraries/System.Reflection.Metadata/src/System/Reflection/PortableExecutable/PEHeaderBuilder.cs +++ b/src/libraries/System.Reflection.Metadata/src/System/Reflection/PortableExecutable/PEHeaderBuilder.cs @@ -105,7 +105,7 @@ public static PEHeaderBuilder CreateLibraryHeader() return new PEHeaderBuilder(imageCharacteristics: Characteristics.ExecutableImage | Characteristics.Dll); } - internal bool Is32Bit => Machine != Machine.Amd64 && Machine != Machine.IA64 && Machine != Machine.Arm64; + internal bool Is32Bit => Machine != Machine.Amd64 && Machine != Machine.IA64 && Machine != Machine.Arm64 && Machine != (Machine)0x5064; /* TODO: update with RiscV64 */ internal int ComputeSizeOfPEHeaders(int sectionCount) => PEBuilder.DosHeaderSize + From a473b2abd2e5de17f775b62a4db0bc7f43fc284b Mon Sep 17 00:00:00 2001 From: Hamish Arblaster Date: Tue, 6 Feb 2024 15:11:15 +1100 Subject: [PATCH 05/19] Change tests and fix for NAOT - Fix test definition - Fix NAOT apps stack size - Add `false` version of non-NAOT tests --- .../Microsoft.NETCore.Native.Windows.targets | 1 + .../Regressions/coreclr/GitHub_87879/test87879.cs | 7 ++----- .../GitHub_87879/test87879_nouseapphost.csproj | 13 +++++++++++++ 3 files changed, 16 insertions(+), 5 deletions(-) create mode 100644 src/tests/Regressions/coreclr/GitHub_87879/test87879_nouseapphost.csproj diff --git a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Windows.targets b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Windows.targets index d5d6c92077a4e6..127ad46b59e1f2 100644 --- a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Windows.targets +++ b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Windows.targets @@ -94,6 +94,7 @@ The .NET Foundation licenses this file to you under the MIT license. + diff --git a/src/tests/Regressions/coreclr/GitHub_87879/test87879.cs b/src/tests/Regressions/coreclr/GitHub_87879/test87879.cs index 4ca24208a8265d..686b67baf5657b 100644 --- a/src/tests/Regressions/coreclr/GitHub_87879/test87879.cs +++ b/src/tests/Regressions/coreclr/GitHub_87879/test87879.cs @@ -8,10 +8,10 @@ namespace test87879; -class test87879 +public class test87879 { [Fact, SkipLocalsInit] - public static int TestEntryPoint() + public static void TestEntryPoint() { //determine the expected available stack size (4MB or 1MB), minus a little bit (384kB) for overhead. var expectedSize = (IntPtr.Size == 8 ? 0x4_00000 : 0x1_00000) - 0x60000; @@ -30,9 +30,6 @@ public static int TestEntryPoint() t.Start(); t.Join(); Console.WriteLine("Secondary thread succeeded."); - - //success - return 100; } [MethodImpl(MethodImplOptions.NoInlining)] diff --git a/src/tests/Regressions/coreclr/GitHub_87879/test87879_nouseapphost.csproj b/src/tests/Regressions/coreclr/GitHub_87879/test87879_nouseapphost.csproj new file mode 100644 index 00000000000000..0f7ba15250a3c2 --- /dev/null +++ b/src/tests/Regressions/coreclr/GitHub_87879/test87879_nouseapphost.csproj @@ -0,0 +1,13 @@ + + + + true + true + false + true + false + + + + + From 8c235d9edee0503bd87a8ef5fbcdcaef6cb9be25 Mon Sep 17 00:00:00 2001 From: Hamish Arblaster Date: Tue, 6 Feb 2024 15:13:47 +1100 Subject: [PATCH 06/19] Fix tests - Pre-emptively move second test project to a seperate folder to avoid build issues --- .../test87879.csproj} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename src/tests/Regressions/coreclr/GitHub_87879/{test87879_nouseapphost.csproj => nouseapphost/test87879.csproj} (93%) diff --git a/src/tests/Regressions/coreclr/GitHub_87879/test87879_nouseapphost.csproj b/src/tests/Regressions/coreclr/GitHub_87879/nouseapphost/test87879.csproj similarity index 93% rename from src/tests/Regressions/coreclr/GitHub_87879/test87879_nouseapphost.csproj rename to src/tests/Regressions/coreclr/GitHub_87879/nouseapphost/test87879.csproj index 0f7ba15250a3c2..dce5cbbf3850f2 100644 --- a/src/tests/Regressions/coreclr/GitHub_87879/test87879_nouseapphost.csproj +++ b/src/tests/Regressions/coreclr/GitHub_87879/nouseapphost/test87879.csproj @@ -8,6 +8,6 @@ false - + From 48b0a2aadb944fb4e5027a0f10ada271eb0d5c4b Mon Sep 17 00:00:00 2001 From: Hamish Arblaster Date: Tue, 6 Feb 2024 18:32:46 +1100 Subject: [PATCH 07/19] Move UseAppHost=false test to another folder --- .../nouseapphost => GitHub_87879_NoAppHost}/test87879.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename src/tests/Regressions/coreclr/{GitHub_87879/nouseapphost => GitHub_87879_NoAppHost}/test87879.csproj (91%) diff --git a/src/tests/Regressions/coreclr/GitHub_87879/nouseapphost/test87879.csproj b/src/tests/Regressions/coreclr/GitHub_87879_NoAppHost/test87879.csproj similarity index 91% rename from src/tests/Regressions/coreclr/GitHub_87879/nouseapphost/test87879.csproj rename to src/tests/Regressions/coreclr/GitHub_87879_NoAppHost/test87879.csproj index dce5cbbf3850f2..c1061e99bcf99b 100644 --- a/src/tests/Regressions/coreclr/GitHub_87879/nouseapphost/test87879.csproj +++ b/src/tests/Regressions/coreclr/GitHub_87879_NoAppHost/test87879.csproj @@ -8,6 +8,6 @@ false - + From ace17209fd9ea47072539117b374dc4a3b56fa45 Mon Sep 17 00:00:00 2001 From: Hamish Arblaster Date: Wed, 7 Feb 2024 05:32:08 +1100 Subject: [PATCH 08/19] Change stack size to 1.5MB on all desktop platforms & re-enable some tests --- eng/native/configurecompiler.cmake | 2 +- .../BuildIntegration/Microsoft.NETCore.Native.Windows.targets | 2 +- src/coreclr/pal/src/init/pal.cpp | 4 ++-- src/native/libs/System.Native/pal_threading.c | 2 +- .../ForeignThread/ForeignThreadExceptionsNative.cpp | 4 ++-- src/tests/JIT/jit64/opt/cse/HugeArray1.csproj | 4 ---- src/tests/JIT/jit64/opt/cse/hugeSimpleExpr1.csproj | 4 ---- src/tests/JIT/jit64/opt/rngchk/RngchkStress2_o.csproj | 4 ---- src/tests/Regressions/coreclr/GitHub_87879/test87879.cs | 4 ++-- src/tests/nativeaot/DesktopStackSize/DesktopStackSize.cs | 4 ++-- 10 files changed, 11 insertions(+), 23 deletions(-) diff --git a/eng/native/configurecompiler.cmake b/eng/native/configurecompiler.cmake index 9fba9c2f5a7d48..166fd52ab96562 100644 --- a/eng/native/configurecompiler.cmake +++ b/eng/native/configurecompiler.cmake @@ -102,7 +102,7 @@ if (MSVC) if (CLR_CMAKE_ENABLE_SANITIZERS) set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /STACK:0x800000") else() - set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /STACK:0x400000") + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /STACK:0x180000") endif() if(EXISTS ${CLR_SOURCELINK_FILE_PATH}) diff --git a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Windows.targets b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Windows.targets index 127ad46b59e1f2..1ea0a9d1fb2391 100644 --- a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Windows.targets +++ b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Windows.targets @@ -94,7 +94,7 @@ The .NET Foundation licenses this file to you under the MIT license. - + diff --git a/src/coreclr/pal/src/init/pal.cpp b/src/coreclr/pal/src/init/pal.cpp index e560e00a4fc7e3..317e4113601127 100644 --- a/src/coreclr/pal/src/init/pal.cpp +++ b/src/coreclr/pal/src/init/pal.cpp @@ -292,7 +292,7 @@ InitializeDefaultStackSize() // Match Windows stack size if (g_defaultStackSize == 0) { - g_defaultStackSize = 4096 * 1024; + g_defaultStackSize = 1536 * 1024; } #endif @@ -301,7 +301,7 @@ InitializeDefaultStackSize() { // Set the default minimum stack size for MUSL to the same value as we // use on Windows. - g_defaultStackSize = 4096 * 1024; + g_defaultStackSize = 1536 * 1024; } #endif // ENSURE_PRIMARY_STACK_SIZE } diff --git a/src/native/libs/System.Native/pal_threading.c b/src/native/libs/System.Native/pal_threading.c index 6e98ecb33a8089..9520ed999f051c 100644 --- a/src/native/libs/System.Native/pal_threading.c +++ b/src/native/libs/System.Native/pal_threading.c @@ -237,7 +237,7 @@ int32_t SystemNative_CreateThread(uintptr_t stackSize, void *(*startAddress)(voi // Match Windows stack size if (stackSize == 0) { - stackSize = 4096 * 1024; + stackSize = 1536 * 1024; } #endif diff --git a/src/tests/Exceptions/ForeignThread/ForeignThreadExceptionsNative.cpp b/src/tests/Exceptions/ForeignThread/ForeignThreadExceptionsNative.cpp index 675094bfa74b3c..d56d8d597c3f16 100644 --- a/src/tests/Exceptions/ForeignThread/ForeignThreadExceptionsNative.cpp +++ b/src/tests/Exceptions/ForeignThread/ForeignThreadExceptionsNative.cpp @@ -49,8 +49,8 @@ extern "C" DLL_EXPORT void InvokeCallbackOnNewThread(PFNACTION1 callback) int st = pthread_attr_init(&attr); AbortIfFail(st); - // set stack size to 4.0MB - st = pthread_attr_setstacksize(&attr, 0x400000); + // set stack size to 1.5MB + st = pthread_attr_setstacksize(&attr, 0x180000); AbortIfFail(st); pthread_t t; diff --git a/src/tests/JIT/jit64/opt/cse/HugeArray1.csproj b/src/tests/JIT/jit64/opt/cse/HugeArray1.csproj index da12a89427f998..e6438b89c251b8 100644 --- a/src/tests/JIT/jit64/opt/cse/HugeArray1.csproj +++ b/src/tests/JIT/jit64/opt/cse/HugeArray1.csproj @@ -3,10 +3,6 @@ true true - - - true Full diff --git a/src/tests/JIT/jit64/opt/cse/hugeSimpleExpr1.csproj b/src/tests/JIT/jit64/opt/cse/hugeSimpleExpr1.csproj index 7ae624af5725c8..b32d6d0b3059be 100644 --- a/src/tests/JIT/jit64/opt/cse/hugeSimpleExpr1.csproj +++ b/src/tests/JIT/jit64/opt/cse/hugeSimpleExpr1.csproj @@ -4,10 +4,6 @@ true true - - - true Full diff --git a/src/tests/JIT/jit64/opt/rngchk/RngchkStress2_o.csproj b/src/tests/JIT/jit64/opt/rngchk/RngchkStress2_o.csproj index 88a3a33728468c..24e01e4305a860 100644 --- a/src/tests/JIT/jit64/opt/rngchk/RngchkStress2_o.csproj +++ b/src/tests/JIT/jit64/opt/rngchk/RngchkStress2_o.csproj @@ -2,10 +2,6 @@ PdbOnly True - - - true diff --git a/src/tests/Regressions/coreclr/GitHub_87879/test87879.cs b/src/tests/Regressions/coreclr/GitHub_87879/test87879.cs index 686b67baf5657b..c6aa05c9bf4d1a 100644 --- a/src/tests/Regressions/coreclr/GitHub_87879/test87879.cs +++ b/src/tests/Regressions/coreclr/GitHub_87879/test87879.cs @@ -13,8 +13,8 @@ public class test87879 [Fact, SkipLocalsInit] public static void TestEntryPoint() { - //determine the expected available stack size (4MB or 1MB), minus a little bit (384kB) for overhead. - var expectedSize = (IntPtr.Size == 8 ? 0x4_00000 : 0x1_00000) - 0x60000; + //determine the expected available stack size 1.5MB, minus a little bit (384kB) for overhead. + var expectedSize = 0x180000 - 0x60000; //allocate 4MB, minus a little bit (512kB) for overhead Span bytes = stackalloc byte[expectedSize]; diff --git a/src/tests/nativeaot/DesktopStackSize/DesktopStackSize.cs b/src/tests/nativeaot/DesktopStackSize/DesktopStackSize.cs index 92743186717703..b6c9c40a49deec 100644 --- a/src/tests/nativeaot/DesktopStackSize/DesktopStackSize.cs +++ b/src/tests/nativeaot/DesktopStackSize/DesktopStackSize.cs @@ -12,8 +12,8 @@ class Program [SkipLocalsInit] static int Main() { - //determine the expected available stack size (4MB or 1MB), minus a little bit (384kB) for overhead. - var expectedSize = (IntPtr.Size == 8 ? 0x4_00000 : 0x1_00000) - 0x60000; + //determine the expected available stack size 1.5MB, minus a little bit (384kB) for overhead. + var expectedSize = 0x180000 - 0x60000; //allocate 4MB, minus a little bit (512kB) for overhead Span bytes = stackalloc byte[expectedSize]; From 8ca1c969c068ebfac4abdc25ab1eee1455ae6be3 Mon Sep 17 00:00:00 2001 From: Hamish Arblaster Date: Wed, 7 Feb 2024 07:55:02 +1100 Subject: [PATCH 09/19] Re-enable some tests, and respect `IlcDefaultStackSize` on Windows - Re-enable disabled tests tracked by #1417 and #2084 - Make stack size configurable on NAOT via `IlcDefaultStackSize` on Windows --- .../BuildIntegration/Microsoft.NETCore.Native.Windows.targets | 3 ++- .../tests/DataContractSerializer.cs | 1 - .../System.Threading.Tasks.Tests/Task/TaskContinueWithTests.cs | 1 - 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Windows.targets b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Windows.targets index 1ea0a9d1fb2391..1224a0eb308140 100644 --- a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Windows.targets +++ b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Windows.targets @@ -94,7 +94,8 @@ The .NET Foundation licenses this file to you under the MIT license. - + + diff --git a/src/libraries/System.Runtime.Serialization.Xml/tests/DataContractSerializer.cs b/src/libraries/System.Runtime.Serialization.Xml/tests/DataContractSerializer.cs index 8a7acf0800596e..bbf437b40207ed 100644 --- a/src/libraries/System.Runtime.Serialization.Xml/tests/DataContractSerializer.cs +++ b/src/libraries/System.Runtime.Serialization.Xml/tests/DataContractSerializer.cs @@ -4475,7 +4475,6 @@ public static void DCS_TypeWithPrimitiveKnownTypes() Assert.NotNull(actual); } - [ActiveIssue("https://github.com/dotnet/runtime/issues/1417", TestPlatforms.OSX)] [SkipOnPlatform(TestPlatforms.Browser, "Causes a stack overflow")] [Fact] public static void DCS_DeeplyLinkedData() diff --git a/src/libraries/System.Runtime/tests/System.Threading.Tasks.Tests/Task/TaskContinueWithTests.cs b/src/libraries/System.Runtime/tests/System.Threading.Tasks.Tests/Task/TaskContinueWithTests.cs index b426a576d982be..7e204159fb19e6 100644 --- a/src/libraries/System.Runtime/tests/System.Threading.Tasks.Tests/Task/TaskContinueWithTests.cs +++ b/src/libraries/System.Runtime/tests/System.Threading.Tasks.Tests/Task/TaskContinueWithTests.cs @@ -1223,7 +1223,6 @@ public static void RunLazyCancellationTests_Negative() } [Fact] - [ActiveIssue("https://github.com/dotnet/runtime/issues/2084", TestRuntimes.Mono)] public static void LongContinuationChain_ContinueWith_DoesNotStackOverflow() { const int DiveDepth = 12_000; From 2abc0cd69265f350761593c1db2f609c95646043 Mon Sep 17 00:00:00 2001 From: Hamish Arblaster Date: Wed, 7 Feb 2024 08:12:30 +1100 Subject: [PATCH 10/19] Fix comments --- src/tests/Regressions/coreclr/GitHub_87879/test87879.cs | 2 +- src/tests/nativeaot/DesktopStackSize/DesktopStackSize.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/tests/Regressions/coreclr/GitHub_87879/test87879.cs b/src/tests/Regressions/coreclr/GitHub_87879/test87879.cs index c6aa05c9bf4d1a..7eb42eb899124e 100644 --- a/src/tests/Regressions/coreclr/GitHub_87879/test87879.cs +++ b/src/tests/Regressions/coreclr/GitHub_87879/test87879.cs @@ -16,7 +16,7 @@ public static void TestEntryPoint() //determine the expected available stack size 1.5MB, minus a little bit (384kB) for overhead. var expectedSize = 0x180000 - 0x60000; - //allocate 4MB, minus a little bit (512kB) for overhead + //allocate on the stack as specified above Span bytes = stackalloc byte[expectedSize]; Consume(bytes); Console.WriteLine("Main thread succeeded."); diff --git a/src/tests/nativeaot/DesktopStackSize/DesktopStackSize.cs b/src/tests/nativeaot/DesktopStackSize/DesktopStackSize.cs index b6c9c40a49deec..dbb76661f571da 100644 --- a/src/tests/nativeaot/DesktopStackSize/DesktopStackSize.cs +++ b/src/tests/nativeaot/DesktopStackSize/DesktopStackSize.cs @@ -15,7 +15,7 @@ static int Main() //determine the expected available stack size 1.5MB, minus a little bit (384kB) for overhead. var expectedSize = 0x180000 - 0x60000; - //allocate 4MB, minus a little bit (512kB) for overhead + //allocate on the stack as specified above Span bytes = stackalloc byte[expectedSize]; Consume(bytes); Console.WriteLine("Main thread succeeded."); From 7bc3c70ac3d5f25ae6334f72b7fc9c360c3fa65d Mon Sep 17 00:00:00 2001 From: Hamish Arblaster Date: Wed, 7 Feb 2024 18:58:37 +1100 Subject: [PATCH 11/19] Apply feedback, up stack size on Mac Catalyst, disable (expected) failing test, fix a test - Apply feedback for `IlcDefaultStackSize` - Change secondary thread stack size on Mac Catalyst to match macOS, and enable tests for it (on non-mono platforms, it's already 2MB on mono) - Skip `LongContinuationChain_ContinueWith_DoesNotStackOverflow` on browser - Instead of distinct `false` test, have a distinct `true` test, since `src/tests/Directory.Build.props` changes it to false --- .../BuildIntegration/Microsoft.NETCore.Native.Unix.targets | 2 +- .../BuildIntegration/Microsoft.NETCore.Native.Windows.targets | 4 ++-- src/coreclr/pal/src/init/pal.cpp | 2 +- .../Task/TaskContinueWithTests.cs | 1 + src/native/libs/System.Native/pal_threading.c | 2 +- src/tests/Regressions/coreclr/GitHub_87879/test87879.csproj | 2 +- .../test87879.csproj | 4 ++-- src/tests/nativeaot/DesktopStackSize/DesktopStackSize.csproj | 2 +- 8 files changed, 10 insertions(+), 9 deletions(-) rename src/tests/Regressions/coreclr/{GitHub_87879_NoAppHost => GitHub_87879_AppHost}/test87879.csproj (75%) diff --git a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets index 1b38cbd3efa379..8e8bde2b450924 100644 --- a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets +++ b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets @@ -23,7 +23,7 @@ The .NET Foundation licenses this file to you under the MIT license. lld lld bfd - 1572864 + 1572864 diff --git a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Windows.targets b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Windows.targets index 1224a0eb308140..5209a194cffce4 100644 --- a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Windows.targets +++ b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Windows.targets @@ -33,6 +33,7 @@ The .NET Foundation licenses this file to you under the MIT license. CONSOLE eventpipe-disabled eventpipe-enabled + 1572864 @@ -94,8 +95,7 @@ The .NET Foundation licenses this file to you under the MIT license. - - + diff --git a/src/coreclr/pal/src/init/pal.cpp b/src/coreclr/pal/src/init/pal.cpp index 317e4113601127..bef3f1d64165e0 100644 --- a/src/coreclr/pal/src/init/pal.cpp +++ b/src/coreclr/pal/src/init/pal.cpp @@ -288,7 +288,7 @@ InitializeDefaultStackSize() } } -#ifdef HOST_OSX +#if defined(HOST_OSX) || defined(HOST_MACCATALYST) // Match Windows stack size if (g_defaultStackSize == 0) { diff --git a/src/libraries/System.Runtime/tests/System.Threading.Tasks.Tests/Task/TaskContinueWithTests.cs b/src/libraries/System.Runtime/tests/System.Threading.Tasks.Tests/Task/TaskContinueWithTests.cs index 7e204159fb19e6..2800a5e9e24c46 100644 --- a/src/libraries/System.Runtime/tests/System.Threading.Tasks.Tests/Task/TaskContinueWithTests.cs +++ b/src/libraries/System.Runtime/tests/System.Threading.Tasks.Tests/Task/TaskContinueWithTests.cs @@ -1223,6 +1223,7 @@ public static void RunLazyCancellationTests_Negative() } [Fact] + [SkipOnPlatform(TestPlatforms.Browser, "Causes a stack overflow")] public static void LongContinuationChain_ContinueWith_DoesNotStackOverflow() { const int DiveDepth = 12_000; diff --git a/src/native/libs/System.Native/pal_threading.c b/src/native/libs/System.Native/pal_threading.c index 9520ed999f051c..29ed92526f8384 100644 --- a/src/native/libs/System.Native/pal_threading.c +++ b/src/native/libs/System.Native/pal_threading.c @@ -233,7 +233,7 @@ int32_t SystemNative_CreateThread(uintptr_t stackSize, void *(*startAddress)(voi error = pthread_attr_setdetachstate(&attrs, PTHREAD_CREATE_DETACHED); assert(error == 0); -#ifdef HOST_OSX +#if defined(HOST_OSX) || defined(HOST_MACCATALYST) // Match Windows stack size if (stackSize == 0) { diff --git a/src/tests/Regressions/coreclr/GitHub_87879/test87879.csproj b/src/tests/Regressions/coreclr/GitHub_87879/test87879.csproj index adca282bebe1ca..066a4d6aa6e095 100644 --- a/src/tests/Regressions/coreclr/GitHub_87879/test87879.csproj +++ b/src/tests/Regressions/coreclr/GitHub_87879/test87879.csproj @@ -4,7 +4,7 @@ true true true - false + false diff --git a/src/tests/Regressions/coreclr/GitHub_87879_NoAppHost/test87879.csproj b/src/tests/Regressions/coreclr/GitHub_87879_AppHost/test87879.csproj similarity index 75% rename from src/tests/Regressions/coreclr/GitHub_87879_NoAppHost/test87879.csproj rename to src/tests/Regressions/coreclr/GitHub_87879_AppHost/test87879.csproj index c1061e99bcf99b..42e66acc955d4f 100644 --- a/src/tests/Regressions/coreclr/GitHub_87879_NoAppHost/test87879.csproj +++ b/src/tests/Regressions/coreclr/GitHub_87879_AppHost/test87879.csproj @@ -3,9 +3,9 @@ true true - false + true true - false + false diff --git a/src/tests/nativeaot/DesktopStackSize/DesktopStackSize.csproj b/src/tests/nativeaot/DesktopStackSize/DesktopStackSize.csproj index b5800015514e8e..0149169ae7f863 100644 --- a/src/tests/nativeaot/DesktopStackSize/DesktopStackSize.csproj +++ b/src/tests/nativeaot/DesktopStackSize/DesktopStackSize.csproj @@ -3,7 +3,7 @@ Exe true true - false + false From 499ff8c3d28dbbab763cfe60811c092bd9c6e77c Mon Sep 17 00:00:00 2001 From: Hamish Arblaster Date: Wed, 7 Feb 2024 19:48:37 +1100 Subject: [PATCH 12/19] Update AppHost test to only run on Windows --- .../Regressions/coreclr/GitHub_87879_AppHost/test87879.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tests/Regressions/coreclr/GitHub_87879_AppHost/test87879.csproj b/src/tests/Regressions/coreclr/GitHub_87879_AppHost/test87879.csproj index 42e66acc955d4f..ca34e2fd52bd87 100644 --- a/src/tests/Regressions/coreclr/GitHub_87879_AppHost/test87879.csproj +++ b/src/tests/Regressions/coreclr/GitHub_87879_AppHost/test87879.csproj @@ -5,7 +5,7 @@ true true true - false + false From 08ceb1b23c538b33188d80f19d61b9242badd318 Mon Sep 17 00:00:00 2001 From: Hamish Arblaster Date: Wed, 7 Feb 2024 20:36:30 +1100 Subject: [PATCH 13/19] Disable building AppHost test on unsupported platforms --- .../Regressions/coreclr/GitHub_87879_AppHost/test87879.csproj | 1 + 1 file changed, 1 insertion(+) diff --git a/src/tests/Regressions/coreclr/GitHub_87879_AppHost/test87879.csproj b/src/tests/Regressions/coreclr/GitHub_87879_AppHost/test87879.csproj index ca34e2fd52bd87..fbca696431178b 100644 --- a/src/tests/Regressions/coreclr/GitHub_87879_AppHost/test87879.csproj +++ b/src/tests/Regressions/coreclr/GitHub_87879_AppHost/test87879.csproj @@ -6,6 +6,7 @@ true true false + $(CLRTestTargetUnsupported) From 2773a79088f169c3bfcc3590d3fff484d9361bc6 Mon Sep 17 00:00:00 2001 From: Hamish Arblaster Date: Thu, 8 Feb 2024 07:24:27 +1100 Subject: [PATCH 14/19] Increase stack size for all apple platforms, remove unnecessary comment --- src/coreclr/pal/src/init/pal.cpp | 2 +- src/native/libs/System.Native/pal_threading.c | 2 +- src/tests/Regressions/coreclr/GitHub_87879/test87879.csproj | 1 - .../Regressions/coreclr/GitHub_87879_AppHost/test87879.csproj | 1 - 4 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/coreclr/pal/src/init/pal.cpp b/src/coreclr/pal/src/init/pal.cpp index bef3f1d64165e0..606bd5311522cd 100644 --- a/src/coreclr/pal/src/init/pal.cpp +++ b/src/coreclr/pal/src/init/pal.cpp @@ -288,7 +288,7 @@ InitializeDefaultStackSize() } } -#if defined(HOST_OSX) || defined(HOST_MACCATALYST) +#ifdef HOST_APPLE // Match Windows stack size if (g_defaultStackSize == 0) { diff --git a/src/native/libs/System.Native/pal_threading.c b/src/native/libs/System.Native/pal_threading.c index 29ed92526f8384..975e94acc476db 100644 --- a/src/native/libs/System.Native/pal_threading.c +++ b/src/native/libs/System.Native/pal_threading.c @@ -233,7 +233,7 @@ int32_t SystemNative_CreateThread(uintptr_t stackSize, void *(*startAddress)(voi error = pthread_attr_setdetachstate(&attrs, PTHREAD_CREATE_DETACHED); assert(error == 0); -#if defined(HOST_OSX) || defined(HOST_MACCATALYST) +#ifdef HOST_APPLE // Match Windows stack size if (stackSize == 0) { diff --git a/src/tests/Regressions/coreclr/GitHub_87879/test87879.csproj b/src/tests/Regressions/coreclr/GitHub_87879/test87879.csproj index 066a4d6aa6e095..92c701a53d18ad 100644 --- a/src/tests/Regressions/coreclr/GitHub_87879/test87879.csproj +++ b/src/tests/Regressions/coreclr/GitHub_87879/test87879.csproj @@ -1,6 +1,5 @@ - true true true diff --git a/src/tests/Regressions/coreclr/GitHub_87879_AppHost/test87879.csproj b/src/tests/Regressions/coreclr/GitHub_87879_AppHost/test87879.csproj index fbca696431178b..db44548fa13285 100644 --- a/src/tests/Regressions/coreclr/GitHub_87879_AppHost/test87879.csproj +++ b/src/tests/Regressions/coreclr/GitHub_87879_AppHost/test87879.csproj @@ -1,6 +1,5 @@ - true true true From 99f07de0d4f7c5e0b7364d2d4e75ce7c18c0229f Mon Sep 17 00:00:00 2001 From: Hamish Arblaster Date: Thu, 8 Feb 2024 07:29:32 +1100 Subject: [PATCH 15/19] Test if AppHost variant is running on Windows --- src/tests/Regressions/coreclr/GitHub_87879/test87879.cs | 5 +++++ .../coreclr/GitHub_87879_AppHost/test87879.csproj | 1 + 2 files changed, 6 insertions(+) diff --git a/src/tests/Regressions/coreclr/GitHub_87879/test87879.cs b/src/tests/Regressions/coreclr/GitHub_87879/test87879.cs index 7eb42eb899124e..c287bff5c93633 100644 --- a/src/tests/Regressions/coreclr/GitHub_87879/test87879.cs +++ b/src/tests/Regressions/coreclr/GitHub_87879/test87879.cs @@ -15,6 +15,11 @@ public static void TestEntryPoint() { //determine the expected available stack size 1.5MB, minus a little bit (384kB) for overhead. var expectedSize = 0x180000 - 0x60000; +#if INTENTIONALLY_FAIL + Console.WriteLine(System.Diagnostics.Process.GetCurrentProcess().MainModule!.FileName); + object o = null; + o.ToString(); +#endif //allocate on the stack as specified above Span bytes = stackalloc byte[expectedSize]; diff --git a/src/tests/Regressions/coreclr/GitHub_87879_AppHost/test87879.csproj b/src/tests/Regressions/coreclr/GitHub_87879_AppHost/test87879.csproj index db44548fa13285..9854a79b4c5a44 100644 --- a/src/tests/Regressions/coreclr/GitHub_87879_AppHost/test87879.csproj +++ b/src/tests/Regressions/coreclr/GitHub_87879_AppHost/test87879.csproj @@ -6,6 +6,7 @@ true false $(CLRTestTargetUnsupported) + $(DefineConstants);INTENTIONALLY_FAIL From 9bd87cf9d7df8def33bb546e2940f0ec0bdedc84 Mon Sep 17 00:00:00 2001 From: Hamish Arblaster Date: Thu, 8 Feb 2024 11:42:19 +1100 Subject: [PATCH 16/19] Try running GitHub_87879_AppHost test on same platforms as GitHub_87879 --- .../coreclr/GitHub_87879_AppHost/test87879.csproj | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/tests/Regressions/coreclr/GitHub_87879_AppHost/test87879.csproj b/src/tests/Regressions/coreclr/GitHub_87879_AppHost/test87879.csproj index 9854a79b4c5a44..fff6ab5bdb69d6 100644 --- a/src/tests/Regressions/coreclr/GitHub_87879_AppHost/test87879.csproj +++ b/src/tests/Regressions/coreclr/GitHub_87879_AppHost/test87879.csproj @@ -4,8 +4,9 @@ true true true - false - $(CLRTestTargetUnsupported) + false + true + false $(DefineConstants);INTENTIONALLY_FAIL From 9a249f05972d7b7532a975d686299b9d71698981 Mon Sep 17 00:00:00 2001 From: Hamish Arblaster Date: Thu, 8 Feb 2024 17:46:16 +1100 Subject: [PATCH 17/19] Rename test87879_AppHost.csproj --- .../{test87879.csproj => test87879_AppHost.csproj} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/tests/Regressions/coreclr/GitHub_87879_AppHost/{test87879.csproj => test87879_AppHost.csproj} (100%) diff --git a/src/tests/Regressions/coreclr/GitHub_87879_AppHost/test87879.csproj b/src/tests/Regressions/coreclr/GitHub_87879_AppHost/test87879_AppHost.csproj similarity index 100% rename from src/tests/Regressions/coreclr/GitHub_87879_AppHost/test87879.csproj rename to src/tests/Regressions/coreclr/GitHub_87879_AppHost/test87879_AppHost.csproj From 63c610865f34810fa081cb6b4a481a65aa4cbf08 Mon Sep 17 00:00:00 2001 From: Hamish Arblaster Date: Sat, 10 Feb 2024 05:04:32 +1100 Subject: [PATCH 18/19] Remove AppHost test, and update test projects to run on all Apple platforms --- .../Regressions/coreclr/GitHub_87879/test87879.cs | 5 ----- .../coreclr/GitHub_87879/test87879.csproj | 2 +- .../GitHub_87879_AppHost/test87879_AppHost.csproj | 15 --------------- .../DesktopStackSize/DesktopStackSize.csproj | 2 +- 4 files changed, 2 insertions(+), 22 deletions(-) delete mode 100644 src/tests/Regressions/coreclr/GitHub_87879_AppHost/test87879_AppHost.csproj diff --git a/src/tests/Regressions/coreclr/GitHub_87879/test87879.cs b/src/tests/Regressions/coreclr/GitHub_87879/test87879.cs index c287bff5c93633..7eb42eb899124e 100644 --- a/src/tests/Regressions/coreclr/GitHub_87879/test87879.cs +++ b/src/tests/Regressions/coreclr/GitHub_87879/test87879.cs @@ -15,11 +15,6 @@ public static void TestEntryPoint() { //determine the expected available stack size 1.5MB, minus a little bit (384kB) for overhead. var expectedSize = 0x180000 - 0x60000; -#if INTENTIONALLY_FAIL - Console.WriteLine(System.Diagnostics.Process.GetCurrentProcess().MainModule!.FileName); - object o = null; - o.ToString(); -#endif //allocate on the stack as specified above Span bytes = stackalloc byte[expectedSize]; diff --git a/src/tests/Regressions/coreclr/GitHub_87879/test87879.csproj b/src/tests/Regressions/coreclr/GitHub_87879/test87879.csproj index 92c701a53d18ad..fdd2160133b6b4 100644 --- a/src/tests/Regressions/coreclr/GitHub_87879/test87879.csproj +++ b/src/tests/Regressions/coreclr/GitHub_87879/test87879.csproj @@ -3,7 +3,7 @@ true true true - false + false diff --git a/src/tests/Regressions/coreclr/GitHub_87879_AppHost/test87879_AppHost.csproj b/src/tests/Regressions/coreclr/GitHub_87879_AppHost/test87879_AppHost.csproj deleted file mode 100644 index fff6ab5bdb69d6..00000000000000 --- a/src/tests/Regressions/coreclr/GitHub_87879_AppHost/test87879_AppHost.csproj +++ /dev/null @@ -1,15 +0,0 @@ - - - true - true - true - true - false - true - false - $(DefineConstants);INTENTIONALLY_FAIL - - - - - diff --git a/src/tests/nativeaot/DesktopStackSize/DesktopStackSize.csproj b/src/tests/nativeaot/DesktopStackSize/DesktopStackSize.csproj index 0149169ae7f863..5c384b20e99400 100644 --- a/src/tests/nativeaot/DesktopStackSize/DesktopStackSize.csproj +++ b/src/tests/nativeaot/DesktopStackSize/DesktopStackSize.csproj @@ -3,7 +3,7 @@ Exe true true - false + false From 3cf73dc065e76fb979333724a0807f54e6bdf6b5 Mon Sep 17 00:00:00 2001 From: Hamish Arblaster Date: Sat, 10 Feb 2024 18:40:49 +1100 Subject: [PATCH 19/19] Apply feedback - Remove the NAOT specific test, since NAOT runs for the main test also --- .../DesktopStackSize/DesktopStackSize.cs | 42 ------------------- .../DesktopStackSize/DesktopStackSize.csproj | 12 ------ 2 files changed, 54 deletions(-) delete mode 100644 src/tests/nativeaot/DesktopStackSize/DesktopStackSize.cs delete mode 100644 src/tests/nativeaot/DesktopStackSize/DesktopStackSize.csproj diff --git a/src/tests/nativeaot/DesktopStackSize/DesktopStackSize.cs b/src/tests/nativeaot/DesktopStackSize/DesktopStackSize.cs deleted file mode 100644 index dbb76661f571da..00000000000000 --- a/src/tests/nativeaot/DesktopStackSize/DesktopStackSize.cs +++ /dev/null @@ -1,42 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -using System; -using System.Threading; -using System.Runtime.CompilerServices; - -namespace DesktopStackSize -{ - class Program - { - [SkipLocalsInit] - static int Main() - { - //determine the expected available stack size 1.5MB, minus a little bit (384kB) for overhead. - var expectedSize = 0x180000 - 0x60000; - - //allocate on the stack as specified above - Span bytes = stackalloc byte[expectedSize]; - Consume(bytes); - Console.WriteLine("Main thread succeeded."); - - //repeat on a secondary thread - Thread t = new Thread([SkipLocalsInit] () => - { - Span bytes = stackalloc byte[expectedSize]; - Consume(bytes); - }); - t.Start(); - t.Join(); - Console.WriteLine("Secondary thread succeeded."); - - //success - return 100; - } - - [MethodImpl(MethodImplOptions.NoInlining)] - static void Consume(Span bytes) - { - } - } -} diff --git a/src/tests/nativeaot/DesktopStackSize/DesktopStackSize.csproj b/src/tests/nativeaot/DesktopStackSize/DesktopStackSize.csproj deleted file mode 100644 index 5c384b20e99400..00000000000000 --- a/src/tests/nativeaot/DesktopStackSize/DesktopStackSize.csproj +++ /dev/null @@ -1,12 +0,0 @@ - - - Exe - true - true - false - - - - - -