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"
38 /* Linux sigaction function */
40 #if defined(linux) && defined(__i386__)
41 /* This is the sigaction structure from the Linux 2.1.20 kernel. */
43 struct kernel_sigaction
46 unsigned long sa_mask;
47 unsigned long sa_flags;
48 void (*sa_restorer)();
51 /* Similar to the sigaction function in libc, except it leaves alone the
52 restorer field, which is used to specify the signal stack address */
53 static __inline__ int wine_sigaction( int sig, struct kernel_sigaction *new,
54 struct kernel_sigaction *old )
57 __asm__ __volatile__( "pushl %%ebx\n\t"
62 : "0" (SYS_sigaction),
67 __asm__ __volatile__( "int $0x80"
69 : "0" (SYS_sigaction),
79 #endif /* linux && __i386__ */
83 static char SIGNAL_Stack[16384];
84 static sigset_t async_signal_set;
86 /**********************************************************************
89 * wait4 terminated child processes
91 static HANDLER_DEF(SIGNAL_child)
95 wait4( 0, NULL, WNOHANG, NULL);
96 #elif defined (HAVE_WAITPID)
97 /* I am sort-of guessing that this is the same as the wait4 call. */
98 waitpid (0, NULL, WNOHANG);
105 /**********************************************************************
108 void SIGNAL_SetHandler( int sig, void (*func)(), int flags )
112 #if defined(linux) && defined(__i386__)
114 struct kernel_sigaction sig_act;
115 sig_act.sa_handler = func;
116 sig_act.sa_flags = SA_RESTART | (flags) ? SA_NOMASK : 0;
118 /* Point to the top of the stack, minus 4 just in case, and make
120 sig_act.sa_restorer =
121 (void (*)())((int)(SIGNAL_Stack + sizeof(SIGNAL_Stack) - 4) & ~3);
122 ret = wine_sigaction( sig, &sig_act, NULL );
124 #else /* linux && __i386__ */
126 struct sigaction sig_act;
127 sig_act.sa_handler = func;
128 sigemptyset( &sig_act.sa_mask );
130 # if defined(__NetBSD__) || defined(__FreeBSD__) || defined(__OpenBSD__)
131 sig_act.sa_flags = SA_ONSTACK;
132 # elif defined (__svr4__) || defined(_SCO_DS)
133 sig_act.sa_flags = SA_SIGINFO | SA_ONSTACK | SA_RESTART;
134 # elif defined(__EMX__)
135 sig_act.sa_flags = 0; /* FIXME: EMX has only SA_ACK and SA_SYSV */
137 sig_act.sa_flags = 0;
139 ret = sigaction( sig, &sig_act, NULL );
141 #endif /* linux && __i386__ */
145 perror( "sigaction" );
150 extern void stop_wait(int a);
151 extern void WINSOCK_sigio(int a);
154 /**********************************************************************
157 BOOL32 SIGNAL_Init(void)
159 extern void SYNC_SetupSignals(void);
161 #ifdef HAVE_SIGALTSTACK
162 struct sigaltstack ss;
163 ss.ss_sp = SIGNAL_Stack;
164 ss.ss_size = sizeof(SIGNAL_Stack);
166 if (sigaltstack(&ss, NULL) < 0)
171 #endif /* HAVE_SIGALTSTACK */
173 sigemptyset(&async_signal_set);
175 SIGNAL_SetHandler( SIGCHLD, (void (*)())SIGNAL_child, 1);
177 sigaddset(&async_signal_set, SIGUSR2);
178 SIGNAL_SetHandler( SIGUSR2, (void (*)())stop_wait, 1); /* For IPC */
181 sigaddset(&async_signal_set, SIGIO);
182 SIGNAL_SetHandler( SIGIO, (void (*)())WINSOCK_sigio, 0);
185 sigaddset(&async_signal_set, SIGALRM);
187 /* ignore SIGPIPE so that WINSOCK can get a EPIPE error instead */
188 signal (SIGPIPE, SIG_IGN);
195 /**********************************************************************
196 * SIGNAL_MaskAsyncEvents
198 void SIGNAL_MaskAsyncEvents( BOOL32 flag )
200 sigprocmask( (flag) ? SIG_BLOCK : SIG_UNBLOCK , &async_signal_set, NULL);