[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:31:48 +0000 |
On 18 February 2013 19:19, Peter Maydell <address@hidden> wrote:
> 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"
This turns out to be accurate but misleading :-)
POSIX also says "The siglongjmp() function shall restore the saved
signal mask if and only if the env argument was initialized by a call
to sigsetjmp() with a non-zero savemask". So it allows the
implementation to pointlessly save the signal mask on sigsetjmp(buf, 0)
but only if it can then guarantee not to restore it on jump.
This means the patch is OK (though the commit message is slightly
misleading in a couple of areas and I guess I could reword it.)
-- PMM