From a1a5ad8d70464534228839ad8f1f2a7938cb9524 Mon Sep 17 00:00:00 2001 From: Rainer Schuetze Date: Sun, 4 Mar 2018 09:57:32 +0100 Subject: [PATCH] fix issue 18547 - Win32: throwing exception in fiber crashes application increase the default stack size because exception handling might need up to 16k. The actually used stack can depend on the version of DbgHelp.dll, the existence of debug information and possibly other conditions. --- src/core/thread.d | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/core/thread.d b/src/core/thread.d index b00871f07a..07afc68788 100644 --- a/src/core/thread.d +++ b/src/core/thread.d @@ -4071,6 +4071,14 @@ class Fiber // Initialization /////////////////////////////////////////////////////////////////////////// + version(Windows) + // exception handling walks the stack, invoking DbgHelp.dll which + // needs up to 16k of stack space depending on the version of DbgHelp.dll, + // the existence of debug symbols and other conditions. Avoid causing + // stack overflows by defaulting to a larger stack size + enum defaultStackPages = 8; + else + enum defaultStackPages = 4; /** * Initializes a fiber object which is associated with a static @@ -4087,7 +4095,7 @@ class Fiber * In: * fn must not be null. */ - this( void function() fn, size_t sz = PAGESIZE*4, + this( void function() fn, size_t sz = PAGESIZE * defaultStackPages, size_t guardPageSize = PAGESIZE ) nothrow in { @@ -4115,7 +4123,7 @@ class Fiber * In: * dg must not be null. */ - this( void delegate() dg, size_t sz = PAGESIZE*4, + this( void delegate() dg, size_t sz = PAGESIZE * defaultStackPages, size_t guardPageSize = PAGESIZE ) nothrow in { @@ -4123,7 +4131,7 @@ class Fiber } do { - allocStack( sz, guardPageSize); + allocStack( sz, guardPageSize ); reset( dg ); }