1 /* x86 variant of the amd64-solaris/context_rflags.c test. */
2
3 #include <assert.h>
4 #include <signal.h>
5 #include <stdio.h>
6 #include <stdlib.h>
7 #include <unistd.h>
8 #include <sys/regset.h>
9 #include <sys/syscall.h>
10 #include <sys/ucontext.h>
11
12 #define OBIT(eflags) (!!((eflags) & (1 << 11)))
13 #define SBIT(eflags) (!!((eflags) & (1 << 7)))
14
15 static siginfo_t si;
16 static ucontext_t uc;
17
sighandler(int sig,siginfo_t * sip,void * arg)18 static void sighandler(int sig, siginfo_t *sip, void *arg)
19 {
20 si = *sip;
21 uc = *((ucontext_t *) arg);
22 }
23
main(void)24 int main(void)
25 {
26 struct sigaction sa;
27 pid_t pid;
28 int eflags;
29
30 sa.sa_sigaction = sighandler;
31 sa.sa_flags = SA_SIGINFO;
32 if (sigfillset(&sa.sa_mask)) {
33 perror("sigfillset");
34 return 1;
35 }
36 if (sigaction(SIGUSR1, &sa, NULL)) {
37 perror("sigaction");
38 return 1;
39 }
40
41 pid = getpid();
42
43 __asm__ __volatile__(
44 /* Set overflow and sign flags. */
45 "movl $1, %%edx\n"
46 "addl $0x7fffffff, %%edx\n"
47
48 /* Prepare syscall parameters. */
49 "pushl %[sig]\n"
50 "pushl %[pid]\n"
51 "pushl $0xdeadbeef\n"
52 "movl %[scall], %%eax\n"
53
54 /* Trigger the signal handler. */
55 "int $0x91\n"
56 "pushfl\n"
57 "popl %%edx\n"
58 "addl $12, %%esp\n"
59 : "=d" (eflags)
60 : [scall] "i" (SYS_kill), [pid] "a" (pid), [sig] "i" (SIGUSR1)
61 : "cc", "memory");
62
63 printf("Values in the signal handler:\n");
64 printf(" overflow=%d, sign=%d\n",
65 OBIT(uc.uc_mcontext.gregs[EFL]), SBIT(uc.uc_mcontext.gregs[EFL]));
66
67 printf("Values after the return from the signal handler:\n");
68 printf(" overflow=%d, sign=%d\n", OBIT(eflags), SBIT(eflags));
69
70 return 0;
71 }
72
73