1 /* Test if x87 FP valus are correctly propagated in and out of a signal
2 handler and also check that the same applies for uninitialised values and
10 #include <sys/syscall.h>
15 static float inhandler
[8];
17 static void sighandler(int sig
, siginfo_t
*sip
, void *arg
)
20 ucontext_t
*ucp
= (ucontext_t
*) arg
;
25 /* Reset the FP stack so it's possible to push other values onto it. (It
26 is fully filled in main() before triggering the signal handler). Note
27 that VEX also clears all FP values when the finit instruction is
28 executed. This provides another level of validation that the restore
33 /* Convert 80b values in mcontext to 32b values in the inhandler array. */
34 for (i
= 0; i
< 8; i
++) {
38 : [out
] "=m" (inhandler
[i
])
39 : [in
] "m" (*(char*)&ucp
->uc_mcontext
.fpregs
.fp_reg_set
.fpchip_state
.st
[i
]));
50 /* Uninitialised, but we know px[0] is 0x0. */
51 float *px
= malloc(sizeof(*px
));
54 sa
.sa_sigaction
= sighandler
;
55 sa
.sa_flags
= SA_SIGINFO
;
56 if (sigfillset(&sa
.sa_mask
)) {
60 if (sigaction(SIGUSR1
, &sa
, NULL
)) {
68 /* Set values in the FP stack. */
78 /* Trigger the signal handler. */
80 "fstps 0x00 + %[out]\n"
81 "fstps 0x04 + %[out]\n"
82 "fstps 0x08 + %[out]\n"
83 "fstps 0x0c + %[out]\n"
84 "fstps 0x10 + %[out]\n"
85 "fstps 0x14 + %[out]\n"
86 "fstps 0x18 + %[out]\n"
87 "fstps 0x1c + %[out]\n"
89 : "a" (SYS_kill
), "D" (pid
), "S" (SIGUSR1
), [x0
] "m" (x0
)
90 : "rdx", "cc", "memory");
92 printf("Values in the signal handler:\n");
93 printf(" fp[0]=%f, fp[2]=%f, fp[4]=%f, fp[6]=%f\n",
94 inhandler
[0], inhandler
[2], inhandler
[4], inhandler
[6]);
95 /* Check that inhandler[1], inhandler[3], inhandler[5] and inhandler[7]
96 contain uninitialised values (origin is px[0]). */
97 if (inhandler
[1] || inhandler
[3] || inhandler
[5] || inhandler
[7])
100 printf("Values after the return from the signal handler:\n");
101 printf(" fp[0]=%f, fp[2]=%f, fp[4]=%f, fp[6]=%f\n",
102 out
[0], out
[2], out
[4], out
[6]);
103 /* Check that out[1], out[3], out[5] and out[7] contain uninitialised
104 values (origin is px[0]). */
105 if (out
[1] || out
[3] || out
[5] || out
[7])