From owner-freebsd-bugs Tue Dec 3 07:10:06 1996 Return-Path: owner-bugs Received: (from root@localhost) by freefall.freebsd.org (8.7.5/8.7.3) id HAA19208 for bugs-outgoing; Tue, 3 Dec 1996 07:10:06 -0800 (PST) Received: (from gnats@localhost) by freefall.freebsd.org (8.7.5/8.7.3) id HAA19198; Tue, 3 Dec 1996 07:10:04 -0800 (PST) Resent-Date: Tue, 3 Dec 1996 07:10:04 -0800 (PST) Resent-Message-Id: <199612031510.HAA19198@freefall.freebsd.org> Resent-From: gnats (GNATS Management) Resent-To: freebsd-bugs Resent-Reply-To: FreeBSD-gnats@freefall.FreeBSD.org, cracauer@cons.org Received: from knight.cons.org (knight.cons.org [194.233.237.86]) by freefall.freebsd.org (8.7.5/8.7.3) with ESMTP id HAA18724 for ; Tue, 3 Dec 1996 07:00:07 -0800 (PST) Received: (from cracauer@localhost) by knight.cons.org (8.7.5/8.7.3) id PAA03960; Tue, 3 Dec 1996 15:43:04 +0100 (MET) Message-Id: <199612031443.PAA03960@knight.cons.org> Date: Tue, 3 Dec 1996 15:43:04 +0100 (MET) From: cracauer@cons.org Reply-To: cracauer@cons.org To: FreeBSD-gnats-submit@freebsd.org X-Send-Pr-Version: 3.2 Subject: kern/2142: FP mask not saved for signal handlers Sender: owner-bugs@freebsd.org X-Loop: FreeBSD.org Precedence: bulk >Number: 2142 >Category: kern >Synopsis: FP mask not saved for signal handlers >Confidential: no >Severity: serious >Priority: medium >Responsible: freebsd-bugs >State: open >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Tue Dec 3 07:10:02 PST 1996 >Last-Modified: >Originator: Martin Cracauer >Organization: private >Release: FreeBSD 2.1.5 >Environment: The problem happens on FreeBSD-2.1.5 and NetBSD-1.1. I didn't test on newer FreeBSD version. CPUs in question were: P6-200 (FreeBSD) and P-166 (NetBSD). >Description: I have an appliation that uses timer interrupts to show a "progress bar". The signal handler does some floating point calculation and then uses fputc to stderr. The application is a floating-point intensitive tabular generator. The problem that arises is that apparently random values in the floating point arrays of the main application are set to NaN when the program completes. When I turn off the "progress bar", and therefore the timer-called signal handler, no values are incorrect (the application can't produce a NaN in normal operation). The number of wrong values grows with the total (wall clock) time the program needs to complete (and therefore with the number of times the signal handler is called). I suspect the FP status register is not correctly saved when the signal handler is called and as a result an interrupted floating point calculation will see the 'NaN' flag set in the FP status register (whatever that is called, don't know anything about the 80387) after the signal handler returned. Therefore, the result of this operation will be set to NaN, no matter what the original calculation said. The same application doesn't show the problem when running on SPARC/SunOS SPARC/Solaris and SGI/Irix. The problem is worse on the FreeBSD-P6 than on the NetBSD-P166 (worse means: The number of wrong values compared to the number of signal handler calls is higher). >How-To-Repeat: I'm sorry I can't provide a short example program. I tried to isolate the problem, but the problem disapears when I replace the original calculation routines with something thought-out. The application makes heavy use of subroutine calls returning doubles, maybe that's related to the problem. I hope this problem is quite easy to solve for someone familar with the signal handling code in FreeBSD and the FP registers on the CPU. If that's not the case, please let me know what I can do. I'm not really lazy, I just hope it the solution is obvious. Here's the signal handler code I use: It purpose is to add a number of blanks to stderr, where is number of blanks shown is the "progress bar" (80 chars = 100%). void interrupt(int sig) { int n,i; static int wieviel=0; setitimer(ITIMER_REAL,&timer1,&timerdummy); bsdsignal(SIGALRM,(void *)(interrupt)); n=(int)((double)counter/(double)max*(double)80); for (i=wieviel;iFix: I suspect one has to add a proper saving of the floating point status register to the signal handler code. >Audit-Trail: >Unformatted: