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__)
110 sig_act
.sa_handler
= func
;
111 sig_act
.sa_flags
= SA_ONSTACK
;
112 sig_act
.sa_mask
= sig_mask
;
113 ret
= sigaction( sig
, &sig_act
, NULL
);
114 #endif /* __FreeBSD__ || __NetBSD__ */
116 #if defined (__svr4__)
117 sig_act
.sa_handler
= func
;
118 sig_act
.sa_flags
= SA_ONSTACK
| SA_SIGINFO
;
119 sig_act
.sa_mask
= sig_mask
;
120 ret
= sigaction( sig
, &sig_act
, NULL
);
121 #endif /* __svr4__ */
125 perror( "sigaction" );
131 /**********************************************************************
134 void init_wine_signals(void)
136 extern void stop_wait(int a
);
138 #if defined(__NetBSD__) || defined(__FreeBSD__)
140 struct sigaltstack ss
;
142 #if !defined (__FreeBSD__)
143 if ((ss
.ss_base
= malloc(MINSIGSTKSZ
)) == NULL
) {
145 if ((ss
.ss_sp
= malloc(MINSIGSTKSZ
)) == NULL
) {
147 fprintf(stderr
, "Unable to allocate signal stack (%d bytes)\n",
151 ss
.ss_size
= MINSIGSTKSZ
;
153 if (sigaltstack(&ss
, NULL
) < 0) {
157 sigemptyset(&sig_mask
);
158 #endif /* __FreeBSD__ || __NetBSD__ */
160 #if defined (__svr4__)
162 struct sigaltstack ss
;
164 if ((ss
.ss_sp
= malloc(SIGSTKSZ
) ) == NULL
) {
165 fprintf(stderr
, "Unable to allocate signal stack (%d bytes)\n",
169 ss
.ss_size
= SIGSTKSZ
;
171 if (sigaltstack(&ss
, NULL
) < 0) {
175 sigemptyset(&sig_mask
);
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 */