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 /* Global variable to save %fs register while in 16-bit code */
38 WORD CALLTO16_Current_fs;
40 /* Linux sigaction function */
42 #if defined(linux) && defined(__i386__)
43 /* This is the sigaction structure from the Linux 2.1.20 kernel. */
45 struct kernel_sigaction
48 unsigned long sa_mask;
49 unsigned long sa_flags;
50 void (*sa_restorer)();
53 /* Similar to the sigaction function in libc, except it leaves alone the
54 restorer field, which is used to specify the signal stack address */
55 static __inline__ int wine_sigaction( int sig, struct kernel_sigaction *new,
56 struct kernel_sigaction *old )
59 __asm__ __volatile__( "pushl %%ebx\n\t"
64 : "0" (SYS_sigaction),
69 __asm__ __volatile__( "int $0x80"
71 : "0" (SYS_sigaction),
81 #endif /* linux && __i386__ */
85 static char SIGNAL_Stack[16384];
86 static sigset_t async_signal_set;
88 /**********************************************************************
91 * wait4 terminated child processes
93 static HANDLER_DEF(SIGNAL_child)
97 wait4( 0, NULL, WNOHANG, NULL);
98 #elif defined (HAVE_WAITPID)
99 /* I am sort-of guessing that this is the same as the wait4 call. */
100 waitpid (0, NULL, WNOHANG);
107 /**********************************************************************
110 void SIGNAL_SetHandler( int sig, void (*func)(), int flags )
114 #if defined(linux) && defined(__i386__)
116 struct kernel_sigaction sig_act;
117 sig_act.sa_handler = func;
118 sig_act.sa_flags = SA_RESTART | (flags) ? SA_NOMASK : 0;
120 /* Point to the top of the stack, minus 4 just in case, and make
122 sig_act.sa_restorer =
123 (void (*)())((int)(SIGNAL_Stack + sizeof(SIGNAL_Stack) - 4) & ~3);
124 ret = wine_sigaction( sig, &sig_act, NULL );
126 #else /* linux && __i386__ */
128 struct sigaction sig_act;
129 sig_act.sa_handler = func;
130 sigemptyset( &sig_act.sa_mask );
132 # if defined(__NetBSD__) || defined(__FreeBSD__) || defined(__OpenBSD__)
133 sig_act.sa_flags = SA_ONSTACK;
134 # elif defined (__svr4__) || defined(_SCO_DS)
135 sig_act.sa_flags = SA_SIGINFO | SA_ONSTACK | SA_RESTART;
136 # elif defined(__EMX__)
137 sig_act.sa_flags = 0; /* FIXME: EMX has only SA_ACK and SA_SYSV */
139 sig_act.sa_flags = 0;
141 ret = sigaction( sig, &sig_act, NULL );
143 #endif /* linux && __i386__ */
147 perror( "sigaction" );
152 extern void stop_wait(int a);
153 extern void WINSOCK_sigio(int a);
156 /**********************************************************************
159 BOOL32 SIGNAL_Init(void)
161 extern void SYNC_SetupSignals(void);
163 #ifdef HAVE_WORKING_SIGALTSTACK
164 struct sigaltstack ss;
165 ss.ss_sp = SIGNAL_Stack;
166 ss.ss_size = sizeof(SIGNAL_Stack);
168 if (sigaltstack(&ss, NULL) < 0)
173 #endif /* HAVE_SIGALTSTACK */
175 sigemptyset(&async_signal_set);
177 SIGNAL_SetHandler( SIGCHLD, (void (*)())SIGNAL_child, 1);
179 sigaddset(&async_signal_set, SIGUSR2);
180 SIGNAL_SetHandler( SIGUSR2, (void (*)())stop_wait, 1); /* For IPC */
183 sigaddset(&async_signal_set, SIGIO);
184 SIGNAL_SetHandler( SIGIO, (void (*)())WINSOCK_sigio, 0);
187 sigaddset(&async_signal_set, SIGALRM);
189 /* ignore SIGPIPE so that WINSOCK can get a EPIPE error instead */
190 signal (SIGPIPE, SIG_IGN);
197 /**********************************************************************
198 * SIGNAL_MaskAsyncEvents
200 void SIGNAL_MaskAsyncEvents( BOOL32 flag )
202 sigprocmask( (flag) ? SIG_BLOCK : SIG_UNBLOCK , &async_signal_set, NULL);