Subject: 25.0.50; Incomplete recovery from stack overflow

From: Ken Brown <[email-masked]>
Date: Mon, 06 Jul 2015 16:41:54 -0400

Cygwin has just implemented an alternate stack in its development trunk,
and I've been testing it by seeing if emacs can recover from a stack
overflow (see handle_sigsegv() in sysdep.c).  This isn't working as I
expect, and I don't know if it's a Cygwin problem or an emacs problem.
(For starters, it would help if someone would try to reproduce it on
GNU/Linux.)

To reproduce the problem, run 'emacs -Q' and then force a stack overflow
as suggested in 
https://lists.gnu.org/archive/html/emacs-devel/2014-08/msg00481.html, 
i.e., by evaluating the following:

(setq max-specpdl-size 83200000
       max-lisp-eval-depth 640000)
(defun foo () (foo))
(foo)

When I do this, handle_sigsegv is called and I get the message
"Re-entering top level after C stack overflow", as expected.  But if I
then type 'C-x d', I get an immediate crash with the following
backtrace:

Program received signal SIGSEGV, Segmentation fault.
0x000000010053aff0 in SDATA (string=-2338913020442312704)
at ../../master/src/lisp.h:1281
1281      return XSTRING (string)->data;
(gdb) bt full
#0  0x000000010053aff0 in SDATA (string=-2338913020442312704)
at ../../master/src/lisp.h:1281
No locals.
#1  0x0000000100628636 in unmark_byte_stack ()
at ../../master/src/bytecode.c:380
stack = 0x100df8a63 <bss_sbrk_buffer+3748003>
#2  0x00000001005c0bcb in garbage_collect_1 (end=0x82b838)
at ../../master/src/alloc.c:5735
nextb = 0x0
stack_top_variable = 0 '\000'
i = 585
message_p = false
count = 17
start = {
tv_sec = 1436214527,
tv_nsec = 316292100
}
retval = 0
tot_before = 0
total = {25782979923, 25782959104, 8565584, 45696, 8566592,
4300451200, 4305864144, 0, 8566624, 4300451200}
#3  0x00000001005c1208 in Fgarbage_collect () at 
../../master/src/alloc.c:5937
end = 0x82b838
#4  0x0000000000000000 in ?? ()
No symbol table info available.
Backtrace stopped: previous frame inner to this frame (corrupt stack?)

Lisp Backtrace:
"Automatic GC" (0x0)
"autoload-do-load" (0x82c0c0)
"command-execute" (0x82c628)

And handle_sigsegv can't do anything about this because garbage
collection is in process.  So we haven't really made a complete recovery 
from the stack overflow.

In GNU Emacs 25.0.50.15 (x86_64-unknown-cygwin, GTK+ Version 3.14.13)
  of 2015-07-06 on moufang
Repository revision: f3480939ffccf7a72b060b4fc21dd85b55f535f6
Windowing system distributor `The Cygwin/X Project', version 11.0.11701000
Configured using:
  `configure 'CFLAGS=-g3 -O0''

Configured features:
XPM JPEG TIFF GIF PNG RSVG IMAGEMAGICK SOUND DBUS GSETTINGS NOTIFY ACL
GNUTLS LIBXML2 FREETYPE M17N_FLT LIBOTF XFT ZLIB TOOLKIT_SCROLL_BARS
GTK3 X11

Important settings:
   value of $LANG: en_US.UTF-8
   locale-coding-system: utf-8-unix

Major mode: Lisp Interaction

Minor modes in effect:
   tooltip-mode: t
   global-eldoc-mode: t
   electric-indent-mode: t
   mouse-wheel-mode: t
   tool-bar-mode: t
   menu-bar-mode: t
   file-name-shadow-mode: t
   global-font-lock-mode: t
   font-lock-mode: t
   blink-cursor-mode: t
   auto-composition-mode: t
   auto-encryption-mode: t
   auto-compression-mode: t
   line-number-mode: t
   transient-mark-mode: t

Recent messages:
For information about GNU Emacs and the GNU system, type C-h C-a.

Load-path shadows:
None found.

Features:
(shadow sort gnus-util mail-extr emacsbug message dired format-spec
rfc822 mml easymenu mml-sec mm-decode mm-bodies mm-encode mail-parse
rfc2231 mailabbrev gmm-utils mailheader sendmail rfc2047 rfc2045
ietf-drums mm-util help-fns cl-loaddefs pcase cl-lib mail-prsvr
mail-utils time-date mule-util tooltip eldoc electric uniquify
ediff-hook vc-hooks lisp-float-type mwheel x-win term/common-win x-dnd
tool-bar dnd fontset image regexp-opt fringe tabulated-list newcomment
elisp-mode lisp-mode prog-mode register page menu-bar rfn-eshadow timer
select scroll-bar mouse jit-lock font-lock syntax facemenu font-core
frame cl-generic cham georgian utf-8-lang misc-lang vietnamese tibetan
thai tai-viet lao korean japanese eucjp-ms cp51932 hebrew greek romanian
slovak czech european ethiopic indian cyrillic chinese charscript
case-table epa-hook jka-cmpr-hook help simple abbrev minibuffer
cl-preloaded nadvice loaddefs button faces cus-face macroexp files
text-properties overlay sha1 md5 base64 format env code-pages mule
custom widget hashtable-print-readable backquote dbusbind gfilenotify
dynamic-setting system-font-setting font-render-setting move-toolbar gtk
x-toolkit x multi-tty make-network-process emacs)