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__)
25 struct sigaction segv_act
;
26 struct sigaction usr2_act
;
29 extern void ___sig_restore();
30 extern void ___masksig_restore();
32 /* Similar to the sigaction function in libc, except it leaves alone the
36 wine_sigaction(int sig
,struct sigaction
* new, struct sigaction
* old
)
38 __asm__("int $0x80":"=a" (sig
)
39 :"0" (SYS_sigaction
),"b" (sig
),"c" (new),"d" (old
));
48 #if defined(linux) || defined(__svr4__)
49 static void win_fault(int signal
, struct sigcontext_struct context_struct
)
51 struct sigcontext_struct
*context
= &context_struct
;
53 static void win_fault(int signal
, int code
, struct sigcontext
*context
)
56 if (signal
!= SIGTRAP
)
58 if (CS_reg(context
) == WINE_CODE_SELECTOR
)
60 fprintf(stderr
, "Segmentation fault in Wine program (%x:%lx)."
62 CS_reg(context
), EIP_reg(context
) );
64 else if (INSTR_EmulateInstruction( context
)) return;
65 fprintf( stderr
,"In win_fault %x:%lx\n",
66 CS_reg(context
), EIP_reg(context
) );
68 XUngrabPointer(display
, CurrentTime
);
69 XUngrabServer(display
);
71 wine_debug( signal
, context
); /* Enter our debugger */
74 void init_wine_signals(void)
76 extern void stop_wait(int a
);
78 segv_act
.sa_handler
= (__sighandler_t
) win_fault
;
79 /* Point to the top of the stack, minus 4 just in case, and make
81 segv_act
.sa_restorer
=
82 (void (*)()) (((unsigned int)(cstack
) + sizeof(cstack
) - 4) & ~3);
83 /* Point to the top of the stack, minus 4 just in case, and make
85 wine_sigaction(SIGSEGV
, &segv_act
, NULL
);
86 wine_sigaction(SIGILL
, &segv_act
, NULL
);
87 wine_sigaction(SIGFPE
, &segv_act
, NULL
);
89 wine_sigaction(SIGBUS
, &segv_act
, NULL
);
91 wine_sigaction(SIGTRAP
, &segv_act
, NULL
); /* For breakpoints */
93 usr2_act
.sa_restorer
= segv_act
.sa_restorer
;
94 usr2_act
.sa_handler
= (__sighandler_t
) stop_wait
;
95 wine_sigaction(SIGUSR2
, &usr2_act
, NULL
);
96 #endif /* CONFIG_IPC */
98 #if defined(__NetBSD__) || defined(__FreeBSD__)
100 struct sigaltstack ss
;
102 #if !defined (__FreeBSD__)
103 if ((ss
.ss_base
= malloc(MINSIGSTKSZ
)) == NULL
) {
105 if ((ss
.ss_sp
= malloc(MINSIGSTKSZ
)) == NULL
) {
107 fprintf(stderr
, "Unable to allocate signal stack (%d bytes)\n",
111 ss
.ss_size
= MINSIGSTKSZ
;
113 if (sigaltstack(&ss
, NULL
) < 0) {
117 sigemptyset(&sig_mask
);
118 segv_act
.sa_handler
= (void (*)) win_fault
;
119 segv_act
.sa_flags
= SA_ONSTACK
;
120 segv_act
.sa_mask
= sig_mask
;
121 if (sigaction(SIGBUS
, &segv_act
, NULL
) < 0) {
122 perror("sigaction: SIGBUS");
125 segv_act
.sa_handler
= (void (*)) win_fault
;
126 segv_act
.sa_flags
= SA_ONSTACK
;
127 segv_act
.sa_mask
= sig_mask
;
128 if (sigaction(SIGSEGV
, &segv_act
, NULL
) < 0) {
129 perror("sigaction: SIGSEGV");
132 segv_act
.sa_handler
= (void (*)) win_fault
; /* For breakpoints */
133 segv_act
.sa_flags
= SA_ONSTACK
;
134 segv_act
.sa_mask
= sig_mask
;
135 if (sigaction(SIGTRAP
, &segv_act
, NULL
) < 0) {
136 perror("sigaction: SIGTRAP");
140 usr2_act
.sa_handler
= (void (*)) stop_wait
; /* For breakpoints */
141 usr2_act
.sa_flags
= SA_ONSTACK
;
142 usr2_act
.sa_mask
= sig_mask
;
143 if (sigaction(SIGUSR2
, &usr2_act
, NULL
) < 0) {
144 perror("sigaction: SIGUSR2");
147 #endif /* CONFIG_IPC */
148 #endif /* __FreeBSD__ || __NetBSD__ */
151 #endif /* ifndef WINELIB */