Subject: Re: save/restore fpu for the signal handler call
To: Jeremy C. Reed <reed@reedmedia.net>
From: Matt Thomas <matt@3am-software.com>
List: port-i386
Date: 11/30/2005 11:29:23
Jeremy C. Reed wrote:
> My X11 pointer was stuck to left side of screen. This led me to NetBSD
> PR 30418 (fixed by NetBSD's pkgsrc/xorg-libs/patches/patch-bl). This
> NetBSD PR led me to xorg bug #3113
> https://bugs.freedesktop.org/show_bug.cgi?id=3113
> 
> So I downloaded and compiled OpenBSD's fpsig.c regression test.
> http://www.openbsd.org/cgi-bin/cvsweb.cgi/src/regress/sys/kern/signal/fpsig/
> 
> 
> It had inconsistent results. So I bumped up the loop as suggested to me.
> 
> As I was told via the xorg bug report, this fpsig "test program computes
> the same floating point value, using variables on the stack both in the
> main code path and in a signal handler." Also, the xorg bug report says
> if the signal handlers do not correctly save/restore the FPU registers,
> the results are unpredictable and will probably not be the same (and are
> printed). When no corruption of the FPU, the two results are the same
> and nothing is printed (and the exit status is 0).

Whether FP state is saved and restored for signal has been a contentious
issue.  In 99.9999% of programs, floating point state wouldn't be modified in a
signal handler so why save and restore it?  Indeed, given the existance of
sig_atomic_t as an int type implies that FP usage in a signal handler is
unpredictable.

-- 
Matt Thomas                     email: matt@3am-software.com
3am Software Foundry              www: http://3am-software.com/bio/matt/
Cupertino, CA              disclaimer: I avow all knowledge of this message.