10 #if defined(__NetBSD__) || defined(__FreeBSD__)
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));
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 == WINE_CODE_SELECTOR)
60 fprintf(stderr, "Segmentation fault in Wine program (%x:%lx)."
61 " Please debug\n", CS, EIP );
63 else if (INSTR_EmulateInstruction( context )) return;
64 fprintf(stderr,"In win_fault %x:%lx\n", CS, EIP );
66 XUngrabPointer(display, CurrentTime);
67 XUngrabServer(display);
69 wine_debug( signal, context ); /* Enter our debugger */
72 void init_wine_signals(void)
74 extern void stop_wait(int a);
76 segv_act.sa_handler = (__sighandler_t) win_fault;
77 /* Point to the top of the stack, minus 4 just in case, and make
79 segv_act.sa_restorer =
80 (void (*)()) (((unsigned int)(cstack) + sizeof(cstack) - 4) & ~3);
81 usr2_act.sa_restorer= segv_act.sa_restorer;
82 usr2_act.sa_handler = (__sighandler_t) stop_wait;
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);
88 wine_sigaction(SIGUSR2, &usr2_act, NULL);
90 wine_sigaction(SIGBUS, &segv_act, NULL);
92 wine_sigaction(SIGTRAP, &segv_act, NULL); /* For breakpoints */
94 #if defined(__NetBSD__) || defined(__FreeBSD__)
96 struct sigaltstack ss;
98 #if !defined (__FreeBSD__)
99 if ((ss.ss_base = malloc(MINSIGSTKSZ)) == NULL) {
101 if ((ss.ss_sp = malloc(MINSIGSTKSZ)) == NULL) {
103 fprintf(stderr, "Unable to allocate signal stack (%d bytes)\n",
107 ss.ss_size = MINSIGSTKSZ;
109 if (sigaltstack(&ss, NULL) < 0) {
113 sigemptyset(&sig_mask);
114 segv_act.sa_handler = (void (*)) win_fault;
115 segv_act.sa_flags = SA_ONSTACK;
116 segv_act.sa_mask = sig_mask;
117 if (sigaction(SIGBUS, &segv_act, NULL) < 0) {
118 perror("sigaction: SIGBUS");
121 segv_act.sa_handler = (void (*)) win_fault;
122 segv_act.sa_flags = SA_ONSTACK;
123 segv_act.sa_mask = sig_mask;
124 if (sigaction(SIGSEGV, &segv_act, NULL) < 0) {
125 perror("sigaction: SIGSEGV");
128 segv_act.sa_handler = (void (*)) win_fault; /* For breakpoints */
129 segv_act.sa_flags = SA_ONSTACK;
130 segv_act.sa_mask = sig_mask;
131 if (sigaction(SIGTRAP, &segv_act, NULL) < 0) {
132 perror("sigaction: SIGTRAP");
135 usr2_act.sa_handler = (void (*)) stop_wait; /* For breakpoints */
136 usr2_act.sa_flags = SA_ONSTACK;
137 usr2_act.sa_mask = sig_mask;
138 if (sigaction(SIGUSR2, &usr2_act, NULL) < 0) {
139 perror("sigaction: SIGUSR2");
145 #endif /* ifndef WINELIB */