diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2021-07-04 11:20:29 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2021-07-04 11:20:29 -0700 |
commit | c29914feda17397ff5bcd0065c0ec029e8292c94 (patch) | |
tree | f82e21e2553459f4639b4f2eb10b4f89a62a5e25 | |
parent | ebca89d000e512851b4f06e5f478635ee70b3f19 (diff) | |
download | txr-c29914feda17397ff5bcd0065c0ec029e8292c94.tar.gz txr-c29914feda17397ff5bcd0065c0ec029e8292c94.tar.bz2 txr-c29914feda17397ff5bcd0065c0ec029e8292c94.zip |
stack-limit: impose minimum limit.
* gc.c (MIN_STACK_LIMIT): New preprocessor symbol.
(gc_init): If the system stack limit is too low, don't
treat that the same way as a missing or unlimited limit.
Instead clamp to the minimum value and hope for the best.
So that is to say, the system limit cannot be used as a
mechanism to set a ridiculously low stack limit in TXR; the
only way to do that is to use the set-stack-limit function.
* txr.1: Documentation updated. Also fixed 326767 typo which
should be 32767.
-rw-r--r-- | gc.c | 12 | ||||
-rw-r--r-- | txr.1 | 14 |
2 files changed, 18 insertions, 8 deletions
@@ -28,6 +28,7 @@ #include <stdio.h> #include <stdlib.h> #include <stdarg.h> +#include <stddef.h> #include <assert.h> #include <wchar.h> #include <signal.h> @@ -68,6 +69,8 @@ #define DFL_STACK_LIMIT (16384 * 1024L) #endif +#define MIN_STACK_LIMIT 32768 + #if HAVE_MEMALIGN || HAVE_POSIX_MEMALIGN #define OBJ_ALIGN (sizeof (obj_t)) #else @@ -899,9 +902,12 @@ void gc_init(val *stack_bottom) #if HAVE_RLIMIT struct rlimit rl; if (getrlimit(RLIMIT_STACK, &rl) == 0) { - if (rl.rlim_cur != RLIM_INFINITY && rl.rlim_cur > 512 * 1024) { - rlim_t lim = (rl.rlim_cur - rl.rlim_cur / 16) / sizeof (val); - gc_stack_limit = gc_stack_bottom - lim; + rlim_t lim = rl.rlim_cur; + if (lim != RLIM_INFINITY) { + ptrdiff_t delta = (lim >= MIN_STACK_LIMIT + ? (lim - lim / 16) + : MIN_STACK_LIMIT) / sizeof (val); + gc_stack_limit = gc_stack_bottom - delta; } } #endif @@ -72734,11 +72734,15 @@ derived from .codn error , is thrown. -The stack overflow guard mechanism is enabled at startup on those platforms -where it is possible to inquire the system about the stack limit, and where the -stack limit is at least 512 kilobytes. \*(TX configures the limit to within a +The stack overflow guard mechanism is configured on start-up. +On platforms on those platforms where it is possible to +inquire the system about the actual stack limit, and where the stack limit is +at least 512 kilobytes, \*(TX sets the limit to within a certain percentage of the actual value. If it is not possible to determine the -system's stack limit, or it is too low, then the mechanism is disabled. +system's stack limit, or if the system indicates that the stack size is +unlimited, then a default limit is imposed. If the system's limit is +configured below a certain small value, then that small value is used +as the stack limit. The .code get-stack-limit @@ -72794,7 +72798,7 @@ of the stack overflow detection mechanism is compromised. Likewise, if .meta value is too low, the operation of \*(TX shall become unreliable. Values -smaller than 326767 bytes are strongly discouraged. +smaller than 32767 bytes are strongly discouraged. .SS* Modularization .coNP Variable @ self-path |