lua: Increase reserved stack space for FreeBSD in debug config

FreeBSD uses more stack space in debug configurations and can overflow
the stack while formatting the error message when the call depth limit
of 20 frames is reached.  This is readily reproduced by running the
gsub recursion test with increased kstack size.  I hit the panic with
16 pages per kstack, and noticed it go away when bumped to 17.

Reserve an additional 64 bytes on the stack when building for FreeBSD.
This is enough to avoid the panic with a deep stack while not wasting
too much space when the default stack size is used.

Reviewed-by: Matt Ahrens <matt@delphix.com>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Ryan Moeller <ryan@iXsystems.com>
Closes #10634
This commit is contained in:
Ryan Moeller 2020-07-31 12:17:37 -04:00 committed by GitHub
parent 24f98ed383
commit 25499e2139
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -126,7 +126,16 @@ typedef LUAI_UACNUMBER l_uacNumber;
* Minimum amount of available stack space (in bytes) to make a C call. With * Minimum amount of available stack space (in bytes) to make a C call. With
* gsub() recursion, the stack space between each luaD_call() is 1256 bytes. * gsub() recursion, the stack space between each luaD_call() is 1256 bytes.
*/ */
#if defined(__FreeBSD__)
/*
* FreeBSD needs a few extra bytes in unoptimized debug builds to avoid a
* double-fault handling the error when the max call depth is exceeded just
* before the C stack runs out. 64 bytes seems to do the trick.
*/
#define LUAI_MINCSTACK 4160
#else
#define LUAI_MINCSTACK 4096 #define LUAI_MINCSTACK 4096
#endif
/* /*
** maximum number of upvalues in a closure (both C and Lua). (Value ** maximum number of upvalues in a closure (both C and Lua). (Value