10 #if defined(__NetBSD__) || defined(__FreeBSD__) || defined(__svr4__)
11 #include <sys/syscall.h>
12 #include <sys/param.h>
19 #include "registers.h"
22 #if !defined(BSD4_4) || defined(linux) || defined(__FreeBSD__)
27 extern void ___sig_restore();
28 extern void ___masksig_restore();
30 /* Similar to the sigaction function in libc, except it leaves alone the
34 wine_sigaction(int sig,struct sigaction * new, struct sigaction * old)
36 __asm__("int $0x80":"=a" (sig)
37 :"0" (SYS_sigaction),"b" (sig),"c" (new),"d" (old));
47 static void win_fault(int signal, struct sigcontext_struct context_struct)
49 struct sigcontext_struct *context = &context_struct;
50 #elif defined(__svr4__)
51 static void win_fault(int signal, void *siginfo, ucontext_t *context)
54 static void win_fault(int signal, int code, struct sigcontext *context)
57 if (signal == SIGTRAP)
59 /* If SIGTRAP not caused by breakpoint or single step
60 don't jump into the debugger */
61 if (!(EFL_reg(context) & STEP_FLAG))
64 addr.seg = CS_reg(context);
65 addr.off = EIP_reg(context) - 1;
66 if (DEBUG_FindBreakpoint(&addr) == -1) return;
69 else if (signal != SIGHUP)
71 if (CS_reg(context) == WINE_CODE_SELECTOR)
73 fprintf(stderr, "Segmentation fault in Wine program (%x:%lx)."
75 CS_reg(context), EIP_reg(context) );
79 if (INSTR_EmulateInstruction( context )) return;
80 fprintf( stderr, "Segmentation fault in Windows program %x:%lx.\n",
81 CS_reg(context), EIP_reg(context) );
85 XUngrabPointer(display, CurrentTime);
86 XUngrabServer(display);
88 wine_debug( signal, context ); /* Enter our debugger */
92 /**********************************************************************
95 static void SIGNAL_SetHandler( int sig, void (*func)() )
98 struct sigaction sig_act;
101 sig_act.sa_handler = func;
102 /* Point to the top of the stack, minus 4 just in case, and make
104 sig_act.sa_restorer =
105 (void (*)()) (((unsigned int)(cstack) + sizeof(cstack) - 4) & ~3);
106 ret = wine_sigaction( sig, &sig_act, NULL );
109 #if defined(__NetBSD__) || defined(__FreeBSD__)
111 sigemptyset(&sig_mask);
112 sig_act.sa_handler = func;
113 sig_act.sa_flags = SA_ONSTACK;
114 sig_act.sa_mask = sig_mask;
115 ret = sigaction( sig, &sig_act, NULL );
116 #endif /* __FreeBSD__ || __NetBSD__ */
118 #if defined (__svr4__)
120 sigemptyset(&sig_mask);
121 sig_act.sa_handler = func;
122 sig_act.sa_flags = SA_ONSTACK | SA_SIGINFO;
123 sig_act.sa_mask = sig_mask;
124 ret = sigaction( sig, &sig_act, NULL );
125 #endif /* __svr4__ */
129 perror( "sigaction" );
135 /**********************************************************************
138 void init_wine_signals(void)
140 extern void stop_wait(int a);
142 #if defined(__NetBSD__) || defined(__FreeBSD__)
143 struct sigaltstack ss;
145 #if !defined (__FreeBSD__)
146 if ((ss.ss_base = malloc(MINSIGSTKSZ)) == NULL) {
148 if ((ss.ss_sp = malloc(MINSIGSTKSZ)) == NULL) {
150 fprintf(stderr, "Unable to allocate signal stack (%d bytes)\n",
154 ss.ss_size = MINSIGSTKSZ;
156 if (sigaltstack(&ss, NULL) < 0) {
160 #endif /* __FreeBSD__ || __NetBSD__ */
162 #if defined (__svr4__)
163 struct sigaltstack ss;
165 if ((ss.ss_sp = malloc(SIGSTKSZ) ) == NULL) {
166 fprintf(stderr, "Unable to allocate signal stack (%d bytes)\n",
170 ss.ss_size = SIGSTKSZ;
172 if (sigaltstack(&ss, NULL) < 0) {
176 #endif /* __svr4__ */
178 SIGNAL_SetHandler( SIGSEGV, (void (*)())win_fault );
179 SIGNAL_SetHandler( SIGILL, (void (*)())win_fault );
180 SIGNAL_SetHandler( SIGFPE, (void (*)())win_fault );
181 SIGNAL_SetHandler( SIGTRAP, (void (*)())win_fault ); /* For debugger */
182 SIGNAL_SetHandler( SIGHUP, (void (*)())win_fault ); /* For forced break */
184 SIGNAL_SetHandler( SIGBUS, (void (*)())win_fault );
187 SIGNAL_SetHandler( SIGUSR2, (void (*)())stop_wait ); /* For IPC */
191 #endif /* ifndef WINELIB */