1 /* Test if definedness of rflags values is correctly propagated in and out
2 of a signal handler. Note that actually only the propagation of the
3 overflow and sign flags is tested.
5 This test must use alarm(2) to trigger the signal and not kill(2) as other
6 tests do because in the latter case the signal is actually delivered after
7 the syscall finished. This means that Valgrind had to save a correct carry
8 flag value (indicating if the syscall succeeded) in the rflags. This save
9 operation unfortunately makes all rflags initialised (due to imprecise
17 #include <sys/regset.h>
18 #include <sys/syscall.h>
21 #define OBIT(rflags) (!!((rflags) & (1 << 11)))
22 #define SBIT(rflags) (!!((rflags) & (1 << 7)))
29 static void sighandler(int sig
, siginfo_t
*sip
, void *arg
)
31 ucontext_t
*ucp
= (ucontext_t
*) arg
;
36 /* Break out of the endless loop. */
37 *(uintptr_t*)&ucp
->uc_mcontext
.gregs
[REG_RIP
] = (uintptr_t)break_out
;
46 /* Uninitialised, but we know px[0] is 0x0. */
47 int *px
= malloc(sizeof(*px
));
50 sa
.sa_sigaction
= sighandler
;
51 sa
.sa_flags
= SA_SIGINFO
;
52 if (sigfillset(&sa
.sa_mask
)) {
56 if (sigaction(SIGALRM
, &sa
, NULL
)) {
64 /* Set overflow and sign flags. */
66 "addl $0x7fffffff, %%edx\n"
68 /* Loopity loop, this is where the SIGALRM is triggered. */
79 /* Check that the overflow and sign flags are uninitialised.
81 Note: This actually fails because the rflags are only approximate
82 (always initialised) in the signal handler. */
83 if (!OBIT(uc
.uc_mcontext
.gregs
[REG_RFL
]) ||
84 !SBIT(uc
.uc_mcontext
.gregs
[REG_RFL
]))
87 /* Check that the overflow and sign flags are uninitialised. */
88 if (!OBIT(rflags
) || !SBIT(rflags
))