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/syscall.h> 9#include <sys/ucontext.h> 10 11#define OBIT(eflags) (!!((eflags) & (1 << 11))) 12#define SBIT(eflags) (!!((eflags) & (1 << 7))) 13 14static siginfo_t si; 15static ucontext_t uc; 16 17static void sighandler(int sig, siginfo_t *sip, ucontext_t *ucp) 18{ 19 si = *sip; 20 uc = *ucp; 21} 22 23int main(void) 24{ 25 struct sigaction sa; 26 pid_t pid; 27 int eflags; 28 29 sa.sa_handler = sighandler; 30 sa.sa_flags = SA_SIGINFO; 31 if (sigfillset(&sa.sa_mask)) { 32 perror("sigfillset"); 33 return 1; 34 } 35 if (sigaction(SIGUSR1, &sa, NULL)) { 36 perror("sigaction"); 37 return 1; 38 } 39 40 pid = getpid(); 41 42 __asm__ __volatile__( 43 /* Set overflow and sign flags. */ 44 "movl $1, %%edx\n" 45 "addl $0x7fffffff, %%edx\n" 46 47 /* Prepare syscall parameters. */ 48 "pushl %[sig]\n" 49 "pushl %[pid]\n" 50 "pushl $0xdeadbeef\n" 51 "movl %[scall], %%eax\n" 52 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"); 61 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])); 65 66 printf("Values after the return from the signal handler:\n"); 67 printf(" overflow=%d, sign=%d\n", OBIT(eflags), SBIT(eflags)); 68 69 return 0; 70} 71 72