qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH] Replace all setjmp()/longjmp() with sigsetjmp()


From: Peter Maydell
Subject: Re: [Qemu-devel] [PATCH] Replace all setjmp()/longjmp() with sigsetjmp()/siglongjmp()
Date: Mon, 18 Feb 2013 19:19:00 +0000

On 17 February 2013 14:44, Peter Maydell <address@hidden> wrote:
> The setjmp() function doesn't specify whether signal masks are saved and
> restored; on Linux they are not, but on BSD (including MacOSX) they are.
> QEMU never wants to save and restore signal masks, because it uses threads,
> and the signal-restoration may restore the whole process signal mask,
> not just the mask for the thread which did the longjmp. In particular,
> this resulted in a bug where ctrl-C was ignored on MacOSX because the
> CPU thread did a longjmp which resulted in its signal mask being applied
> to every thread, so that all threads had SIGINT and SIGTERM blocked.
>
> The POSIX-sanctioned portable way to do a jump without affecting signal
> masks is to use sigsetjmp() with a zero savemask parameter, so change
> all uses of setjmp()/longjmp() accordingly.

This turns out to be not exactly accurate. POSIX says:
"if savemask is zero, it is unspecified whether the signal mask is saved"

Which isn't very helpful. It looks like _setjmp/_longjmp are
POSIX-required not to mess with the sigmask, but on the other
hand POSIX has also deprecated them. Sigh.

So I'm not sure what to do here. I guess this patch makes us
at least "portable between BSD and Linux", which are the major
use cases. I have no idea whether anybody's actually ever implemented
sigsetjmp() to ignore the savemask parameter; it would be pretty
perverse to do so.

-- PMM



reply via email to

[Prev in Thread] Current Thread [Next in Thread]