diff options
author | Xavier Leroy <xavier.leroy@inria.fr> | 2011-12-20 14:38:53 +0000 |
---|---|---|
committer | Xavier Leroy <xavier.leroy@inria.fr> | 2011-12-20 14:38:53 +0000 |
commit | a69f9be8c5fd60296550ffb23de9a2e9d4c372e4 (patch) | |
tree | c51bc599c18c98325309cd34f214bd81529c6c64 | |
parent | d0667f4e52167a4a415d29f76289750cf9515652 (diff) |
PR#4746: wrong detection of stack overflows in native code under Linux
(quick fix, will have to find something better)
testsuite/tests/runtime-errors: make the test output independent of
the stack size; add a "ulimit -s" just to make sure stack is limited.
testsuite/tests/asmcomp: updated to compile again.
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@11898 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
-rw-r--r-- | asmrun/signals_asm.c | 11 | ||||
-rw-r--r-- | testsuite/tests/asmcomp/Makefile | 1 | ||||
-rw-r--r-- | testsuite/tests/runtime-errors/Makefile | 3 | ||||
-rw-r--r-- | testsuite/tests/runtime-errors/stackoverflow.bytecode.reference | 5 | ||||
-rw-r--r-- | testsuite/tests/runtime-errors/stackoverflow.ml | 2 | ||||
-rw-r--r-- | testsuite/tests/runtime-errors/stackoverflow.native.reference | 65 |
6 files changed, 17 insertions, 70 deletions
diff --git a/asmrun/signals_asm.c b/asmrun/signals_asm.c index 5b3f9955e..556bd945b 100644 --- a/asmrun/signals_asm.c +++ b/asmrun/signals_asm.c @@ -175,6 +175,15 @@ DECLARE_SIGNAL_HANDLER(trap_handler) static char * system_stack_top; static char sig_alt_stack[SIGSTKSZ]; +#if defined(SYS_linux) +/* PR#4746: recent Linux kernels with support for stack randomization + silently add 2 Mb of stack space on top of RLIMIT_STACK. + 2 Mb = 0x200000, to which we add 8 kB (=0x2000) for overshoot. */ +#define EXTRA_STACK 0x202000 +#else +#define EXTRA_STACK 0x2000 +#endif + DECLARE_SIGNAL_HANDLER(segv_handler) { struct rlimit limit; @@ -189,7 +198,7 @@ DECLARE_SIGNAL_HANDLER(segv_handler) if (((uintnat) fault_addr & (sizeof(intnat) - 1)) == 0 && getrlimit(RLIMIT_STACK, &limit) == 0 && fault_addr < system_stack_top - && fault_addr >= system_stack_top - limit.rlim_cur - 0x2000 + && fault_addr >= system_stack_top - limit.rlim_cur - EXTRA_STACK #ifdef CONTEXT_PC && Is_in_code_area(CONTEXT_PC) #endif diff --git a/testsuite/tests/asmcomp/Makefile b/testsuite/tests/asmcomp/Makefile index 0883e2cd5..20a69148a 100644 --- a/testsuite/tests/asmcomp/Makefile +++ b/testsuite/tests/asmcomp/Makefile @@ -17,7 +17,6 @@ OTHEROBJS=\ $(TOPDIR)/utils/ccomp.cmo \ $(TOPDIR)/utils/warnings.cmo \ $(TOPDIR)/utils/consistbl.cmo \ - $(TOPDIR)/parsing/linenum.cmo \ $(TOPDIR)/parsing/location.cmo \ $(TOPDIR)/parsing/longident.cmo \ $(TOPDIR)/parsing/syntaxerr.cmo \ diff --git a/testsuite/tests/runtime-errors/Makefile b/testsuite/tests/runtime-errors/Makefile index 551b82d39..63f63c9e7 100644 --- a/testsuite/tests/runtime-errors/Makefile +++ b/testsuite/tests/runtime-errors/Makefile @@ -12,7 +12,8 @@ compile: fi run: - @for f in *.bytecode; do \ + @ulimit -s 1024; \ + for f in *.bytecode; do \ printf " ... testing '$$f':"; \ (./$$f > $$f.result 2>&1; true); \ diff -q $$f.reference $$f.result > /dev/null || (echo " => failed" && exit 1) && echo " => passed"; \ diff --git a/testsuite/tests/runtime-errors/stackoverflow.bytecode.reference b/testsuite/tests/runtime-errors/stackoverflow.bytecode.reference index 745f81aef..a5bbdea33 100644 --- a/testsuite/tests/runtime-errors/stackoverflow.bytecode.reference +++ b/testsuite/tests/runtime-errors/stackoverflow.bytecode.reference @@ -1,5 +1,4 @@ -x = 196608 -x = 131072 -x = 65536 +x = 20000 +x = 10000 x = 0 Stack overflow caught diff --git a/testsuite/tests/runtime-errors/stackoverflow.ml b/testsuite/tests/runtime-errors/stackoverflow.ml index 4d211bc82..ab53b8b06 100644 --- a/testsuite/tests/runtime-errors/stackoverflow.ml +++ b/testsuite/tests/runtime-errors/stackoverflow.ml @@ -1,5 +1,5 @@ let rec f x = - if x land 0xFFFF <> 0 + if not (x = 0 || x = 10000 || x = 20000) then 1 + f (x + 1) else try diff --git a/testsuite/tests/runtime-errors/stackoverflow.native.reference b/testsuite/tests/runtime-errors/stackoverflow.native.reference index 835095c58..a5bbdea33 100644 --- a/testsuite/tests/runtime-errors/stackoverflow.native.reference +++ b/testsuite/tests/runtime-errors/stackoverflow.native.reference @@ -1,65 +1,4 @@ -x = 4128768 -x = 4063232 -x = 3997696 -x = 3932160 -x = 3866624 -x = 3801088 -x = 3735552 -x = 3670016 -x = 3604480 -x = 3538944 -x = 3473408 -x = 3407872 -x = 3342336 -x = 3276800 -x = 3211264 -x = 3145728 -x = 3080192 -x = 3014656 -x = 2949120 -x = 2883584 -x = 2818048 -x = 2752512 -x = 2686976 -x = 2621440 -x = 2555904 -x = 2490368 -x = 2424832 -x = 2359296 -x = 2293760 -x = 2228224 -x = 2162688 -x = 2097152 -x = 2031616 -x = 1966080 -x = 1900544 -x = 1835008 -x = 1769472 -x = 1703936 -x = 1638400 -x = 1572864 -x = 1507328 -x = 1441792 -x = 1376256 -x = 1310720 -x = 1245184 -x = 1179648 -x = 1114112 -x = 1048576 -x = 983040 -x = 917504 -x = 851968 -x = 786432 -x = 720896 -x = 655360 -x = 589824 -x = 524288 -x = 458752 -x = 393216 -x = 327680 -x = 262144 -x = 196608 -x = 131072 -x = 65536 +x = 20000 +x = 10000 x = 0 Stack overflow caught |