mirror of
https://gitlab.com/embeddable-common-lisp/ecl.git
synced 2026-01-23 13:01:42 -08:00
stacks: introduce sensible behaviour if getrlimit fails
If getrlimit fails, new_size may be zero. Furthermore, getrlimit may also return RLIM_INFINITY in which case new_size is way to large. In both cases the real stack size is unknown and we can only use some sensible default.
This commit is contained in:
parent
90043d205c
commit
370e1969d8
1 changed files with 16 additions and 7 deletions
|
|
@ -40,13 +40,22 @@ cs_set_size(cl_env_ptr env, cl_index new_size)
|
|||
if (setrlimit(RLIMIT_STACK, &rl))
|
||||
ecl_internal_error("Can't set the size of the C stack");
|
||||
}
|
||||
new_size = rl.rlim_cur;
|
||||
#ifdef ECL_DOWN_STACK
|
||||
env->cs_barrier = env->cs_org - new_size;
|
||||
#else
|
||||
env->cs_barrier = env->cs_org + new_size;
|
||||
#endif
|
||||
} else {
|
||||
rl.rlim_cur = new_size;
|
||||
}
|
||||
if (rl.rlim_cur == 0 || rl.rlim_cur == RLIM_INFINITY || rl.rlim_cur > (cl_index)(-1)) {
|
||||
/* Either getrlimit failed or returned nonsense, either way we
|
||||
* don't know the stack size. Use a default of 1 MB and hope for
|
||||
* the best. */
|
||||
new_size = 1048576;
|
||||
} else {
|
||||
new_size = rl.rlim_cur;
|
||||
}
|
||||
#ifdef ECL_DOWN_STACK
|
||||
env->cs_barrier = env->cs_org - new_size;
|
||||
#else
|
||||
env->cs_barrier = env->cs_org + new_size;
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
env->cs_limit_size = new_size - (2*margin);
|
||||
|
|
@ -64,7 +73,7 @@ cs_set_size(cl_env_ptr env, cl_index new_size)
|
|||
}
|
||||
#endif
|
||||
else
|
||||
ecl_internal_error("Can't set the size of the C stack");
|
||||
ecl_internal_error("Can't set the size of the C stack: sanity check failed");
|
||||
env->cs_size = new_size;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue