4 * Copyright 1995 Alexandre Julliard
18 #include <sys/timeb.h>
19 #include <sys/types.h>
22 #ifdef HAVE_SYS_PARAM_H
23 # include <sys/param.h>
28 # ifdef HAVE_SYS_SYSCALL_H
29 # include <sys/syscall.h>
39 #include "wine/exception.h"
40 #include "debugtools.h"
43 /* Linux sigaction function */
45 #if defined(linux) && defined(__i386__)
46 /* This is the sigaction structure from the Linux 2.1.20 kernel. */
49 struct kernel_sigaction
52 unsigned long sa_mask;
53 unsigned long sa_flags;
54 void (*sa_restorer)();
57 /* Similar to the sigaction function in libc, except it leaves alone the
58 restorer field, which is used to specify the signal stack address */
59 static inline int wine_sigaction( int sig, struct kernel_sigaction *new,
60 struct kernel_sigaction *old )
63 __asm__ __volatile__( "pushl %%ebx\n\t"
68 : "0" (SYS_sigaction),
73 __asm__ __volatile__( "int $0x80"
75 : "0" (SYS_sigaction),
85 #endif /* linux && __i386__ */
89 static char SIGNAL_Stack[16384];
90 static sigset_t async_signal_set;
92 /**********************************************************************
95 * wait4 terminated child processes
97 static HANDLER_DEF(SIGNAL_child)
101 wait4( 0, NULL, WNOHANG, NULL);
102 #elif defined (HAVE_WAITPID)
103 /* I am sort-of guessing that this is the same as the wait4 call. */
104 waitpid (0, NULL, WNOHANG);
111 /**********************************************************************
114 void SIGNAL_SetHandler( int sig, void (*func)(), int flags )
118 #if defined(linux) && defined(__i386__)
120 struct kernel_sigaction sig_act;
121 sig_act.sa_handler = func;
122 sig_act.sa_flags = SA_RESTART | (flags) ? SA_NOMASK : 0;
124 /* Point to the top of the stack, minus 4 just in case, and make
126 sig_act.sa_restorer =
127 (void (*)())((int)(SIGNAL_Stack + sizeof(SIGNAL_Stack) - 4) & ~3);
128 ret = wine_sigaction( sig, &sig_act, NULL );
130 #else /* linux && __i386__ */
132 struct sigaction sig_act;
133 sig_act.sa_handler = func;
134 sigemptyset( &sig_act.sa_mask );
136 # if defined(__NetBSD__) || defined(__FreeBSD__) || defined(__OpenBSD__)
137 sig_act.sa_flags = SA_ONSTACK;
138 # elif defined (__svr4__) || defined(_SCO_DS)
139 sig_act.sa_flags = SA_SIGINFO | SA_ONSTACK | SA_RESTART;
140 # elif defined(__EMX__)
141 sig_act.sa_flags = 0; /* FIXME: EMX has only SA_ACK and SA_SYSV */
143 sig_act.sa_flags = 0;
145 ret = sigaction( sig, &sig_act, NULL );
147 #endif /* linux && __i386__ */
151 perror( "sigaction" );
156 extern void stop_wait(int a);
157 extern void WINSOCK_sigio(int a);
158 extern void ASYNC_sigio(int a);
161 /**********************************************************************
162 * SIGNAL_MaskAsyncEvents
164 void SIGNAL_MaskAsyncEvents( BOOL flag )
166 sigprocmask( (flag) ? SIG_BLOCK : SIG_UNBLOCK , &async_signal_set, NULL);
170 /**********************************************************************
173 BOOL SIGNAL_Init(void)
175 #ifdef HAVE_WORKING_SIGALTSTACK
176 struct sigaltstack ss;
177 ss.ss_sp = SIGNAL_Stack;
178 ss.ss_size = sizeof(SIGNAL_Stack);
180 if (sigaltstack(&ss, NULL) < 0)
182 perror("sigaltstack");
183 /* fall through on error and try it differently */
185 #endif /* HAVE_SIGALTSTACK */
187 sigemptyset(&async_signal_set);
189 SIGNAL_SetHandler( SIGCHLD, (void (*)())SIGNAL_child, 1);
191 sigaddset(&async_signal_set, SIGIO);
192 /* SIGNAL_SetHandler( SIGIO, (void (*)())WINSOCK_sigio, 0); */
193 SIGNAL_SetHandler( SIGIO, (void (*)())ASYNC_sigio, 0);
195 sigaddset(&async_signal_set, SIGALRM);
197 /* ignore SIGPIPE so that WINSOCK can get a EPIPE error instead */
198 signal (SIGPIPE, SIG_IGN);