summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2021-07-04 09:53:29 -0700
committerKaz Kylheku <kaz@kylheku.com>2021-07-04 09:53:29 -0700
commit9d8a89af69dfa46c7b74c2ffe049a5deddd67274 (patch)
tree3c194a7dffbf0b83ee6322cfa6b7797261dd5392
parentdcc42a5204f97efaf3f99e14a117fbb7720ad515 (diff)
downloadtxr-9d8a89af69dfa46c7b74c2ffe049a5deddd67274.tar.gz
txr-9d8a89af69dfa46c7b74c2ffe049a5deddd67274.tar.bz2
txr-9d8a89af69dfa46c7b74c2ffe049a5deddd67274.zip
stack-limit: bug: not handling RLIM_INFINITY.
* gc.c (gc_init): We must check rlim_cur for the RLIM_INFINITY value indicating unlimited stack, and not misuse this value as a limit number, otherwise hilarity ensues. This reproduced on an older platform with make 3.81, which calls setrlimit to bring about an unlimited stack, passed on to child processes. Because of this txr segfaulted, as a consequence of a false positive. * tests/012/stack.tl (stack-limited): New variable which indicates whether there is a stack limit. If there isn't, we avoid running the fork-based test case. Also, we set the stack limit to 32768 so we have a limit against which to run some of the tests.
-rw-r--r--gc.c2
-rw-r--r--tests/012/stack.tl15
2 files changed, 10 insertions, 7 deletions
diff --git a/gc.c b/gc.c
index 4b7c0a8c..ee47f054 100644
--- a/gc.c
+++ b/gc.c
@@ -896,7 +896,7 @@ void gc_init(val *stack_bottom)
#if HAVE_RLIMIT
struct rlimit rl;
if (getrlimit(RLIMIT_STACK, &rl) == 0) {
- if (rl.rlim_cur > 512 * 1024) {
+ 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;
}
diff --git a/tests/012/stack.tl b/tests/012/stack.tl
index 879d3d27..9a7534bb 100644
--- a/tests/012/stack.tl
+++ b/tests/012/stack.tl
@@ -1,5 +1,7 @@
(load "../common")
+(defvar stack-limited (set-stack-limit 32768))
+
(defun recur () (recur))
(defmacro so (expr)
@@ -8,12 +10,13 @@
(test (so (recur)) :so)
-(test (let ((pid (fork)))
- (cond
- ((zerop pid) (set-stack-limit 0) (recur))
- (t (let ((status (wait pid)))
- (w-ifsignaled status)))))
- t)
+(if stack-limited
+ (test (let ((pid (fork)))
+ (cond
+ ((zerop pid) (set-stack-limit 0) (recur))
+ (t (let ((status (wait pid)))
+ (w-ifsignaled status)))))
+ t))
(defmacro infexp ()
^(foo (infexp)))