This repository has been archived by the owner on Jan 30, 2023. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
175 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,175 @@ | ||
diff --git a/src/aclocal.m4 b/src/aclocal.m4 | ||
index 6adc5c63d7c60cf34ac7cee372158d617143191b..cf011efd016a20d5685c12bbac7d1d731eaa755e 100644 | ||
--- a/src/aclocal.m4 | ||
+++ b/src/aclocal.m4 | ||
@@ -665,6 +665,21 @@ case "${ECL_STACK_DIR}" in | ||
up|UP) AC_MSG_RESULT(no) ;; | ||
*) AC_MSG_ERROR(Unable to determine stack growth direction) | ||
esac]) | ||
+ | ||
+dnl | ||
+dnl -------------------------------------------------------------- | ||
+dnl Check if we can determine the stack size at runtime | ||
+dnl | ||
+AC_DEFUN(ECL_STACK_SIZE,[ | ||
+AC_CHECK_HEADER([sys/resource.h], | ||
+ [AC_DEFINE([HAVE_SYS_RESOURCE_H], [], [Define to 1 if you have the <sys/resource.h> header file.]) | ||
+ AC_CHECK_DECL([RLIMIT_STACK], | ||
+ [AC_DEFINE([ECL_CAN_SET_STACK_SIZE], [], [Define to 1 if we can set the stack size at runtime.])], | ||
+ [], | ||
+ [#include <sys/resource.h>])], | ||
+ [],[]) | ||
+]) | ||
+ | ||
dnl | ||
dnl ------------------------------------------------------------ | ||
dnl Find out a setjmp() that does not save signals. It is called | ||
diff --git a/src/c/stacks.d b/src/c/stacks.d | ||
index d985766ba5e03b07d6a25e31e9880576250038aa..c0125ed2bc8ec9d1712e5e71f3c91edb1bc7c12a 100644 | ||
--- a/src/c/stacks.d | ||
+++ b/src/c/stacks.d | ||
@@ -29,7 +29,7 @@ cs_set_size(cl_env_ptr env, cl_index new_size) | ||
{ | ||
volatile char foo = 0; | ||
cl_index margin = ecl_option_values[ECL_OPT_C_STACK_SAFETY_AREA]; | ||
-#if defined(HAVE_SYS_RESOURCE_H) && defined(RLIMIT_STACK) && !defined(NACL) | ||
+#if defined(ECL_CAN_SET_STACK_SIZE) | ||
{ | ||
struct rlimit rl; | ||
|
||
@@ -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"); | ||
} | ||
+ } 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; | ||
+ env->cs_barrier = env->cs_org - new_size; | ||
#else | ||
- env->cs_barrier = env->cs_org + new_size; | ||
+ 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; | ||
} | ||
|
||
diff --git a/src/configure b/src/configure | ||
index 103f4102be537c5521889ad14f7d4151245bd4b2..b2e7608887d1d0648c80578dea26a50ff9a945c0 100755 | ||
--- a/src/configure | ||
+++ b/src/configure | ||
@@ -7125,7 +7125,7 @@ fi | ||
done | ||
|
||
|
||
-for ac_header in sys/resource.h sys/utsname.h float.h pwd.h dlfcn.h link.h \ | ||
+for ac_header in sys/utsname.h float.h pwd.h dlfcn.h link.h \ | ||
mach-o/dyld.h dirent.h sys/ioctl.h sys/select.h \ | ||
sys/wait.h semaphore.h | ||
do : | ||
@@ -8345,6 +8345,24 @@ $as_echo "no" >&6; } ;; | ||
*) as_fn_error $? "Unable to determine stack growth direction" "$LINENO" 5 | ||
esac | ||
|
||
+ac_fn_c_check_header_mongrel "$LINENO" "sys/resource.h" "ac_cv_header_sys_resource_h" "$ac_includes_default" | ||
+if test "x$ac_cv_header_sys_resource_h" = xyes; then : | ||
+ | ||
+$as_echo "#define HAVE_SYS_RESOURCE_H /**/" >>confdefs.h | ||
+ | ||
+ ac_fn_c_check_decl "$LINENO" "RLIMIT_STACK" "ac_cv_have_decl_RLIMIT_STACK" "#include <sys/resource.h> | ||
+" | ||
+if test "x$ac_cv_have_decl_RLIMIT_STACK" = xyes; then : | ||
+ | ||
+$as_echo "#define ECL_CAN_SET_STACK_SIZE /**/" >>confdefs.h | ||
+ | ||
+fi | ||
+ | ||
+fi | ||
+ | ||
+ | ||
+ | ||
+ | ||
|
||
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether closedir returns void" >&5 | ||
$as_echo_n "checking whether closedir returns void... " >&6; } | ||
@@ -8997,8 +9015,6 @@ main () | ||
if (*(data + i) != *(data3 + i)) | ||
return 14; | ||
close (fd); | ||
- free (data); | ||
- free (data3); | ||
return 0; | ||
} | ||
_ACEOF | ||
diff --git a/src/configure.ac b/src/configure.ac | ||
index 4e615408e7b336329b4228cb40ca820f12adacba..8103d88bc9b2abe24ebef83db4ea36355c947fc6 100644 | ||
--- a/src/configure.ac | ||
+++ b/src/configure.ac | ||
@@ -658,7 +658,7 @@ AC_CHECK_HEADERS( [fcntl.h limits.h netdb.h netinet/in.h] \ | ||
[sched.h] ) | ||
dnl !!! end autoscan | ||
|
||
-AC_CHECK_HEADERS( [sys/resource.h sys/utsname.h float.h pwd.h dlfcn.h link.h] \ | ||
+AC_CHECK_HEADERS( [sys/utsname.h float.h pwd.h dlfcn.h link.h] \ | ||
[mach-o/dyld.h dirent.h sys/ioctl.h sys/select.h] \ | ||
[sys/wait.h semaphore.h] ) | ||
|
||
@@ -711,8 +711,9 @@ ECL_SSE | ||
ECL_COMPLEX_C99 | ||
|
||
dnl ----------------------------------------------------------------------- | ||
-dnl Study the call conventions | ||
+dnl Stack size and growth direction | ||
ECL_STACK_DIRECTION | ||
+ECL_STACK_SIZE | ||
|
||
dnl ===================================================================== | ||
dnl Checks for library functions | ||
diff --git a/src/ecl/configpre.h b/src/ecl/configpre.h | ||
index 98f96bd653052014ef612cfcfcd87a08557979fd..aeda058e059d07d07d9c903f647e74f8dfe30c7a 100644 | ||
--- a/src/ecl/configpre.h | ||
+++ b/src/ecl/configpre.h | ||
@@ -9,6 +9,9 @@ | ||
/* ECL_AVOID_FPE_H */ | ||
#undef ECL_AVOID_FPE_H | ||
|
||
+/* Define to 1 if we can set the stack size at runtime. */ | ||
+#undef ECL_CAN_SET_STACK_SIZE | ||
+ | ||
/* Allow STREAM operations to work on arbitrary objects */ | ||
#undef ECL_CLOS_STREAMS | ||
|
||
diff --git a/src/h/config-internal.h.in b/src/h/config-internal.h.in | ||
index dd7a4f8ad0e86fb735333c4794665d4520fbf830..6b4438ad5953971952ac26328c5c2a3e0f898eff 100644 | ||
--- a/src/h/config-internal.h.in | ||
+++ b/src/h/config-internal.h.in | ||
@@ -240,7 +240,10 @@ | ||
#include "@ECL_LIBFFI_HEADER@" | ||
#endif | ||
|
||
-#if defined(HAVE_SYS_RESOURCE_H) && defined(RLIMIT_STACK) && !defined(NACL) | ||
+/* Can we determine and set the stack size at runtime? */ | ||
+#undef ECL_CAN_SET_STACK_SIZE | ||
+ | ||
+#if defined(ECL_CAN_SET_STACK_SIZE) | ||
#define ECL_DEFAULT_C_STACK_SIZE 0 /* Use the stack size provided by the OS */ | ||
#else | ||
#define ECL_DEFAULT_C_STACK_SIZE @ECL_DEFAULT_C_STACK_SIZE@ |