tests/vg_regtest: Always evaluate prerequisite expressions with sh
[valgrind.git] / memcheck / tests / x86-solaris / context_eflags.c
blob63c6377d7fb232c97e79567b9c2ac71d7d48ddea
1 /* x86 variant of the amd64-solaris/context_rflags.c test. */
3 #include <assert.h>
4 #include <signal.h>
5 #include <stdio.h>
6 #include <stdlib.h>
7 #include <unistd.h>
8 #include <sys/syscall.h>
9 #include <sys/ucontext.h>
11 #define OBIT(eflags) (!!((eflags) & (1 << 11)))
12 #define SBIT(eflags) (!!((eflags) & (1 << 7)))
14 static siginfo_t si;
15 static ucontext_t uc;
17 static void sighandler(int sig, siginfo_t *sip, ucontext_t *ucp)
19 si = *sip;
20 uc = *ucp;
23 int main(void)
25 struct sigaction sa;
26 pid_t pid;
27 int eflags;
29 sa.sa_handler = sighandler;
30 sa.sa_flags = SA_SIGINFO;
31 if (sigfillset(&sa.sa_mask)) {
32 perror("sigfillset");
33 return 1;
35 if (sigaction(SIGUSR1, &sa, NULL)) {
36 perror("sigaction");
37 return 1;
40 pid = getpid();
42 __asm__ __volatile__(
43 /* Set overflow and sign flags. */
44 "movl $1, %%edx\n"
45 "addl $0x7fffffff, %%edx\n"
47 /* Prepare syscall parameters. */
48 "pushl %[sig]\n"
49 "pushl %[pid]\n"
50 "pushl $0xdeadbeef\n"
51 "movl %[scall], %%eax\n"
53 /* Trigger the signal handler. */
54 "int $0x91\n"
55 "pushfl\n"
56 "popl %%edx\n"
57 "addl $12, %%esp\n"
58 : "=d" (eflags)
59 : [scall] "i" (SYS_kill), [pid] "a" (pid), [sig] "i" (SIGUSR1)
60 : "cc", "memory");
62 printf("Values in the signal handler:\n");
63 printf(" overflow=%d, sign=%d\n",
64 OBIT(uc.uc_mcontext.gregs[EFL]), SBIT(uc.uc_mcontext.gregs[EFL]));
66 printf("Values after the return from the signal handler:\n");
67 printf(" overflow=%d, sign=%d\n", OBIT(eflags), SBIT(eflags));
69 return 0;