unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Eli Zaretskii <eliz@gnu.org>
To: Constantine Vetoshev <vetoshev@gmail.com>
Cc: 32338@debbugs.gnu.org, alan@idiocy.org, npostavs@gmail.com
Subject: bug#32338: 26.1; term.el broken on macOS
Date: Wed, 03 Oct 2018 17:59:14 +0300	[thread overview]
Message-ID: <83k1mz2i0t.fsf@gnu.org> (raw)
In-Reply-To: <CA+CaSqqRR62QNqpKN-ssHXPoD3cd_tV0+iOfrc5VWYcG3_rP9w@mail.gmail.com> (message from Constantine Vetoshev on Tue, 2 Oct 2018 15:51:11 -0700)

> From: Constantine Vetoshev <vetoshev@gmail.com>
> Date: Tue, 2 Oct 2018 15:51:11 -0700
> Cc: Alan Third <alan@idiocy.org>, Noam Postavsky <npostavs@gmail.com>, 32338@debbugs.gnu.org
> 
> One change from my past reports: after compiling Emacs with -g flags,
> I have now managed to reproduce the crash under lldb, including
> attaching to the forked process which eats CPU after the crash.
> Backtrace from that process is attached.

Great, thanks.

> The highlights (as far as I noticed) are:
> - emacs_re_max_failures and the older re_max_failures are not
> initialized at this point

I believe this is incorrect.  re_max_failures is statically assigned a
value of 40000 in regex-emacs.c, and should be initialized at link
time.  Your build is with optimizations, isn't it?  I think the
optimizer reordered instructions, which creates the illusion that
re_max_failures has a garbled value at that point.  The value of
newlim, 10022912, is correct, you can confirm that by calculating it
by hand assuming that re_max_failures is 40000 and using the other
values your debugging session shows.

> - in the working branch, newlim is reset to rlim.rlim_max; in the
> broken branch, it is not
> - in the working branch, setrlimit does not get called; in the broken
> branch, it does

Right.

> I'm guessing the problem is with the uninitialized values for
> *_re_max_failures and the resulting values being assigned to lim and
> newlim. It seems to only work on the working branch by accident
> because, for whatever reason, newlim always gets reset to
> rlim.rlim_max and setrlimit doesn't get called.

No, I think the problem is with this line:

   > 884            if (pagesize <= newlim - lim)

In your case newlim is smaller than lim, but rlim_t is an unsigned
data type on your system, so the subtraction wraps around and produces
a large positive value, which then tricks Emacs into thinking it needs
to enlarge the stack, whereas in reality the stack space already
available, 67MB, is large enough.  (Btw, that value sounds too large,
I wonder if it's some problem with getrlimit on your system.)

So please try the patch below with the emacs-26 branch, and see if the
problem goes away.

diff --git a/src/emacs.c b/src/emacs.c
index 483e848..c0b4bd9 100644
--- a/src/emacs.c
+++ b/src/emacs.c
@@ -875,7 +875,8 @@ main (int argc, char **argv)
 	    newlim = rlim.rlim_max;
 	  newlim -= newlim % pagesize;
 
-	  if (pagesize <= newlim - lim)
+	  if (newlim > lim	/* in case rlim_t is an unsigned type */
+	      && pagesize <= newlim - lim)
 	    {
 	      rlim.rlim_cur = newlim;
 	      if (setrlimit (RLIMIT_STACK, &rlim) == 0)
@@ -884,9 +885,9 @@ main (int argc, char **argv)
 	}
       /* If the stack is big enough, let regex.c more of it before
          falling back to heap allocation.  */
-      emacs_re_safe_alloca = max
-        (min (lim - extra, SIZE_MAX) * (min_ratio / ratio),
-         MAX_ALLOCA);
+      emacs_re_safe_alloca =
+	max (min (min (0, lim - extra), SIZE_MAX) * (min_ratio / ratio),
+	     MAX_ALLOCA);
     }
 #endif /* HAVE_SETRLIMIT and RLIMIT_STACK and not CYGWIN */
 





  reply	other threads:[~2018-10-03 14:59 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-07-31 19:29 bug#32338: 26.1; term.el broken on macOS Constantine Vetoshev
2018-09-19 23:30 ` Noam Postavsky
2018-09-20 14:15   ` Constantine Vetoshev
2018-09-21  0:35     ` Noam Postavsky
2018-09-22 18:12       ` Constantine Vetoshev
2018-09-22 22:14         ` Noam Postavsky
2018-09-23  5:42           ` Eli Zaretskii
2018-09-29 23:52             ` Constantine Vetoshev
2018-09-30  5:59               ` Eli Zaretskii
2018-09-30 15:25                 ` Constantine Vetoshev
2018-09-30 17:13                   ` Eli Zaretskii
2018-10-02 22:51                     ` Constantine Vetoshev
2018-10-03 14:59                       ` Eli Zaretskii [this message]
2018-10-03 19:21                         ` Constantine Vetoshev
2018-10-04 16:15                           ` Eli Zaretskii
2018-09-30  9:16               ` Alan Third

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=83k1mz2i0t.fsf@gnu.org \
    --to=eliz@gnu.org \
    --cc=32338@debbugs.gnu.org \
    --cc=alan@idiocy.org \
    --cc=npostavs@gmail.com \
    --cc=vetoshev@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).