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 |
Jonathan Ernst | 360a3f9 | 2006-05-18 14:49:52 +0200 | [diff] [blame] | 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA |
Ulrich Weigand | 65bc810 | 1999-11-12 01:00:34 +0000 | [diff] [blame] | 19 | */ |
| 20 | |
| 21 | #ifdef __sparc__ |
| 22 | |
| 23 | #include "config.h" |
Alexandre Julliard | fb9cead | 2005-09-14 10:36:58 +0000 | [diff] [blame] | 24 | #include "wine/port.h" |
Ulrich Weigand | 65bc810 | 1999-11-12 01:00:34 +0000 | [diff] [blame] | 25 | |
Alexandre Julliard | fb9cead | 2005-09-14 10:36:58 +0000 | [diff] [blame] | 26 | #include <assert.h> |
Ulrich Weigand | 65bc810 | 1999-11-12 01:00:34 +0000 | [diff] [blame] | 27 | #include <signal.h> |
| 28 | #include <stdlib.h> |
Patrik Stridvall | d016f81 | 2002-08-17 00:43:16 +0000 | [diff] [blame] | 29 | #ifdef HAVE_UNISTD_H |
| 30 | # include <unistd.h> |
| 31 | #endif |
Alexandre Julliard | e37c6e1 | 2003-09-05 23:08:26 +0000 | [diff] [blame] | 32 | #include <stdarg.h> |
Ulrich Weigand | afd6a4b | 2000-06-04 01:48:05 +0000 | [diff] [blame] | 33 | #include <stdio.h> |
Ulrich Weigand | 65bc810 | 1999-11-12 01:00:34 +0000 | [diff] [blame] | 34 | #include <sys/ucontext.h> |
| 35 | |
Alexandre Julliard | e37c6e1 | 2003-09-05 23:08:26 +0000 | [diff] [blame] | 36 | #include "windef.h" |
Alexandre Julliard | e37c6e1 | 2003-09-05 23:08:26 +0000 | [diff] [blame] | 37 | #include "winternl.h" |
Patrik Stridvall | bc38d6b | 2001-07-20 18:00:00 +0000 | [diff] [blame] | 38 | #include "winnt.h" |
| 39 | |
| 40 | #include "wine/exception.h" |
Alexandre Julliard | 217fdab | 2003-06-30 21:00:15 +0000 | [diff] [blame] | 41 | #include "ntdll_misc.h" |
Patrik Stridvall | bc38d6b | 2001-07-20 18:00:00 +0000 | [diff] [blame] | 42 | |
Alexandre Julliard | 0799c1a | 2002-03-09 23:29:33 +0000 | [diff] [blame] | 43 | #include "wine/debug.h" |
Ulrich Weigand | 65bc810 | 1999-11-12 01:00:34 +0000 | [diff] [blame] | 44 | |
Alexandre Julliard | 0799c1a | 2002-03-09 23:29:33 +0000 | [diff] [blame] | 45 | WINE_DEFAULT_DEBUG_CHANNEL(seh); |
Ulrich Weigand | 65bc810 | 1999-11-12 01:00:34 +0000 | [diff] [blame] | 46 | |
Juraj Hercek | 386d51d | 2002-11-08 18:54:10 +0000 | [diff] [blame] | 47 | #define HANDLER_DEF(name) void name( int __signal, struct siginfo *__siginfo, ucontext_t *__context ) |
| 48 | #define HANDLER_CONTEXT (__context) |
| 49 | |
Patrik Stridvall | 4325554 | 2002-08-09 01:07:29 +0000 | [diff] [blame] | 50 | typedef int (*wine_signal_handler)(unsigned int sig); |
Eric Pouech | 3d4d7e0 | 2002-07-31 18:46:09 +0000 | [diff] [blame] | 51 | |
| 52 | static wine_signal_handler handlers[256]; |
| 53 | |
Eric Pouech | 3d4d7e0 | 2002-07-31 18:46:09 +0000 | [diff] [blame] | 54 | /*********************************************************************** |
| 55 | * dispatch_signal |
| 56 | */ |
Andrew Talbot | 0108667 | 2007-03-17 10:28:32 +0000 | [diff] [blame] | 57 | static inline 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 | |
Alexandre Julliard | 2654be0 | 2006-01-11 20:20:32 +0100 | [diff] [blame] | 151 | /*********************************************************************** |
Alexandre Julliard | d2ad6f8 | 2006-04-20 15:40:28 +0200 | [diff] [blame] | 152 | * get_cpu_context |
| 153 | * |
| 154 | * Get the context of the current thread. |
| 155 | */ |
| 156 | void get_cpu_context( CONTEXT *context ) |
| 157 | { |
| 158 | FIXME("not implemented\n"); |
| 159 | } |
| 160 | |
| 161 | |
| 162 | /*********************************************************************** |
Alexandre Julliard | 2654be0 | 2006-01-11 20:20:32 +0100 | [diff] [blame] | 163 | * set_cpu_context |
| 164 | * |
| 165 | * Set the new CPU context. |
| 166 | */ |
| 167 | void set_cpu_context( const CONTEXT *context ) |
| 168 | { |
| 169 | FIXME("not implemented\n"); |
| 170 | } |
| 171 | |
| 172 | |
Ulrich Weigand | 65bc810 | 1999-11-12 01:00:34 +0000 | [diff] [blame] | 173 | /********************************************************************** |
| 174 | * segv_handler |
| 175 | * |
| 176 | * Handler for SIGSEGV. |
| 177 | */ |
| 178 | static void segv_handler( int signal, siginfo_t *info, ucontext_t *ucontext ) |
| 179 | { |
| 180 | EXCEPTION_RECORD rec; |
| 181 | CONTEXT context; |
| 182 | |
Alexandre Julliard | 81b9ca5 | 2008-11-25 12:02:16 +0100 | [diff] [blame^] | 183 | rec.ExceptionCode = EXCEPTION_ACCESS_VIOLATION; |
| 184 | |
Ulrich Weigand | 65bc810 | 1999-11-12 01:00:34 +0000 | [diff] [blame] | 185 | /* we want the page-fault case to be fast */ |
| 186 | if ( info->si_code == SEGV_ACCERR ) |
Alexandre Julliard | 81b9ca5 | 2008-11-25 12:02:16 +0100 | [diff] [blame^] | 187 | if (!(rec.ExceptionCode = virtual_handle_fault( info->si_addr, 0 ))) return; |
Ulrich Weigand | 65bc810 | 1999-11-12 01:00:34 +0000 | [diff] [blame] | 188 | |
| 189 | save_context( &context, ucontext ); |
Ulrich Weigand | 65bc810 | 1999-11-12 01:00:34 +0000 | [diff] [blame] | 190 | rec.ExceptionRecord = NULL; |
| 191 | rec.ExceptionFlags = EXCEPTION_CONTINUABLE; |
| 192 | rec.ExceptionAddress = (LPVOID)context.pc; |
| 193 | rec.NumberParameters = 2; |
| 194 | rec.ExceptionInformation[0] = 0; /* FIXME: read/write access ? */ |
Dmitry Timoshkov | 0497af0 | 2005-02-24 13:15:36 +0000 | [diff] [blame] | 195 | rec.ExceptionInformation[1] = (ULONG_PTR)info->si_addr; |
Vincent BĂ©ron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 196 | |
Alexandre Julliard | 26050b4 | 2005-05-07 18:10:30 +0000 | [diff] [blame] | 197 | __regs_RtlRaiseException( &rec, &context ); |
Ulrich Weigand | 65bc810 | 1999-11-12 01:00:34 +0000 | [diff] [blame] | 198 | restore_context( &context, ucontext ); |
| 199 | } |
| 200 | |
| 201 | /********************************************************************** |
| 202 | * bus_handler |
| 203 | * |
| 204 | * Handler for SIGBUS. |
| 205 | */ |
| 206 | static void bus_handler( int signal, siginfo_t *info, ucontext_t *ucontext ) |
| 207 | { |
| 208 | EXCEPTION_RECORD rec; |
| 209 | CONTEXT context; |
| 210 | |
| 211 | save_context( &context, ucontext ); |
| 212 | rec.ExceptionRecord = NULL; |
| 213 | rec.ExceptionFlags = EXCEPTION_CONTINUABLE; |
| 214 | rec.ExceptionAddress = (LPVOID)context.pc; |
| 215 | rec.NumberParameters = 0; |
| 216 | |
| 217 | if ( info->si_code == BUS_ADRALN ) |
| 218 | rec.ExceptionCode = EXCEPTION_DATATYPE_MISALIGNMENT; |
| 219 | else |
| 220 | rec.ExceptionCode = EXCEPTION_ACCESS_VIOLATION; |
Vincent BĂ©ron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 221 | |
Alexandre Julliard | 26050b4 | 2005-05-07 18:10:30 +0000 | [diff] [blame] | 222 | __regs_RtlRaiseException( &rec, &context ); |
Ulrich Weigand | 65bc810 | 1999-11-12 01:00:34 +0000 | [diff] [blame] | 223 | restore_context( &context, ucontext ); |
| 224 | } |
| 225 | |
| 226 | /********************************************************************** |
| 227 | * ill_handler |
| 228 | * |
| 229 | * Handler for SIGILL. |
| 230 | */ |
| 231 | static void ill_handler( int signal, siginfo_t *info, ucontext_t *ucontext ) |
| 232 | { |
| 233 | EXCEPTION_RECORD rec; |
| 234 | CONTEXT context; |
| 235 | |
| 236 | switch ( info->si_code ) |
| 237 | { |
| 238 | default: |
| 239 | case ILL_ILLOPC: |
| 240 | case ILL_ILLOPN: |
| 241 | case ILL_ILLADR: |
| 242 | case ILL_ILLTRP: |
| 243 | rec.ExceptionCode = EXCEPTION_ILLEGAL_INSTRUCTION; |
| 244 | break; |
| 245 | |
| 246 | case ILL_PRVOPC: |
| 247 | case ILL_PRVREG: |
| 248 | rec.ExceptionCode = EXCEPTION_PRIV_INSTRUCTION; |
| 249 | break; |
| 250 | |
| 251 | case ILL_BADSTK: |
| 252 | rec.ExceptionCode = EXCEPTION_STACK_OVERFLOW; |
| 253 | break; |
| 254 | } |
Vincent BĂ©ron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 255 | |
Ulrich Weigand | 65bc810 | 1999-11-12 01:00:34 +0000 | [diff] [blame] | 256 | save_context( &context, ucontext ); |
| 257 | rec.ExceptionRecord = NULL; |
| 258 | rec.ExceptionFlags = EXCEPTION_CONTINUABLE; |
| 259 | rec.ExceptionAddress = (LPVOID)context.pc; |
| 260 | rec.NumberParameters = 0; |
Alexandre Julliard | 26050b4 | 2005-05-07 18:10:30 +0000 | [diff] [blame] | 261 | __regs_RtlRaiseException( &rec, &context ); |
Ulrich Weigand | 65bc810 | 1999-11-12 01:00:34 +0000 | [diff] [blame] | 262 | restore_context( &context, ucontext ); |
| 263 | } |
| 264 | |
| 265 | |
| 266 | /********************************************************************** |
| 267 | * trap_handler |
| 268 | * |
| 269 | * Handler for SIGTRAP. |
| 270 | */ |
| 271 | static void trap_handler( int signal, siginfo_t *info, ucontext_t *ucontext ) |
| 272 | { |
| 273 | EXCEPTION_RECORD rec; |
| 274 | CONTEXT context; |
| 275 | |
| 276 | switch ( info->si_code ) |
| 277 | { |
| 278 | case TRAP_TRACE: |
| 279 | rec.ExceptionCode = EXCEPTION_SINGLE_STEP; |
| 280 | break; |
| 281 | case TRAP_BRKPT: |
| 282 | default: |
| 283 | rec.ExceptionCode = EXCEPTION_BREAKPOINT; |
| 284 | break; |
| 285 | } |
| 286 | |
| 287 | save_context( &context, ucontext ); |
| 288 | rec.ExceptionFlags = EXCEPTION_CONTINUABLE; |
| 289 | rec.ExceptionRecord = NULL; |
| 290 | rec.ExceptionAddress = (LPVOID)context.pc; |
| 291 | rec.NumberParameters = 0; |
Alexandre Julliard | 26050b4 | 2005-05-07 18:10:30 +0000 | [diff] [blame] | 292 | __regs_RtlRaiseException( &rec, &context ); |
Ulrich Weigand | 65bc810 | 1999-11-12 01:00:34 +0000 | [diff] [blame] | 293 | restore_context( &context, ucontext ); |
| 294 | } |
| 295 | |
| 296 | |
| 297 | /********************************************************************** |
| 298 | * fpe_handler |
| 299 | * |
| 300 | * Handler for SIGFPE. |
| 301 | */ |
| 302 | static void fpe_handler( int signal, siginfo_t *info, ucontext_t *ucontext ) |
| 303 | { |
| 304 | EXCEPTION_RECORD rec; |
| 305 | CONTEXT context; |
| 306 | |
| 307 | switch ( info->si_code ) |
| 308 | { |
| 309 | case FPE_FLTSUB: |
| 310 | rec.ExceptionCode = EXCEPTION_ARRAY_BOUNDS_EXCEEDED; |
| 311 | break; |
| 312 | case FPE_INTDIV: |
| 313 | rec.ExceptionCode = EXCEPTION_INT_DIVIDE_BY_ZERO; |
| 314 | break; |
| 315 | case FPE_INTOVF: |
| 316 | rec.ExceptionCode = EXCEPTION_INT_OVERFLOW; |
| 317 | break; |
| 318 | case FPE_FLTDIV: |
| 319 | rec.ExceptionCode = EXCEPTION_FLT_DIVIDE_BY_ZERO; |
| 320 | break; |
| 321 | case FPE_FLTOVF: |
| 322 | rec.ExceptionCode = EXCEPTION_FLT_OVERFLOW; |
| 323 | break; |
| 324 | case FPE_FLTUND: |
| 325 | rec.ExceptionCode = EXCEPTION_FLT_UNDERFLOW; |
| 326 | break; |
| 327 | case FPE_FLTRES: |
| 328 | rec.ExceptionCode = EXCEPTION_FLT_INEXACT_RESULT; |
| 329 | break; |
| 330 | case FPE_FLTINV: |
| 331 | default: |
| 332 | rec.ExceptionCode = EXCEPTION_FLT_INVALID_OPERATION; |
| 333 | break; |
| 334 | } |
| 335 | |
| 336 | save_context( &context, ucontext ); |
| 337 | save_fpu( &context, ucontext ); |
| 338 | rec.ExceptionFlags = EXCEPTION_CONTINUABLE; |
| 339 | rec.ExceptionRecord = NULL; |
| 340 | rec.ExceptionAddress = (LPVOID)context.pc; |
| 341 | rec.NumberParameters = 0; |
Alexandre Julliard | 26050b4 | 2005-05-07 18:10:30 +0000 | [diff] [blame] | 342 | __regs_RtlRaiseException( &rec, &context ); |
Ulrich Weigand | 65bc810 | 1999-11-12 01:00:34 +0000 | [diff] [blame] | 343 | restore_context( &context, ucontext ); |
| 344 | restore_fpu( &context, ucontext ); |
| 345 | } |
| 346 | |
| 347 | |
| 348 | /********************************************************************** |
| 349 | * int_handler |
| 350 | * |
| 351 | * Handler for SIGINT. |
| 352 | */ |
| 353 | static void int_handler( int signal, siginfo_t *info, ucontext_t *ucontext ) |
| 354 | { |
Eric Pouech | 3d4d7e0 | 2002-07-31 18:46:09 +0000 | [diff] [blame] | 355 | if (!dispatch_signal(SIGINT)) |
Eric Pouech | 93bfa0d | 2002-06-02 21:22:22 +0000 | [diff] [blame] | 356 | { |
| 357 | EXCEPTION_RECORD rec; |
| 358 | CONTEXT context; |
Ulrich Weigand | 65bc810 | 1999-11-12 01:00:34 +0000 | [diff] [blame] | 359 | |
Eric Pouech | 93bfa0d | 2002-06-02 21:22:22 +0000 | [diff] [blame] | 360 | save_context( &context, ucontext ); |
| 361 | rec.ExceptionCode = CONTROL_C_EXIT; |
| 362 | rec.ExceptionFlags = EXCEPTION_CONTINUABLE; |
| 363 | rec.ExceptionRecord = NULL; |
| 364 | rec.ExceptionAddress = (LPVOID)context.pc; |
| 365 | rec.NumberParameters = 0; |
Alexandre Julliard | 26050b4 | 2005-05-07 18:10:30 +0000 | [diff] [blame] | 366 | __regs_RtlRaiseException( &rec, &context ); |
Eric Pouech | 93bfa0d | 2002-06-02 21:22:22 +0000 | [diff] [blame] | 367 | restore_context( &context, ucontext ); |
| 368 | } |
Ulrich Weigand | 65bc810 | 1999-11-12 01:00:34 +0000 | [diff] [blame] | 369 | } |
| 370 | |
Lionel Ulmer | bdb4455 | 2002-10-28 23:56:58 +0000 | [diff] [blame] | 371 | /********************************************************************** |
| 372 | * abrt_handler |
| 373 | * |
| 374 | * Handler for SIGABRT. |
| 375 | */ |
| 376 | static HANDLER_DEF(abrt_handler) |
| 377 | { |
| 378 | EXCEPTION_RECORD rec; |
| 379 | CONTEXT context; |
| 380 | |
| 381 | save_context( &context, HANDLER_CONTEXT ); |
| 382 | rec.ExceptionCode = EXCEPTION_WINE_ASSERTION; |
| 383 | rec.ExceptionFlags = EH_NONCONTINUABLE; |
| 384 | rec.ExceptionRecord = NULL; |
Juraj Hercek | 386d51d | 2002-11-08 18:54:10 +0000 | [diff] [blame] | 385 | rec.ExceptionAddress = (LPVOID)context.pc; |
Lionel Ulmer | bdb4455 | 2002-10-28 23:56:58 +0000 | [diff] [blame] | 386 | rec.NumberParameters = 0; |
Alexandre Julliard | 26050b4 | 2005-05-07 18:10:30 +0000 | [diff] [blame] | 387 | __regs_RtlRaiseException( &rec, &context ); /* Should never return.. */ |
Lionel Ulmer | bdb4455 | 2002-10-28 23:56:58 +0000 | [diff] [blame] | 388 | restore_context( &context, HANDLER_CONTEXT ); |
| 389 | } |
Ulrich Weigand | 65bc810 | 1999-11-12 01:00:34 +0000 | [diff] [blame] | 390 | |
Alexandre Julliard | d04ccb8 | 2003-03-04 22:18:43 +0000 | [diff] [blame] | 391 | |
| 392 | /********************************************************************** |
Alexandre Julliard | 3b244b9 | 2007-12-20 12:19:35 +0100 | [diff] [blame] | 393 | * quit_handler |
Alexandre Julliard | 6a26e3f | 2003-03-21 23:45:26 +0000 | [diff] [blame] | 394 | * |
Alexandre Julliard | 3b244b9 | 2007-12-20 12:19:35 +0100 | [diff] [blame] | 395 | * Handler for SIGQUIT. |
Alexandre Julliard | 6a26e3f | 2003-03-21 23:45:26 +0000 | [diff] [blame] | 396 | */ |
Alexandre Julliard | 3b244b9 | 2007-12-20 12:19:35 +0100 | [diff] [blame] | 397 | static HANDLER_DEF(quit_handler) |
Alexandre Julliard | 6a26e3f | 2003-03-21 23:45:26 +0000 | [diff] [blame] | 398 | { |
Alexandre Julliard | 4dba172 | 2003-11-06 00:08:05 +0000 | [diff] [blame] | 399 | server_abort_thread(0); |
Alexandre Julliard | 6a26e3f | 2003-03-21 23:45:26 +0000 | [diff] [blame] | 400 | } |
| 401 | |
| 402 | |
| 403 | /********************************************************************** |
Alexandre Julliard | d04ccb8 | 2003-03-04 22:18:43 +0000 | [diff] [blame] | 404 | * usr1_handler |
| 405 | * |
| 406 | * Handler for SIGUSR1, used to signal a thread that it got suspended. |
| 407 | */ |
| 408 | static HANDLER_DEF(usr1_handler) |
| 409 | { |
Alexandre Julliard | 73c7239 | 2005-11-02 20:54:12 +0000 | [diff] [blame] | 410 | CONTEXT context; |
Eric Pouech | 14d04b6 | 2003-04-03 23:57:11 +0000 | [diff] [blame] | 411 | |
Alexandre Julliard | 73c7239 | 2005-11-02 20:54:12 +0000 | [diff] [blame] | 412 | save_context( &context, HANDLER_CONTEXT ); |
| 413 | wait_suspend( &context ); |
| 414 | restore_context( &context, HANDLER_CONTEXT ); |
Alexandre Julliard | fb9cead | 2005-09-14 10:36:58 +0000 | [diff] [blame] | 415 | } |
| 416 | |
| 417 | |
| 418 | /********************************************************************** |
| 419 | * get_signal_stack_total_size |
| 420 | * |
| 421 | * Retrieve the size to allocate for the signal stack, including the TEB at the bottom. |
| 422 | * Must be a power of two. |
| 423 | */ |
| 424 | size_t get_signal_stack_total_size(void) |
| 425 | { |
| 426 | assert( sizeof(TEB) <= getpagesize() ); |
| 427 | return getpagesize(); /* this is just for the TEB, we don't need a signal stack */ |
Alexandre Julliard | d04ccb8 | 2003-03-04 22:18:43 +0000 | [diff] [blame] | 428 | } |
| 429 | |
| 430 | |
Ulrich Weigand | 65bc810 | 1999-11-12 01:00:34 +0000 | [diff] [blame] | 431 | /*********************************************************************** |
| 432 | * set_handler |
| 433 | * |
| 434 | * Set a signal handler |
| 435 | */ |
| 436 | static int set_handler( int sig, void (*func)() ) |
| 437 | { |
| 438 | struct sigaction sig_act; |
| 439 | |
Ulrich Weigand | 65bc810 | 1999-11-12 01:00:34 +0000 | [diff] [blame] | 440 | sig_act.sa_sigaction = func; |
Alexandre Julliard | c388c58 | 2007-01-18 12:20:56 +0100 | [diff] [blame] | 441 | sig_act.sa_mask = server_block_set; |
Ulrich Weigand | 65bc810 | 1999-11-12 01:00:34 +0000 | [diff] [blame] | 442 | sig_act.sa_flags = SA_SIGINFO; |
| 443 | |
| 444 | return sigaction( sig, &sig_act, NULL ); |
| 445 | } |
| 446 | |
| 447 | |
Ove Kaaven | e4a98ec | 2001-06-15 19:43:15 +0000 | [diff] [blame] | 448 | /*********************************************************************** |
Eric Pouech | 3d4d7e0 | 2002-07-31 18:46:09 +0000 | [diff] [blame] | 449 | * __wine_set_signal_handler (NTDLL.@) |
| 450 | */ |
Patrik Stridvall | 4325554 | 2002-08-09 01:07:29 +0000 | [diff] [blame] | 451 | int __wine_set_signal_handler(unsigned int sig, wine_signal_handler wsh) |
Eric Pouech | 3d4d7e0 | 2002-07-31 18:46:09 +0000 | [diff] [blame] | 452 | { |
| 453 | if (sig > sizeof(handlers) / sizeof(handlers[0])) return -1; |
| 454 | if (handlers[sig] != NULL) return -2; |
| 455 | handlers[sig] = wsh; |
| 456 | return 0; |
| 457 | } |
| 458 | |
| 459 | |
Ulrich Weigand | 65bc810 | 1999-11-12 01:00:34 +0000 | [diff] [blame] | 460 | /********************************************************************** |
Alexandre Julliard | 531ff0b | 2008-07-03 20:18:23 +0200 | [diff] [blame] | 461 | * signal_init_thread |
Ulrich Weigand | 65bc810 | 1999-11-12 01:00:34 +0000 | [diff] [blame] | 462 | */ |
Alexandre Julliard | 531ff0b | 2008-07-03 20:18:23 +0200 | [diff] [blame] | 463 | void signal_init_thread(void) |
| 464 | { |
| 465 | } |
| 466 | |
| 467 | /********************************************************************** |
| 468 | * signal_init_process |
| 469 | */ |
| 470 | void signal_init_process(void) |
Ulrich Weigand | 65bc810 | 1999-11-12 01:00:34 +0000 | [diff] [blame] | 471 | { |
Ulrich Weigand | 65bc810 | 1999-11-12 01:00:34 +0000 | [diff] [blame] | 472 | if (set_handler( SIGINT, (void (*)())int_handler ) == -1) goto error; |
| 473 | if (set_handler( SIGFPE, (void (*)())fpe_handler ) == -1) goto error; |
| 474 | if (set_handler( SIGSEGV, (void (*)())segv_handler ) == -1) goto error; |
| 475 | if (set_handler( SIGILL, (void (*)())ill_handler ) == -1) goto error; |
| 476 | if (set_handler( SIGBUS, (void (*)())bus_handler ) == -1) goto error; |
| 477 | if (set_handler( SIGTRAP, (void (*)())trap_handler ) == -1) goto error; |
Lionel Ulmer | bdb4455 | 2002-10-28 23:56:58 +0000 | [diff] [blame] | 478 | if (set_handler( SIGABRT, (void (*)())abrt_handler ) == -1) goto error; |
Alexandre Julliard | 3b244b9 | 2007-12-20 12:19:35 +0100 | [diff] [blame] | 479 | if (set_handler( SIGQUIT, (void (*)())quit_handler ) == -1) goto error; |
Alexandre Julliard | d04ccb8 | 2003-03-04 22:18:43 +0000 | [diff] [blame] | 480 | if (set_handler( SIGUSR1, (void (*)())usr1_handler ) == -1) goto error; |
Eric Frias | c8866c0 | 2004-11-21 15:38:26 +0000 | [diff] [blame] | 481 | /* 'ta 6' tells the kernel to synthesize any unaligned accesses this |
| 482 | process makes, instead of just signalling an error and terminating |
| 483 | the process. wine-devel did not reach a conclusion on whether |
| 484 | this is correct, because that is what x86 does, or it is harmful |
| 485 | because it could obscure problems in user code */ |
| 486 | asm("ta 6"); /* 6 == ST_FIX_ALIGN defined in sys/trap.h */ |
Alexandre Julliard | 531ff0b | 2008-07-03 20:18:23 +0200 | [diff] [blame] | 487 | signal_init_thread(); |
| 488 | return; |
Ulrich Weigand | 65bc810 | 1999-11-12 01:00:34 +0000 | [diff] [blame] | 489 | |
| 490 | error: |
| 491 | perror("sigaction"); |
Alexandre Julliard | 531ff0b | 2008-07-03 20:18:23 +0200 | [diff] [blame] | 492 | exit(1); |
Ulrich Weigand | 65bc810 | 1999-11-12 01:00:34 +0000 | [diff] [blame] | 493 | } |
| 494 | |
Alexandre Julliard | 50c6b74 | 2002-01-07 18:02:35 +0000 | [diff] [blame] | 495 | |
| 496 | /********************************************************************** |
Alexandre Julliard | b59627c | 2000-09-24 03:11:54 +0000 | [diff] [blame] | 497 | * __wine_enter_vm86 |
| 498 | */ |
| 499 | void __wine_enter_vm86( CONTEXT *context ) |
| 500 | { |
| 501 | MESSAGE("vm86 mode not supported on this platform\n"); |
| 502 | } |
| 503 | |
| 504 | /********************************************************************** |
Patrik Stridvall | 3ca9823 | 2001-06-20 23:03:14 +0000 | [diff] [blame] | 505 | * DbgBreakPoint (NTDLL.@) |
Ulrich Weigand | afd6a4b | 2000-06-04 01:48:05 +0000 | [diff] [blame] | 506 | */ |
| 507 | void WINAPI DbgBreakPoint(void) |
| 508 | { |
Gregg Mattinson | 07db325 | 2002-06-21 20:10:07 +0000 | [diff] [blame] | 509 | kill(getpid(), SIGTRAP); |
Ulrich Weigand | afd6a4b | 2000-06-04 01:48:05 +0000 | [diff] [blame] | 510 | } |
| 511 | |
| 512 | /********************************************************************** |
Patrik Stridvall | 3ca9823 | 2001-06-20 23:03:14 +0000 | [diff] [blame] | 513 | * DbgUserBreakPoint (NTDLL.@) |
Ulrich Weigand | afd6a4b | 2000-06-04 01:48:05 +0000 | [diff] [blame] | 514 | */ |
| 515 | void WINAPI DbgUserBreakPoint(void) |
| 516 | { |
Gregg Mattinson | 07db325 | 2002-06-21 20:10:07 +0000 | [diff] [blame] | 517 | kill(getpid(), SIGTRAP); |
Ulrich Weigand | afd6a4b | 2000-06-04 01:48:05 +0000 | [diff] [blame] | 518 | } |
| 519 | |
Ulrich Weigand | 65bc810 | 1999-11-12 01:00:34 +0000 | [diff] [blame] | 520 | #endif /* __sparc__ */ |