1 /* $OpenBSD: fpsig.c,v 1.2 2005/07/15 07:28:33 otto Exp $ */ 2 3 /* 4 * Public domain. 2005, Otto Moerbeek 5 * 6 * Try to check if fp registers are properly saved and restored while 7 * calling a signal hander. This is not supposed to catch all that 8 * can go wrong, but trashed fp registers will typically get caught. 9 */ 10 11 #include <err.h> 12 #include <signal.h> 13 #include <unistd.h> 14 15 #define LIMIT 10.0 16 17 volatile sig_atomic_t count; 18 19 volatile double g1; 20 volatile double g2; 21 22 void 23 handler(int signo) 24 { 25 double a, b, c = 0.0; 26 27 if (signo) 28 alarm(1); 29 for (a = 0.0; a < LIMIT; a++) 30 for (b = 0.0; b < LIMIT; b++) 31 c += a * a + b * b; 32 33 if (signo) { 34 g1 = c; 35 count++; 36 } else 37 g2 = c; 38 } 39 40 int 41 main() 42 { 43 signal(SIGALRM, handler); 44 /* initialize global vars */ 45 handler(0); 46 handler(1); 47 48 while (count < 10) { 49 handler(0); 50 if (g1 != g2) 51 errx(1, "%f %f", g1, g2); 52 } 53 return (0); 54 } 55