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];
92 /**********************************************************************
95 void SIGNAL_SetHandler( int sig
, void (*func
)() )
99 #if defined(linux) && defined(__i386__)
101 struct kernel_sigaction sig_act
;
102 sig_act
.sa_handler
= func
;
103 sig_act
.sa_flags
= SA_RESTART
| SA_NOMASK
;
105 /* Point to the top of the stack, minus 4 just in case, and make
107 sig_act
.sa_restorer
=
108 (void (*)())((int)(SIGNAL_Stack
+ sizeof(SIGNAL_Stack
) - 4) & ~3);
109 ret
= wine_sigaction( sig
, &sig_act
, NULL
);
111 #else /* linux && __i386__ */
113 struct sigaction sig_act
;
114 sig_act
.sa_handler
= func
;
115 sigemptyset( &sig_act
.sa_mask
);
117 # if defined(__NetBSD__) || defined(__FreeBSD__) || defined(__OpenBSD__)
118 sig_act
.sa_flags
= SA_ONSTACK
;
119 # elif defined (__svr4__) || defined(_SCO_DS)
120 sig_act
.sa_flags
= SA_SIGINFO
| SA_ONSTACK
| SA_RESTART
;
121 # elif defined(__EMX__)
122 sig_act
.sa_flags
= 0; /* FIXME: EMX has only SA_ACK and SA_SYSV */
124 sig_act
.sa_flags
= 0;
126 ret
= sigaction( sig
, &sig_act
, NULL
);
128 #endif /* linux && __i386__ */
132 perror( "sigaction" );
138 /**********************************************************************
141 BOOL
SIGNAL_Init(void)
143 #ifdef HAVE_WORKING_SIGALTSTACK
144 struct sigaltstack ss
;
145 ss
.ss_sp
= SIGNAL_Stack
;
146 ss
.ss_size
= sizeof(SIGNAL_Stack
);
148 if (sigaltstack(&ss
, NULL
) < 0)
150 perror("sigaltstack");
151 /* fall through on error and try it differently */
153 #endif /* HAVE_SIGALTSTACK */
155 /* ignore SIGPIPE so that WINSOCK can get a EPIPE error instead */
156 signal (SIGPIPE
, SIG_IGN
);
157 /* automatic child reaping to avoid zombies */
158 signal (SIGCHLD
, SIG_IGN
);