1 #include <features.h> 2 #include <fpu_control.h> 3 #include <signal.h> 4 #include <sys/types.h> 5 #include <signal.h> 6 #include <stdio.h> 7 #include <stdlib.h> 8 #include <ucontext.h> 9 #include <unistd.h> 10 11 void handle_SIG(int sig) 12 { 13 double d; 14 15 _FPU_SETCW(0); 16 d = 7; 17 asm volatile ("":: "f" (d)); 18 printf("Got signal %d\n", sig); 19 if (sig == SIGSEGV) { 20 printf("SIGSEGV, exiting...\n"); 21 exit(0); 22 } 23 } 24 25 void handle_rt_SIG(int sig, siginfo_t *info, void *uc) 26 { 27 double d; 28 29 _FPU_SETCW(0); 30 d = 8; 31 asm volatile ("":: "f" (d)); 32 printf("Got signal %d\n", sig); 33 printf("si_signo: %d\n", info->si_signo); 34 printf("si_errno: %d\n", info->si_errno); 35 printf("si_code: %d\n", info->si_code); 36 if (sig == SIGSEGV) { 37 printf("SIGSEGV, exiting...\n"); 38 exit(0); 39 } 40 } 41 42 int main(void) 43 { 44 // char *a; 45 struct sigaction sa; 46 double d1,d2,d3,d4,d5; 47 48 _FPU_SETCW(1); 49 d1 = d2 = d3 = d4 = d5 = 1; 50 sa.sa_sigaction=handle_rt_SIG; 51 sa.sa_flags =SA_SIGINFO; 52 sigemptyset(&sa.sa_mask); 53 sigaction(SIGALRM, &sa, NULL); 54 signal(SIGUSR1, handle_SIG); 55 signal(SIGSEGV, handle_SIG); 56 kill(getpid(), SIGALRM); 57 printf("One!\n"); 58 kill(getpid(), SIGUSR1); 59 printf("floating point is now: %f %f %f %f %f\n", d1, d2, d3, d4, d5); 60 { 61 int fpc; 62 _FPU_GETCW(fpc); 63 printf("fpc= %d\n", fpc); 64 } 65 printf("Good Bye!\n"); 66 // a = (char *) 0x12345678; 67 // *a = 1; 68 exit(0); 69 } 70