Signal handler can clobber fpu regs

Andreas Schwab schwab at suse.de
Thu Oct 21 22:23:30 EST 2004


Apparently the scratch fpu registers are not saved around calls to signal
handlers.  Here is a test case, when run the output changes every second,
tested with 2.6.9:

#include <stdio.h>
#include <signal.h>
#include <sys/time.h>

void
sigalarm (int sig)
{
  static double x[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
  static int i;
  asm volatile ("lfd 0,%0" : : "Q" (x[i++]));
  if (i == sizeof (x) / sizeof (*x))
    i = 0;
}

int
main (void)
{
  static struct itimerval one_second = { { 1, 0 }, { 1, 0 } };
  static double zero;
  setitimer (ITIMER_REAL, &one_second, 0);
  signal (SIGALRM, sigalarm);
  asm volatile ("lfd 0,%0" : : "Q" (zero));
  for (;;)
    {
      union { double d; unsigned int i[2]; } x;
      asm volatile ("stfd 0,%0" : "=Q" (x.d));
      printf ("f0 = %08x%08x\n", x.i[0], x.i[1]);
    }
}

Andreas.

-- 
Andreas Schwab, SuSE Labs, schwab at suse.de
SuSE Linux AG, Maxfeldstraße 5, 90409 Nürnberg, Germany
Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."



More information about the Linuxppc-dev mailing list