Ulrich Weigand | 65bc810 | 1999-11-12 01:00:34 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Sparc signal handling routines |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 3 | * |
Ulrich Weigand | 65bc810 | 1999-11-12 01:00:34 +0000 | [diff] [blame] | 4 | * Copyright 1999 Ulrich Weigand |
Alexandre Julliard | 0799c1a | 2002-03-09 23:29:33 +0000 | [diff] [blame] | 5 | * |
| 6 | * This library is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU Lesser General Public |
| 8 | * License as published by the Free Software Foundation; either |
| 9 | * version 2.1 of the License, or (at your option) any later version. |
| 10 | * |
| 11 | * This library is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 | * Lesser General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU Lesser General Public |
| 17 | * License along with this library; if not, write to the Free Software |
| 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
Ulrich Weigand | 65bc810 | 1999-11-12 01:00:34 +0000 | [diff] [blame] | 19 | */ |
| 20 | |
| 21 | #ifdef __sparc__ |
| 22 | |
| 23 | #include "config.h" |
| 24 | |
Ulrich Weigand | 65bc810 | 1999-11-12 01:00:34 +0000 | [diff] [blame] | 25 | #include <signal.h> |
| 26 | #include <stdlib.h> |
Patrik Stridvall | d016f81 | 2002-08-17 00:43:16 +0000 | [diff] [blame] | 27 | #ifdef HAVE_UNISTD_H |
| 28 | # include <unistd.h> |
| 29 | #endif |
Ulrich Weigand | afd6a4b | 2000-06-04 01:48:05 +0000 | [diff] [blame] | 30 | #include <stdio.h> |
Ulrich Weigand | 65bc810 | 1999-11-12 01:00:34 +0000 | [diff] [blame] | 31 | #include <sys/ucontext.h> |
| 32 | |
Patrik Stridvall | 9c1de6d | 2002-09-12 22:07:02 +0000 | [diff] [blame] | 33 | #include "winternl.h" |
Ulrich Weigand | 65bc810 | 1999-11-12 01:00:34 +0000 | [diff] [blame] | 34 | #include "winbase.h" |
Patrik Stridvall | bc38d6b | 2001-07-20 18:00:00 +0000 | [diff] [blame] | 35 | #include "winnt.h" |
| 36 | |
| 37 | #include "wine/exception.h" |
Ulrich Weigand | 65bc810 | 1999-11-12 01:00:34 +0000 | [diff] [blame] | 38 | #include "global.h" |
| 39 | #include "stackframe.h" |
Patrik Stridvall | bc38d6b | 2001-07-20 18:00:00 +0000 | [diff] [blame] | 40 | |
Alexandre Julliard | 0799c1a | 2002-03-09 23:29:33 +0000 | [diff] [blame] | 41 | #include "wine/debug.h" |
Ulrich Weigand | 65bc810 | 1999-11-12 01:00:34 +0000 | [diff] [blame] | 42 | |
Alexandre Julliard | 0799c1a | 2002-03-09 23:29:33 +0000 | [diff] [blame] | 43 | WINE_DEFAULT_DEBUG_CHANNEL(seh); |
Ulrich Weigand | 65bc810 | 1999-11-12 01:00:34 +0000 | [diff] [blame] | 44 | |
Juraj Hercek | 386d51d | 2002-11-08 18:54:10 +0000 | [diff] [blame] | 45 | #define HANDLER_DEF(name) void name( int __signal, struct siginfo *__siginfo, ucontext_t *__context ) |
| 46 | #define HANDLER_CONTEXT (__context) |
| 47 | |
Patrik Stridvall | 4325554 | 2002-08-09 01:07:29 +0000 | [diff] [blame] | 48 | typedef int (*wine_signal_handler)(unsigned int sig); |
Eric Pouech | 3d4d7e0 | 2002-07-31 18:46:09 +0000 | [diff] [blame] | 49 | |
| 50 | static wine_signal_handler handlers[256]; |
| 51 | |
Alexandre Julliard | b4a4c05 | 2003-01-04 00:19:17 +0000 | [diff] [blame] | 52 | extern void WINAPI EXC_RtlRaiseException( PEXCEPTION_RECORD, PCONTEXT ); |
Eric Pouech | 3d4d7e0 | 2002-07-31 18:46:09 +0000 | [diff] [blame] | 53 | |
| 54 | /*********************************************************************** |
| 55 | * dispatch_signal |
| 56 | */ |
Patrik Stridvall | 4325554 | 2002-08-09 01:07:29 +0000 | [diff] [blame] | 57 | inline static int dispatch_signal(unsigned int sig) |
Eric Pouech | 3d4d7e0 | 2002-07-31 18:46:09 +0000 | [diff] [blame] | 58 | { |
| 59 | if (handlers[sig] == NULL) return 0; |
| 60 | return handlers[sig](sig); |
| 61 | } |
| 62 | |
| 63 | |
Ulrich Weigand | 65bc810 | 1999-11-12 01:00:34 +0000 | [diff] [blame] | 64 | /* |
| 65 | * FIXME: All this works only on Solaris for now |
| 66 | */ |
| 67 | |
| 68 | /********************************************************************** |
| 69 | * save_context |
| 70 | */ |
| 71 | static void save_context( CONTEXT *context, ucontext_t *ucontext ) |
| 72 | { |
| 73 | /* Special registers */ |
| 74 | context->psr = ucontext->uc_mcontext.gregs[REG_PSR]; |
| 75 | context->pc = ucontext->uc_mcontext.gregs[REG_PC]; |
| 76 | context->npc = ucontext->uc_mcontext.gregs[REG_nPC]; |
| 77 | context->y = ucontext->uc_mcontext.gregs[REG_Y]; |
| 78 | context->wim = 0; /* FIXME */ |
| 79 | context->tbr = 0; /* FIXME */ |
| 80 | |
| 81 | /* Global registers */ |
| 82 | context->g0 = 0; /* always */ |
| 83 | context->g1 = ucontext->uc_mcontext.gregs[REG_G1]; |
| 84 | context->g2 = ucontext->uc_mcontext.gregs[REG_G2]; |
| 85 | context->g3 = ucontext->uc_mcontext.gregs[REG_G3]; |
| 86 | context->g4 = ucontext->uc_mcontext.gregs[REG_G4]; |
| 87 | context->g5 = ucontext->uc_mcontext.gregs[REG_G5]; |
| 88 | context->g6 = ucontext->uc_mcontext.gregs[REG_G6]; |
| 89 | context->g7 = ucontext->uc_mcontext.gregs[REG_G7]; |
| 90 | |
| 91 | /* Current 'out' registers */ |
| 92 | context->o0 = ucontext->uc_mcontext.gregs[REG_O0]; |
| 93 | context->o1 = ucontext->uc_mcontext.gregs[REG_O1]; |
| 94 | context->o2 = ucontext->uc_mcontext.gregs[REG_O2]; |
| 95 | context->o3 = ucontext->uc_mcontext.gregs[REG_O3]; |
| 96 | context->o4 = ucontext->uc_mcontext.gregs[REG_O4]; |
| 97 | context->o5 = ucontext->uc_mcontext.gregs[REG_O5]; |
| 98 | context->o6 = ucontext->uc_mcontext.gregs[REG_O6]; |
| 99 | context->o7 = ucontext->uc_mcontext.gregs[REG_O7]; |
| 100 | |
| 101 | /* FIXME: what if the current register window isn't saved? */ |
| 102 | if ( ucontext->uc_mcontext.gwins && ucontext->uc_mcontext.gwins->wbcnt > 0 ) |
| 103 | { |
| 104 | /* Current 'local' registers from first register window */ |
| 105 | context->l0 = ucontext->uc_mcontext.gwins->wbuf[0].rw_local[0]; |
| 106 | context->l1 = ucontext->uc_mcontext.gwins->wbuf[0].rw_local[1]; |
| 107 | context->l2 = ucontext->uc_mcontext.gwins->wbuf[0].rw_local[2]; |
| 108 | context->l3 = ucontext->uc_mcontext.gwins->wbuf[0].rw_local[3]; |
| 109 | context->l4 = ucontext->uc_mcontext.gwins->wbuf[0].rw_local[4]; |
| 110 | context->l5 = ucontext->uc_mcontext.gwins->wbuf[0].rw_local[5]; |
| 111 | context->l6 = ucontext->uc_mcontext.gwins->wbuf[0].rw_local[6]; |
| 112 | context->l7 = ucontext->uc_mcontext.gwins->wbuf[0].rw_local[7]; |
| 113 | |
| 114 | /* Current 'in' registers from first register window */ |
| 115 | context->i0 = ucontext->uc_mcontext.gwins->wbuf[0].rw_in[0]; |
| 116 | context->i1 = ucontext->uc_mcontext.gwins->wbuf[0].rw_in[1]; |
| 117 | context->i2 = ucontext->uc_mcontext.gwins->wbuf[0].rw_in[2]; |
| 118 | context->i3 = ucontext->uc_mcontext.gwins->wbuf[0].rw_in[3]; |
| 119 | context->i4 = ucontext->uc_mcontext.gwins->wbuf[0].rw_in[4]; |
| 120 | context->i5 = ucontext->uc_mcontext.gwins->wbuf[0].rw_in[5]; |
| 121 | context->i6 = ucontext->uc_mcontext.gwins->wbuf[0].rw_in[6]; |
| 122 | context->i7 = ucontext->uc_mcontext.gwins->wbuf[0].rw_in[7]; |
| 123 | } |
| 124 | } |
| 125 | |
| 126 | /********************************************************************** |
| 127 | * restore_context |
| 128 | */ |
| 129 | static void restore_context( CONTEXT *context, ucontext_t *ucontext ) |
| 130 | { |
| 131 | /* FIXME */ |
| 132 | } |
| 133 | |
| 134 | /********************************************************************** |
| 135 | * save_fpu |
| 136 | */ |
| 137 | static void save_fpu( CONTEXT *context, ucontext_t *ucontext ) |
| 138 | { |
| 139 | /* FIXME */ |
| 140 | } |
| 141 | |
| 142 | /********************************************************************** |
| 143 | * restore_fpu |
| 144 | */ |
| 145 | static void restore_fpu( CONTEXT *context, ucontext_t *ucontext ) |
| 146 | { |
| 147 | /* FIXME */ |
| 148 | } |
| 149 | |
| 150 | |
| 151 | /********************************************************************** |
| 152 | * segv_handler |
| 153 | * |
| 154 | * Handler for SIGSEGV. |
| 155 | */ |
| 156 | static void segv_handler( int signal, siginfo_t *info, ucontext_t *ucontext ) |
| 157 | { |
| 158 | EXCEPTION_RECORD rec; |
| 159 | CONTEXT context; |
| 160 | |
| 161 | /* we want the page-fault case to be fast */ |
| 162 | if ( info->si_code == SEGV_ACCERR ) |
| 163 | if (VIRTUAL_HandleFault( (LPVOID)info->si_addr )) return; |
| 164 | |
| 165 | save_context( &context, ucontext ); |
| 166 | rec.ExceptionCode = EXCEPTION_ACCESS_VIOLATION; |
| 167 | rec.ExceptionRecord = NULL; |
| 168 | rec.ExceptionFlags = EXCEPTION_CONTINUABLE; |
| 169 | rec.ExceptionAddress = (LPVOID)context.pc; |
| 170 | rec.NumberParameters = 2; |
| 171 | rec.ExceptionInformation[0] = 0; /* FIXME: read/write access ? */ |
| 172 | rec.ExceptionInformation[1] = (DWORD)info->si_addr; |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 173 | |
Ulrich Weigand | eb94c7d | 1999-11-13 23:54:04 +0000 | [diff] [blame] | 174 | EXC_RtlRaiseException( &rec, &context ); |
Ulrich Weigand | 65bc810 | 1999-11-12 01:00:34 +0000 | [diff] [blame] | 175 | restore_context( &context, ucontext ); |
| 176 | } |
| 177 | |
| 178 | /********************************************************************** |
| 179 | * bus_handler |
| 180 | * |
| 181 | * Handler for SIGBUS. |
| 182 | */ |
| 183 | static void bus_handler( int signal, siginfo_t *info, ucontext_t *ucontext ) |
| 184 | { |
| 185 | EXCEPTION_RECORD rec; |
| 186 | CONTEXT context; |
| 187 | |
| 188 | save_context( &context, ucontext ); |
| 189 | rec.ExceptionRecord = NULL; |
| 190 | rec.ExceptionFlags = EXCEPTION_CONTINUABLE; |
| 191 | rec.ExceptionAddress = (LPVOID)context.pc; |
| 192 | rec.NumberParameters = 0; |
| 193 | |
| 194 | if ( info->si_code == BUS_ADRALN ) |
| 195 | rec.ExceptionCode = EXCEPTION_DATATYPE_MISALIGNMENT; |
| 196 | else |
| 197 | rec.ExceptionCode = EXCEPTION_ACCESS_VIOLATION; |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 198 | |
Ulrich Weigand | eb94c7d | 1999-11-13 23:54:04 +0000 | [diff] [blame] | 199 | EXC_RtlRaiseException( &rec, &context ); |
Ulrich Weigand | 65bc810 | 1999-11-12 01:00:34 +0000 | [diff] [blame] | 200 | restore_context( &context, ucontext ); |
| 201 | } |
| 202 | |
| 203 | /********************************************************************** |
| 204 | * ill_handler |
| 205 | * |
| 206 | * Handler for SIGILL. |
| 207 | */ |
| 208 | static void ill_handler( int signal, siginfo_t *info, ucontext_t *ucontext ) |
| 209 | { |
| 210 | EXCEPTION_RECORD rec; |
| 211 | CONTEXT context; |
| 212 | |
| 213 | switch ( info->si_code ) |
| 214 | { |
| 215 | default: |
| 216 | case ILL_ILLOPC: |
| 217 | case ILL_ILLOPN: |
| 218 | case ILL_ILLADR: |
| 219 | case ILL_ILLTRP: |
| 220 | rec.ExceptionCode = EXCEPTION_ILLEGAL_INSTRUCTION; |
| 221 | break; |
| 222 | |
| 223 | case ILL_PRVOPC: |
| 224 | case ILL_PRVREG: |
| 225 | rec.ExceptionCode = EXCEPTION_PRIV_INSTRUCTION; |
| 226 | break; |
| 227 | |
| 228 | case ILL_BADSTK: |
| 229 | rec.ExceptionCode = EXCEPTION_STACK_OVERFLOW; |
| 230 | break; |
| 231 | } |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 232 | |
Ulrich Weigand | 65bc810 | 1999-11-12 01:00:34 +0000 | [diff] [blame] | 233 | save_context( &context, ucontext ); |
| 234 | rec.ExceptionRecord = NULL; |
| 235 | rec.ExceptionFlags = EXCEPTION_CONTINUABLE; |
| 236 | rec.ExceptionAddress = (LPVOID)context.pc; |
| 237 | rec.NumberParameters = 0; |
Ulrich Weigand | eb94c7d | 1999-11-13 23:54:04 +0000 | [diff] [blame] | 238 | EXC_RtlRaiseException( &rec, &context ); |
Ulrich Weigand | 65bc810 | 1999-11-12 01:00:34 +0000 | [diff] [blame] | 239 | restore_context( &context, ucontext ); |
| 240 | } |
| 241 | |
| 242 | |
| 243 | /********************************************************************** |
| 244 | * trap_handler |
| 245 | * |
| 246 | * Handler for SIGTRAP. |
| 247 | */ |
| 248 | static void trap_handler( int signal, siginfo_t *info, ucontext_t *ucontext ) |
| 249 | { |
| 250 | EXCEPTION_RECORD rec; |
| 251 | CONTEXT context; |
| 252 | |
| 253 | switch ( info->si_code ) |
| 254 | { |
| 255 | case TRAP_TRACE: |
| 256 | rec.ExceptionCode = EXCEPTION_SINGLE_STEP; |
| 257 | break; |
| 258 | case TRAP_BRKPT: |
| 259 | default: |
| 260 | rec.ExceptionCode = EXCEPTION_BREAKPOINT; |
| 261 | break; |
| 262 | } |
| 263 | |
| 264 | save_context( &context, ucontext ); |
| 265 | rec.ExceptionFlags = EXCEPTION_CONTINUABLE; |
| 266 | rec.ExceptionRecord = NULL; |
| 267 | rec.ExceptionAddress = (LPVOID)context.pc; |
| 268 | rec.NumberParameters = 0; |
Ulrich Weigand | eb94c7d | 1999-11-13 23:54:04 +0000 | [diff] [blame] | 269 | EXC_RtlRaiseException( &rec, &context ); |
Ulrich Weigand | 65bc810 | 1999-11-12 01:00:34 +0000 | [diff] [blame] | 270 | restore_context( &context, ucontext ); |
| 271 | } |
| 272 | |
| 273 | |
| 274 | /********************************************************************** |
| 275 | * fpe_handler |
| 276 | * |
| 277 | * Handler for SIGFPE. |
| 278 | */ |
| 279 | static void fpe_handler( int signal, siginfo_t *info, ucontext_t *ucontext ) |
| 280 | { |
| 281 | EXCEPTION_RECORD rec; |
| 282 | CONTEXT context; |
| 283 | |
| 284 | switch ( info->si_code ) |
| 285 | { |
| 286 | case FPE_FLTSUB: |
| 287 | rec.ExceptionCode = EXCEPTION_ARRAY_BOUNDS_EXCEEDED; |
| 288 | break; |
| 289 | case FPE_INTDIV: |
| 290 | rec.ExceptionCode = EXCEPTION_INT_DIVIDE_BY_ZERO; |
| 291 | break; |
| 292 | case FPE_INTOVF: |
| 293 | rec.ExceptionCode = EXCEPTION_INT_OVERFLOW; |
| 294 | break; |
| 295 | case FPE_FLTDIV: |
| 296 | rec.ExceptionCode = EXCEPTION_FLT_DIVIDE_BY_ZERO; |
| 297 | break; |
| 298 | case FPE_FLTOVF: |
| 299 | rec.ExceptionCode = EXCEPTION_FLT_OVERFLOW; |
| 300 | break; |
| 301 | case FPE_FLTUND: |
| 302 | rec.ExceptionCode = EXCEPTION_FLT_UNDERFLOW; |
| 303 | break; |
| 304 | case FPE_FLTRES: |
| 305 | rec.ExceptionCode = EXCEPTION_FLT_INEXACT_RESULT; |
| 306 | break; |
| 307 | case FPE_FLTINV: |
| 308 | default: |
| 309 | rec.ExceptionCode = EXCEPTION_FLT_INVALID_OPERATION; |
| 310 | break; |
| 311 | } |
| 312 | |
| 313 | save_context( &context, ucontext ); |
| 314 | save_fpu( &context, ucontext ); |
| 315 | rec.ExceptionFlags = EXCEPTION_CONTINUABLE; |
| 316 | rec.ExceptionRecord = NULL; |
| 317 | rec.ExceptionAddress = (LPVOID)context.pc; |
| 318 | rec.NumberParameters = 0; |
Ulrich Weigand | eb94c7d | 1999-11-13 23:54:04 +0000 | [diff] [blame] | 319 | EXC_RtlRaiseException( &rec, &context ); |
Ulrich Weigand | 65bc810 | 1999-11-12 01:00:34 +0000 | [diff] [blame] | 320 | restore_context( &context, ucontext ); |
| 321 | restore_fpu( &context, ucontext ); |
| 322 | } |
| 323 | |
| 324 | |
| 325 | /********************************************************************** |
| 326 | * int_handler |
| 327 | * |
| 328 | * Handler for SIGINT. |
| 329 | */ |
| 330 | static void int_handler( int signal, siginfo_t *info, ucontext_t *ucontext ) |
| 331 | { |
Eric Pouech | 3d4d7e0 | 2002-07-31 18:46:09 +0000 | [diff] [blame] | 332 | if (!dispatch_signal(SIGINT)) |
Eric Pouech | 93bfa0d | 2002-06-02 21:22:22 +0000 | [diff] [blame] | 333 | { |
| 334 | EXCEPTION_RECORD rec; |
| 335 | CONTEXT context; |
Ulrich Weigand | 65bc810 | 1999-11-12 01:00:34 +0000 | [diff] [blame] | 336 | |
Eric Pouech | 93bfa0d | 2002-06-02 21:22:22 +0000 | [diff] [blame] | 337 | save_context( &context, ucontext ); |
| 338 | rec.ExceptionCode = CONTROL_C_EXIT; |
| 339 | rec.ExceptionFlags = EXCEPTION_CONTINUABLE; |
| 340 | rec.ExceptionRecord = NULL; |
| 341 | rec.ExceptionAddress = (LPVOID)context.pc; |
| 342 | rec.NumberParameters = 0; |
| 343 | EXC_RtlRaiseException( &rec, &context ); |
| 344 | restore_context( &context, ucontext ); |
| 345 | } |
Ulrich Weigand | 65bc810 | 1999-11-12 01:00:34 +0000 | [diff] [blame] | 346 | } |
| 347 | |
Lionel Ulmer | bdb4455 | 2002-10-28 23:56:58 +0000 | [diff] [blame] | 348 | /********************************************************************** |
| 349 | * abrt_handler |
| 350 | * |
| 351 | * Handler for SIGABRT. |
| 352 | */ |
| 353 | static HANDLER_DEF(abrt_handler) |
| 354 | { |
| 355 | EXCEPTION_RECORD rec; |
| 356 | CONTEXT context; |
| 357 | |
| 358 | save_context( &context, HANDLER_CONTEXT ); |
| 359 | rec.ExceptionCode = EXCEPTION_WINE_ASSERTION; |
| 360 | rec.ExceptionFlags = EH_NONCONTINUABLE; |
| 361 | rec.ExceptionRecord = NULL; |
Juraj Hercek | 386d51d | 2002-11-08 18:54:10 +0000 | [diff] [blame] | 362 | rec.ExceptionAddress = (LPVOID)context.pc; |
Lionel Ulmer | bdb4455 | 2002-10-28 23:56:58 +0000 | [diff] [blame] | 363 | rec.NumberParameters = 0; |
| 364 | EXC_RtlRaiseException( &rec, &context ); /* Should never return.. */ |
| 365 | restore_context( &context, HANDLER_CONTEXT ); |
| 366 | } |
Ulrich Weigand | 65bc810 | 1999-11-12 01:00:34 +0000 | [diff] [blame] | 367 | |
Alexandre Julliard | d04ccb8 | 2003-03-04 22:18:43 +0000 | [diff] [blame] | 368 | |
| 369 | /********************************************************************** |
Alexandre Julliard | 6a26e3f | 2003-03-21 23:45:26 +0000 | [diff] [blame] | 370 | * term_handler |
| 371 | * |
| 372 | * Handler for SIGTERM. |
| 373 | */ |
| 374 | static HANDLER_DEF(term_handler) |
| 375 | { |
| 376 | SYSDEPS_AbortThread(0); |
| 377 | } |
| 378 | |
| 379 | |
| 380 | /********************************************************************** |
Alexandre Julliard | d04ccb8 | 2003-03-04 22:18:43 +0000 | [diff] [blame] | 381 | * usr1_handler |
| 382 | * |
| 383 | * Handler for SIGUSR1, used to signal a thread that it got suspended. |
| 384 | */ |
| 385 | static HANDLER_DEF(usr1_handler) |
| 386 | { |
| 387 | /* wait with 0 timeout, will only return once the thread is no longer suspended */ |
| 388 | WaitForMultipleObjectsEx( 0, NULL, FALSE, 0, FALSE ); |
| 389 | } |
| 390 | |
| 391 | |
Ulrich Weigand | 65bc810 | 1999-11-12 01:00:34 +0000 | [diff] [blame] | 392 | /*********************************************************************** |
| 393 | * set_handler |
| 394 | * |
| 395 | * Set a signal handler |
| 396 | */ |
| 397 | static int set_handler( int sig, void (*func)() ) |
| 398 | { |
| 399 | struct sigaction sig_act; |
| 400 | |
| 401 | sig_act.sa_handler = NULL; |
| 402 | sig_act.sa_sigaction = func; |
| 403 | sigemptyset( &sig_act.sa_mask ); |
| 404 | sig_act.sa_flags = SA_SIGINFO; |
| 405 | |
| 406 | return sigaction( sig, &sig_act, NULL ); |
| 407 | } |
| 408 | |
| 409 | |
Ove Kaaven | e4a98ec | 2001-06-15 19:43:15 +0000 | [diff] [blame] | 410 | /*********************************************************************** |
Eric Pouech | 3d4d7e0 | 2002-07-31 18:46:09 +0000 | [diff] [blame] | 411 | * __wine_set_signal_handler (NTDLL.@) |
| 412 | */ |
Patrik Stridvall | 4325554 | 2002-08-09 01:07:29 +0000 | [diff] [blame] | 413 | int __wine_set_signal_handler(unsigned int sig, wine_signal_handler wsh) |
Eric Pouech | 3d4d7e0 | 2002-07-31 18:46:09 +0000 | [diff] [blame] | 414 | { |
| 415 | if (sig > sizeof(handlers) / sizeof(handlers[0])) return -1; |
| 416 | if (handlers[sig] != NULL) return -2; |
| 417 | handlers[sig] = wsh; |
| 418 | return 0; |
| 419 | } |
| 420 | |
| 421 | |
Ulrich Weigand | 65bc810 | 1999-11-12 01:00:34 +0000 | [diff] [blame] | 422 | /********************************************************************** |
| 423 | * SIGNAL_Init |
| 424 | */ |
| 425 | BOOL SIGNAL_Init(void) |
| 426 | { |
Ove Kaaven | e4a98ec | 2001-06-15 19:43:15 +0000 | [diff] [blame] | 427 | sigfillset( &all_sigs ); |
| 428 | |
Ulrich Weigand | 65bc810 | 1999-11-12 01:00:34 +0000 | [diff] [blame] | 429 | if (set_handler( SIGINT, (void (*)())int_handler ) == -1) goto error; |
| 430 | if (set_handler( SIGFPE, (void (*)())fpe_handler ) == -1) goto error; |
| 431 | if (set_handler( SIGSEGV, (void (*)())segv_handler ) == -1) goto error; |
| 432 | if (set_handler( SIGILL, (void (*)())ill_handler ) == -1) goto error; |
| 433 | if (set_handler( SIGBUS, (void (*)())bus_handler ) == -1) goto error; |
| 434 | if (set_handler( SIGTRAP, (void (*)())trap_handler ) == -1) goto error; |
Lionel Ulmer | bdb4455 | 2002-10-28 23:56:58 +0000 | [diff] [blame] | 435 | if (set_handler( SIGABRT, (void (*)())abrt_handler ) == -1) goto error; |
Alexandre Julliard | 6a26e3f | 2003-03-21 23:45:26 +0000 | [diff] [blame] | 436 | if (set_handler( SIGTERM, (void (*)())term_handler ) == -1) goto error; |
Alexandre Julliard | d04ccb8 | 2003-03-04 22:18:43 +0000 | [diff] [blame] | 437 | if (set_handler( SIGUSR1, (void (*)())usr1_handler ) == -1) goto error; |
Lionel Ulmer | bdb4455 | 2002-10-28 23:56:58 +0000 | [diff] [blame] | 438 | return TRUE; |
Ulrich Weigand | 65bc810 | 1999-11-12 01:00:34 +0000 | [diff] [blame] | 439 | |
| 440 | error: |
| 441 | perror("sigaction"); |
| 442 | return FALSE; |
| 443 | } |
| 444 | |
Alexandre Julliard | 50c6b74 | 2002-01-07 18:02:35 +0000 | [diff] [blame] | 445 | |
| 446 | /********************************************************************** |
Alexandre Julliard | 6a26e3f | 2003-03-21 23:45:26 +0000 | [diff] [blame] | 447 | * SIGNAL_Block |
| 448 | * |
| 449 | * Block the async signals. |
Alexandre Julliard | 50c6b74 | 2002-01-07 18:02:35 +0000 | [diff] [blame] | 450 | */ |
Alexandre Julliard | 6a26e3f | 2003-03-21 23:45:26 +0000 | [diff] [blame] | 451 | void SIGNAL_Block(void) |
Alexandre Julliard | 50c6b74 | 2002-01-07 18:02:35 +0000 | [diff] [blame] | 452 | { |
| 453 | sigset_t block_set; |
| 454 | |
Alexandre Julliard | 50c6b74 | 2002-01-07 18:02:35 +0000 | [diff] [blame] | 455 | sigemptyset( &block_set ); |
| 456 | sigaddset( &block_set, SIGALRM ); |
| 457 | sigaddset( &block_set, SIGIO ); |
| 458 | sigaddset( &block_set, SIGHUP ); |
Alexandre Julliard | d04ccb8 | 2003-03-04 22:18:43 +0000 | [diff] [blame] | 459 | sigaddset( &block_set, SIGUSR1 ); |
Alexandre Julliard | 50c6b74 | 2002-01-07 18:02:35 +0000 | [diff] [blame] | 460 | sigaddset( &block_set, SIGUSR2 ); |
| 461 | sigprocmask( SIG_BLOCK, &block_set, NULL ); |
Alexandre Julliard | 6a26e3f | 2003-03-21 23:45:26 +0000 | [diff] [blame] | 462 | } |
Alexandre Julliard | 50c6b74 | 2002-01-07 18:02:35 +0000 | [diff] [blame] | 463 | |
Alexandre Julliard | 6a26e3f | 2003-03-21 23:45:26 +0000 | [diff] [blame] | 464 | |
| 465 | /*********************************************************************** |
| 466 | * SIGNAL_Unblock |
| 467 | * |
| 468 | * Unblock signals. Called from EXC_RtlRaiseException. |
| 469 | */ |
| 470 | void SIGNAL_Unblock(void) |
| 471 | { |
| 472 | sigset_t all_sigs; |
| 473 | |
| 474 | sigfillset( &all_sigs ); |
| 475 | sigprocmask( SIG_UNBLOCK, &all_sigs, NULL ); |
| 476 | } |
| 477 | |
| 478 | |
| 479 | /********************************************************************** |
| 480 | * SIGNAL_Reset |
| 481 | * |
| 482 | * Restore the default handlers. |
| 483 | */ |
| 484 | void SIGNAL_Reset(void) |
| 485 | { |
Alexandre Julliard | 50c6b74 | 2002-01-07 18:02:35 +0000 | [diff] [blame] | 486 | signal( SIGINT, SIG_DFL ); |
| 487 | signal( SIGFPE, SIG_DFL ); |
| 488 | signal( SIGSEGV, SIG_DFL ); |
| 489 | signal( SIGILL, SIG_DFL ); |
| 490 | signal( SIGBUS, SIG_DFL ); |
| 491 | signal( SIGTRAP, SIG_DFL ); |
Alexandre Julliard | 6a26e3f | 2003-03-21 23:45:26 +0000 | [diff] [blame] | 492 | signal( SIGABRT, SIG_DFL ); |
| 493 | signal( SIGTERM, SIG_DFL ); |
Alexandre Julliard | 50c6b74 | 2002-01-07 18:02:35 +0000 | [diff] [blame] | 494 | } |
| 495 | |
| 496 | |
Ulrich Weigand | afd6a4b | 2000-06-04 01:48:05 +0000 | [diff] [blame] | 497 | /********************************************************************** |
Alexandre Julliard | b59627c | 2000-09-24 03:11:54 +0000 | [diff] [blame] | 498 | * __wine_enter_vm86 |
| 499 | */ |
| 500 | void __wine_enter_vm86( CONTEXT *context ) |
| 501 | { |
| 502 | MESSAGE("vm86 mode not supported on this platform\n"); |
| 503 | } |
| 504 | |
| 505 | /********************************************************************** |
Patrik Stridvall | 3ca9823 | 2001-06-20 23:03:14 +0000 | [diff] [blame] | 506 | * DbgBreakPoint (NTDLL.@) |
Ulrich Weigand | afd6a4b | 2000-06-04 01:48:05 +0000 | [diff] [blame] | 507 | */ |
| 508 | void WINAPI DbgBreakPoint(void) |
| 509 | { |
Gregg Mattinson | 07db325 | 2002-06-21 20:10:07 +0000 | [diff] [blame] | 510 | kill(getpid(), SIGTRAP); |
Ulrich Weigand | afd6a4b | 2000-06-04 01:48:05 +0000 | [diff] [blame] | 511 | } |
| 512 | |
| 513 | /********************************************************************** |
Patrik Stridvall | 3ca9823 | 2001-06-20 23:03:14 +0000 | [diff] [blame] | 514 | * DbgUserBreakPoint (NTDLL.@) |
Ulrich Weigand | afd6a4b | 2000-06-04 01:48:05 +0000 | [diff] [blame] | 515 | */ |
| 516 | void WINAPI DbgUserBreakPoint(void) |
| 517 | { |
Gregg Mattinson | 07db325 | 2002-06-21 20:10:07 +0000 | [diff] [blame] | 518 | kill(getpid(), SIGTRAP); |
Ulrich Weigand | afd6a4b | 2000-06-04 01:48:05 +0000 | [diff] [blame] | 519 | } |
| 520 | |
Ulrich Weigand | 65bc810 | 1999-11-12 01:00:34 +0000 | [diff] [blame] | 521 | #endif /* __sparc__ */ |