17 #include <sys/timeb.h>
18 #include <sys/types.h>
21 #ifdef HAVE_SYS_PARAM_H
22 # include <sys/param.h>
27 # ifdef HAVE_SYS_SYSCALL_H
28 # include <sys/syscall.h>
33 #include "selectors.h"
34 #include "sig_context.h"
37 /* Linux sigaction function */
39 #if defined(linux) && defined(__i386__)
40 /* This is the sigaction structure from the Linux 2.1.20 kernel. */
42 struct kernel_sigaction
45 unsigned long sa_mask;
46 unsigned long sa_flags;
47 void (*sa_restorer)();
50 /* Similar to the sigaction function in libc, except it leaves alone the
51 restorer field, which is used to specify the signal stack address */
52 static __inline__ int wine_sigaction( int sig, struct kernel_sigaction *new,
53 struct kernel_sigaction *old )
56 __asm__ __volatile__( "pushl %%ebx\n\t"
61 : "0" (SYS_sigaction),
66 __asm__ __volatile__( "int $0x80"
68 : "0" (SYS_sigaction),
78 #endif /* linux && __i386__ */
82 static char SIGNAL_Stack[16384];
83 static sigset_t async_signal_set;
85 /**********************************************************************
88 * wait4 terminated child processes
90 static HANDLER_DEF(SIGNAL_child)
94 wait4( 0, NULL, WNOHANG, NULL);
95 #elif defined (HAVE_WAITPID)
96 /* I am sort-of guessing that this is the same as the wait4 call. */
97 waitpid (0, NULL, WNOHANG);
104 /**********************************************************************
107 void SIGNAL_SetHandler( int sig, void (*func)(), int flags )
111 #if defined(linux) && defined(__i386__)
113 struct kernel_sigaction sig_act;
114 sig_act.sa_handler = func;
115 sig_act.sa_flags = SA_RESTART | (flags) ? SA_NOMASK : 0;
117 /* Point to the top of the stack, minus 4 just in case, and make
119 sig_act.sa_restorer =
120 (void (*)())((int)(SIGNAL_Stack + sizeof(SIGNAL_Stack) - 4) & ~3);
121 ret = wine_sigaction( sig, &sig_act, NULL );
123 #else /* linux && __i386__ */
125 struct sigaction sig_act;
126 sig_act.sa_handler = func;
127 sigemptyset( &sig_act.sa_mask );
129 # if defined(__NetBSD__) || defined(__FreeBSD__) || defined(__OpenBSD__)
130 sig_act.sa_flags = SA_ONSTACK;
131 # elif defined (__svr4__) || defined(_SCO_DS)
132 sig_act.sa_flags = SA_SIGINFO | SA_ONSTACK | SA_RESTART;
133 # elif defined(__EMX__)
134 sig_act.sa_flags = 0; /* FIXME: EMX has only SA_ACK and SA_SYSV */
136 sig_act.sa_flags = 0;
138 ret = sigaction( sig, &sig_act, NULL );
140 #endif /* linux && __i386__ */
144 perror( "sigaction" );
149 extern void stop_wait(int a);
150 extern void WINSOCK_sigio(int a);
153 /**********************************************************************
156 BOOL32 SIGNAL_Init(void)
158 extern void SYNC_SetupSignals(void);
160 #ifdef HAVE_WORKING_SIGALTSTACK
161 struct sigaltstack ss;
162 ss.ss_sp = SIGNAL_Stack;
163 ss.ss_size = sizeof(SIGNAL_Stack);
165 if (sigaltstack(&ss, NULL) < 0)
170 #endif /* HAVE_SIGALTSTACK */
172 sigemptyset(&async_signal_set);
174 SIGNAL_SetHandler( SIGCHLD, (void (*)())SIGNAL_child, 1);
176 sigaddset(&async_signal_set, SIGUSR2);
177 SIGNAL_SetHandler( SIGUSR2, (void (*)())stop_wait, 1); /* For IPC */
180 sigaddset(&async_signal_set, SIGIO);
181 SIGNAL_SetHandler( SIGIO, (void (*)())WINSOCK_sigio, 0);
184 sigaddset(&async_signal_set, SIGALRM);
186 /* ignore SIGPIPE so that WINSOCK can get a EPIPE error instead */
187 signal (SIGPIPE, SIG_IGN);
194 /**********************************************************************
195 * SIGNAL_MaskAsyncEvents
197 void SIGNAL_MaskAsyncEvents( BOOL32 flag )
199 sigprocmask( (flag) ? SIG_BLOCK : SIG_UNBLOCK , &async_signal_set, NULL);