Subject: Re: save/restore fpu for the signal handler call
To: Rui Paulo <rpaulo@fnop.net>
From: Pavel Cahyna <pcah8322@artax.karlin.mff.cuni.cz>
List: port-i386
Date: 11/30/2005 22:04:51
On Wed, Nov 30, 2005 at 08:54:55PM +0000, Rui Paulo wrote:
> On 2005.11.30 21:36:06 +0100, Pavel Cahyna wrote:
> | On Wed, Nov 30, 2005 at 09:16:53PM +0100, Jaromir Dolecek wrote:
> | > Except that printf() isn't :) You cannot safely access
> | > stdio within signal handler.
> | 
> | Why not?
> 
> signal(7):
> 
>      A function that is async-signal-safe is either reentrant or non-inter-
>      ruptible by signals.  This means that they can be used in signal handlers
>      and in the child of threaded programs after doing fork(2).
> 
>      The following functions are async-signal-safe.  Any function not listed
>      below is unsafe to use in signal handlers.

Thanks for the reference. That is IMHO a bug, because POSIX says :

"All functions not in the above table are considered to be unsafe with
respect to signals. In the presence of signals, all functions defined by
this volume of IEEE Std 1003.1-2001 shall behave as defined when called
from or interrupted by a signal-catching function, with a single
exception: when a signal interrupts an unsafe function and the
signal-catching function calls an unsafe function, the behavior is
undefined."

So it should be perfectly legal to call printf() from a signal handler
which is carefully blocked around calls to unsafe functions, because this
does not fall in the exception above, no?

Pavel