all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Paul Eggert <eggert@cs.ucla.edu>
To: Eli Zaretskii <eliz@gnu.org>
Cc: lekktu@gmail.com, 12446@debbugs.gnu.org
Subject: bug#12446: port better to POSIX hosts lacking _setjmp
Date: Sat, 15 Sep 2012 00:50:17 -0700	[thread overview]
Message-ID: <50543339.3090500@cs.ucla.edu> (raw)
In-Reply-To: <83sjaju5ca.fsf@gnu.org>

On 09/15/2012 12:12 AM, Eli Zaretskii wrote:
> On which platforms does longjmp change the signal
> mask and how, and in what ways can this "mess things up and slow
> things down"?

For example, under FreeBSD, setjmp saves the signal mask,
and longjmp restores the signal mask to the value that it had
when setjmp was called.  See
<http://www.freebsd.org/cgi/man.cgi?query=setjmp&manpath=FreeBSD+9.0-RELEASE>.
FreeBSD is not alone in this -- it's sort of a BSD tradition --
but I don't have a list handy of exactly which OSes do it and
which do not.

Saving and restoring the signal mask takes time -- often system
calls are involved.  Emacs doesn't need the mask saved and restored,
typically, so the effort is wasted.  It's not uncommon for
_setjmp+_longjmp to be 30x faster than setjmp+longjmp.  This is
partly why Emacs has long preferred _setjmp if available.

Messups are trickier, because they involve rare race conditions.
They can occur if Emacs or a system call has set the signal mask to X,
but a longjump unexpectedly changes it to Y, where Y is not equal to X.
This can happen if a signal handler invokes longjmp, either directly
or indirectly.  For example, Emacs signal handlers can invoke xmalloc,
which can do a longjmp if memory is full, leading to a rare bug.

Arguably signal handlers should not invoke malloc -- and I'll
submit a patch shortly along those lines -- but regardless,
it's better if Emacs's nonlocal gotos uniformly leave
the signal mask alone, rather than leaving it alone on some hosts
and messing with it on others.





  reply	other threads:[~2012-09-15  7:50 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-09-14 19:44 bug#12446: port better to POSIX hosts lacking _setjmp Paul Eggert
2012-09-14 20:30 ` Eli Zaretskii
2012-09-14 21:28   ` Paul Eggert
2012-09-15  7:10     ` Paul Eggert
2012-09-15  8:08       ` Eli Zaretskii
2012-09-15  8:46         ` Paul Eggert
2012-09-15  9:41           ` Eli Zaretskii
2012-09-15 10:06             ` Paul Eggert
2012-09-15  7:12     ` Eli Zaretskii
2012-09-15  7:50       ` Paul Eggert [this message]
2012-09-15  8:28         ` Eli Zaretskii
2012-09-15  8:55           ` Paul Eggert
2012-09-15  9:44             ` Eli Zaretskii
2012-09-15 10:00               ` Paul Eggert
2012-09-15 10:27                 ` Eli Zaretskii
2012-09-15 20:26                   ` Paul Eggert

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

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

  git send-email \
    --in-reply-to=50543339.3090500@cs.ucla.edu \
    --to=eggert@cs.ucla.edu \
    --cc=12446@debbugs.gnu.org \
    --cc=eliz@gnu.org \
    --cc=lekktu@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 external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.