On 17 February 2013 14:44, Peter Maydell <[email protected]> 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
