10 #if defined(__NetBSD__) || defined(__FreeBSD__) || defined(__svr4__)
11 #include <sys/syscall.h>
12 #include <sys/param.h>
19 #include "registers.h"
23 #if !defined(BSD4_4) || defined(linux) || defined(__FreeBSD__)
26 struct sigaction segv_act
;
27 struct sigaction usr2_act
;
30 extern void ___sig_restore();
31 extern void ___masksig_restore();
33 /* Similar to the sigaction function in libc, except it leaves alone the
37 wine_sigaction(int sig
,struct sigaction
* new, struct sigaction
* old
)
39 __asm__("int $0x80":"=a" (sig
)
40 :"0" (SYS_sigaction
),"b" (sig
),"c" (new),"d" (old
));
49 #if defined(linux) || defined(__svr4__)
50 static void win_fault(int signal
, struct sigcontext_struct context_struct
)
52 struct sigcontext_struct
*context
= &context_struct
;
54 static void win_fault(int signal
, int code
, struct sigcontext
*context
)
57 if (signal
!= SIGTRAP
)
59 if (CS_reg(context
) == WINE_CODE_SELECTOR
)
61 fprintf(stderr
, "Segmentation fault in Wine program (%04x:%08lx)."
63 CS_reg(context
), EIP_reg(context
) );
65 else if (INSTR_EmulateInstruction( context
)) return;
66 fprintf( stderr
,"In win_fault %x:%lx\n",
67 CS_reg(context
), EIP_reg(context
) );
69 XUngrabPointer(display
, CurrentTime
);
70 XUngrabServer(display
);
72 wine_debug( signal
, context
); /* Enter our debugger */
75 void init_wine_signals(void)
77 extern void stop_wait(int a
);
79 segv_act
.sa_handler
= (__sighandler_t
) win_fault
;
80 /* Point to the top of the stack, minus 4 just in case, and make
82 segv_act
.sa_restorer
=
83 (void (*)()) (((unsigned int)(cstack
) + sizeof(cstack
) - 4) & ~3);
84 /* Point to the top of the stack, minus 4 just in case, and make
86 wine_sigaction(SIGSEGV
, &segv_act
, NULL
);
87 wine_sigaction(SIGILL
, &segv_act
, NULL
);
88 wine_sigaction(SIGFPE
, &segv_act
, NULL
);
90 wine_sigaction(SIGBUS
, &segv_act
, NULL
);
92 wine_sigaction(SIGTRAP
, &segv_act
, NULL
); /* For breakpoints */
94 usr2_act
.sa_restorer
= segv_act
.sa_restorer
;
95 usr2_act
.sa_handler
= (__sighandler_t
) stop_wait
;
96 wine_sigaction(SIGUSR2
, &usr2_act
, NULL
);
97 #endif /* CONFIG_IPC */
99 #if defined(__NetBSD__) || defined(__FreeBSD__)
101 struct sigaltstack ss
;
103 #if !defined (__FreeBSD__)
104 ss
.ss_base
= xmalloc (MINSIGSTKSZ
);
106 ss
.ss_sp
= xmalloc (MINSIGSTKSZ
);
108 ss
.ss_size
= MINSIGSTKSZ
;
110 if (sigaltstack(&ss
, NULL
) < 0) {
114 sigemptyset(&sig_mask
);
115 segv_act
.sa_handler
= (void (*)) win_fault
;
116 segv_act
.sa_flags
= SA_ONSTACK
;
117 segv_act
.sa_mask
= sig_mask
;
118 if (sigaction(SIGBUS
, &segv_act
, NULL
) < 0) {
119 perror("sigaction: SIGBUS");
122 segv_act
.sa_handler
= (void (*)) win_fault
;
123 segv_act
.sa_flags
= SA_ONSTACK
;
124 segv_act
.sa_mask
= sig_mask
;
125 if (sigaction(SIGSEGV
, &segv_act
, NULL
) < 0) {
126 perror("sigaction: SIGSEGV");
129 segv_act
.sa_handler
= (void (*)) win_fault
; /* For breakpoints */
130 segv_act
.sa_flags
= SA_ONSTACK
;
131 segv_act
.sa_mask
= sig_mask
;
132 if (sigaction(SIGTRAP
, &segv_act
, NULL
) < 0) {
133 perror("sigaction: SIGTRAP");
137 usr2_act
.sa_handler
= (void (*)) stop_wait
; /* For breakpoints */
138 usr2_act
.sa_flags
= SA_ONSTACK
;
139 usr2_act
.sa_mask
= sig_mask
;
140 if (sigaction(SIGUSR2
, &usr2_act
, NULL
) < 0) {
141 perror("sigaction: SIGUSR2");
144 #endif /* CONFIG_IPC */
145 #endif /* __FreeBSD__ || __NetBSD__ */
148 #endif /* ifndef WINELIB */