From 5f68e6d69fe734565cf64705d93a99546a88f97c Mon Sep 17 00:00:00 2001 From: PoweredByPie Date: Thu, 23 May 2024 03:54:35 -0700 Subject: [PATCH] Get max stack size in `setStackSize` to match Linux --- src/libutil/current-process.cc | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/libutil/current-process.cc b/src/libutil/current-process.cc index db3111560..9efb68d47 100644 --- a/src/libutil/current-process.cc +++ b/src/libutil/current-process.cc @@ -82,19 +82,23 @@ void setStackSize(size_t stackSize) } } #else + ULONG_PTR stackLow, stackHigh; + GetCurrentThreadStackLimits(&stackLow, &stackHigh); + ULONG maxStackSize = stackHigh - stackLow; ULONG currStackSize = 0; // This retrieves the current promised stack size SetThreadStackGuarantee(&currStackSize); if (currStackSize < stackSize) { savedStackSize = currStackSize; - ULONG newStackSize = stackSize; + ULONG newStackSize = std::min(static_cast(stackSize), maxStackSize); if (SetThreadStackGuarantee(&newStackSize) == 0) { logger->log( lvlError, HintFmt( - "Failed to increase stack size from %1% to %2%: %3%", + "Failed to increase stack size from %1% to %2% (maximum allowed stack size: %3%): %4%", savedStackSize, stackSize, + maxStackSize, std::to_string(GetLastError()) ).str() );