Skip to contentSkip to conversation

Signal handler can clobber fpu regs

DISCUSSION Andreas Schwab 1 participant 1 message Oct 21, 2004

lore
Share & tools
lore
#0 lore raw

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.

Signature · 4 lines
Andreas Schwab, SuSE Labs, [email protected]
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."