Fix EXC_segv for the TRAP_sig undefined case (eg FreeBSD).
[wine/wine-kai.git] / dlls / ntdll / exception.c
blob94053d60c2d632f73f433fe3ced05b6ed6afbe22
1 /*
2 * NT exception handling routines
3 *
4 * Copyright 1999 Turchanov Sergey
5 * Copyright 1999 Alexandre Julliard
6 */
8 #include <signal.h>
9 #include "winnt.h"
10 #include "ntddk.h"
11 #include "process.h"
12 #include "global.h"
13 #include "wine/exception.h"
14 #include "stackframe.h"
15 #include "sig_context.h"
16 #include "miscemu.h"
17 #include "debugtools.h"
19 DEFAULT_DEBUG_CHANNEL(seh)
21 /* Exception record for handling exceptions happening inside exception handlers */
22 typedef struct
24 EXCEPTION_FRAME frame;
25 EXCEPTION_FRAME *prevFrame;
26 } EXC_NESTED_FRAME;
28 #ifdef __i386__
29 # define GET_IP(context) ((LPVOID)EIP_reg(context))
30 #else
31 # define GET_IP(context) ((LPVOID)0)
32 #endif /* __i386__ */
34 /* Default hook for built-in debugger */
35 static DWORD default_hook( EXCEPTION_RECORD *rec, CONTEXT *ctx, BOOL first )
37 if (!first)
39 DPRINTF( "stopping process due to unhandled exception %08lx.\n",
40 rec->ExceptionCode );
41 raise( SIGSTOP );
43 return 0; /* not handled */
45 static DEBUGHOOK debug_hook = default_hook;
47 /*******************************************************************
48 * EXC_SetDebugEventHook
49 * EXC_GetDebugEventHook
51 * Set/Get the hook for the built-in debugger.
53 * FIXME: the built-in debugger should use the normal debug events.
55 void EXC_SetDebugEventHook( DEBUGHOOK hook )
57 debug_hook = hook;
59 DEBUGHOOK EXC_GetDebugEventHook(void)
61 return debug_hook;
64 /*******************************************************************
65 * EXC_RaiseHandler
67 * Handler for exceptions happening inside a handler.
69 static DWORD CALLBACK EXC_RaiseHandler( EXCEPTION_RECORD *rec, EXCEPTION_FRAME *frame,
70 CONTEXT *context, EXCEPTION_FRAME **dispatcher )
72 if (rec->ExceptionFlags & (EH_UNWINDING | EH_EXIT_UNWIND))
73 return ExceptionContinueSearch;
74 /* We shouldn't get here so we store faulty frame in dispatcher */
75 *dispatcher = ((EXC_NESTED_FRAME*)frame)->prevFrame;
76 return ExceptionNestedException;
80 /*******************************************************************
81 * EXC_UnwindHandler
83 * Handler for exceptions happening inside an unwind handler.
85 static DWORD CALLBACK EXC_UnwindHandler( EXCEPTION_RECORD *rec, EXCEPTION_FRAME *frame,
86 CONTEXT *context, EXCEPTION_FRAME **dispatcher )
88 if (!(rec->ExceptionFlags & (EH_UNWINDING | EH_EXIT_UNWIND)))
89 return ExceptionContinueSearch;
90 /* We shouldn't get here so we store faulty frame in dispatcher */
91 *dispatcher = ((EXC_NESTED_FRAME*)frame)->prevFrame;
92 return ExceptionCollidedUnwind;
96 /*******************************************************************
97 * EXC_CallHandler
99 * Call an exception handler, setting up an exception frame to catch exceptions
100 * happening during the handler execution.
102 static DWORD EXC_CallHandler( PEXCEPTION_HANDLER handler, PEXCEPTION_HANDLER nested_handler,
103 EXCEPTION_RECORD *record, EXCEPTION_FRAME *frame,
104 CONTEXT *context, EXCEPTION_FRAME **dispatcher )
106 EXC_NESTED_FRAME newframe;
107 DWORD ret;
109 newframe.frame.Handler = nested_handler;
110 newframe.prevFrame = frame;
111 EXC_push_frame( &newframe.frame );
112 TRACE( "calling handler at %p code=%lx flags=%lx\n",
113 handler, record->ExceptionCode, record->ExceptionFlags );
114 ret = handler( record, frame, context, dispatcher );
115 TRACE( "handler returned %lx\n", ret );
116 EXC_pop_frame( &newframe.frame );
117 return ret;
121 /*******************************************************************
122 * EXC_DefaultHandling
124 * Default handling for exceptions. Called when we didn't find a suitable handler.
126 static void EXC_DefaultHandling( EXCEPTION_RECORD *rec, CONTEXT *context )
128 if ((PROCESS_Current()->flags & PDB32_DEBUGGED) &&
129 (DEBUG_SendExceptionEvent( rec, FALSE ) == DBG_CONTINUE))
130 return; /* continue execution */
132 if (debug_hook( rec, context, FALSE ) == DBG_CONTINUE)
133 return; /* continue execution */
135 if (rec->ExceptionFlags & EH_STACK_INVALID)
136 ERR("Exception frame is not in stack limits => unable to dispatch exception.\n");
137 else if (rec->ExceptionCode == EXCEPTION_NONCONTINUABLE_EXCEPTION)
138 ERR("Process attempted to continue execution after noncontinuable exception.\n");
139 else
140 ERR("Unhandled exception code %lx flags %lx addr %p\n",
141 rec->ExceptionCode, rec->ExceptionFlags, rec->ExceptionAddress );
142 TerminateProcess( GetCurrentProcess(), 1 );
146 /***********************************************************************
147 * RtlRaiseException (NTDLL.464)
149 void WINAPI REGS_FUNC(RtlRaiseException)( EXCEPTION_RECORD *rec, CONTEXT *context )
151 PEXCEPTION_FRAME frame, dispatch, nested_frame;
152 EXCEPTION_RECORD newrec;
153 DWORD res;
155 TRACE( "code=%lx flags=%lx\n", rec->ExceptionCode, rec->ExceptionFlags );
157 if ((PROCESS_Current()->flags & PDB32_DEBUGGED) &&
158 (DEBUG_SendExceptionEvent( rec, TRUE ) == DBG_CONTINUE))
159 return; /* continue execution */
161 if (debug_hook( rec, context, TRUE ) == DBG_CONTINUE)
162 return; /* continue execution */
164 frame = NtCurrentTeb()->except;
165 nested_frame = NULL;
166 while (frame != (PEXCEPTION_FRAME)0xFFFFFFFF)
168 /* Check frame address */
169 if (((void*)frame < NtCurrentTeb()->stack_low) ||
170 ((void*)(frame+1) > NtCurrentTeb()->stack_top) ||
171 (int)frame & 3)
173 rec->ExceptionFlags |= EH_STACK_INVALID;
174 break;
177 /* Call handler */
178 res = EXC_CallHandler( frame->Handler, EXC_RaiseHandler, rec, frame, context, &dispatch );
179 if (frame == nested_frame)
181 /* no longer nested */
182 nested_frame = NULL;
183 rec->ExceptionFlags &= ~EH_NESTED_CALL;
186 switch(res)
188 case ExceptionContinueExecution:
189 if (!(rec->ExceptionFlags & EH_NONCONTINUABLE)) return;
190 newrec.ExceptionCode = STATUS_NONCONTINUABLE_EXCEPTION;
191 newrec.ExceptionFlags = EH_NONCONTINUABLE;
192 newrec.ExceptionRecord = rec;
193 newrec.NumberParameters = 0;
194 RtlRaiseException( &newrec ); /* never returns */
195 break;
196 case ExceptionContinueSearch:
197 break;
198 case ExceptionNestedException:
199 if (nested_frame < dispatch) nested_frame = dispatch;
200 rec->ExceptionFlags |= EH_NESTED_CALL;
201 break;
202 default:
203 newrec.ExceptionCode = STATUS_INVALID_DISPOSITION;
204 newrec.ExceptionFlags = EH_NONCONTINUABLE;
205 newrec.ExceptionRecord = rec;
206 newrec.NumberParameters = 0;
207 RtlRaiseException( &newrec ); /* never returns */
208 break;
210 frame = frame->Prev;
212 EXC_DefaultHandling( rec, context );
216 /*******************************************************************
217 * RtlUnwind (KERNEL32.590) (NTDLL.518)
219 void WINAPI REGS_FUNC(RtlUnwind)( PEXCEPTION_FRAME pEndFrame, LPVOID unusedEip,
220 PEXCEPTION_RECORD pRecord, DWORD returnEax,
221 CONTEXT *context )
223 EXCEPTION_RECORD record, newrec;
224 PEXCEPTION_FRAME frame, dispatch;
226 #ifdef __i386__
227 EAX_reg(context) = returnEax;
228 #endif
230 /* build an exception record, if we do not have one */
231 if (!pRecord)
233 record.ExceptionCode = STATUS_UNWIND;
234 record.ExceptionFlags = 0;
235 record.ExceptionRecord = NULL;
236 record.ExceptionAddress = GET_IP(context);
237 record.NumberParameters = 0;
238 pRecord = &record;
241 pRecord->ExceptionFlags |= EH_UNWINDING | (pEndFrame ? 0 : EH_EXIT_UNWIND);
243 TRACE( "code=%lx flags=%lx\n", pRecord->ExceptionCode, pRecord->ExceptionFlags );
245 /* get chain of exception frames */
246 frame = NtCurrentTeb()->except;
247 while ((frame != (PEXCEPTION_FRAME)0xffffffff) && (frame != pEndFrame))
249 /* Check frame address */
250 if (pEndFrame && (frame > pEndFrame))
252 newrec.ExceptionCode = STATUS_INVALID_UNWIND_TARGET;
253 newrec.ExceptionFlags = EH_NONCONTINUABLE;
254 newrec.ExceptionRecord = pRecord;
255 newrec.NumberParameters = 0;
256 RtlRaiseException( &newrec ); /* never returns */
258 if (((void*)frame < NtCurrentTeb()->stack_low) ||
259 ((void*)(frame+1) > NtCurrentTeb()->stack_top) ||
260 (int)frame & 3)
262 newrec.ExceptionCode = STATUS_BAD_STACK;
263 newrec.ExceptionFlags = EH_NONCONTINUABLE;
264 newrec.ExceptionRecord = pRecord;
265 newrec.NumberParameters = 0;
266 RtlRaiseException( &newrec ); /* never returns */
269 /* Call handler */
270 switch(EXC_CallHandler( frame->Handler, EXC_UnwindHandler, pRecord,
271 frame, context, &dispatch ))
273 case ExceptionContinueSearch:
274 break;
275 case ExceptionCollidedUnwind:
276 frame = dispatch;
277 break;
278 default:
279 newrec.ExceptionCode = STATUS_INVALID_DISPOSITION;
280 newrec.ExceptionFlags = EH_NONCONTINUABLE;
281 newrec.ExceptionRecord = pRecord;
282 newrec.NumberParameters = 0;
283 RtlRaiseException( &newrec ); /* never returns */
284 break;
286 frame = EXC_pop_frame( frame );
291 /*******************************************************************
292 * NtRaiseException (NTDLL.175)
294 * Real prototype:
295 * DWORD WINAPI NtRaiseException( EXCEPTION_RECORD *rec, CONTEXT *ctx, BOOL first );
297 void WINAPI REGS_FUNC(NtRaiseException)( EXCEPTION_RECORD *rec, CONTEXT *ctx,
298 BOOL first, CONTEXT *context )
300 REGS_FUNC(RtlRaiseException)( rec, ctx );
301 *context = *ctx;
305 /***********************************************************************
306 * RtlRaiseStatus (NTDLL.465)
308 * Raise an exception with ExceptionCode = status
310 void WINAPI RtlRaiseStatus( NTSTATUS status )
312 EXCEPTION_RECORD ExceptionRec;
314 ExceptionRec.ExceptionCode = status;
315 ExceptionRec.ExceptionFlags = EH_NONCONTINUABLE;
316 ExceptionRec.ExceptionRecord = NULL;
317 ExceptionRec.NumberParameters = 0;
318 RtlRaiseException( &ExceptionRec );
322 /***********************************************************************
323 * DebugBreak (KERNEL32.181)
325 void WINAPI REGS_FUNC(DebugBreak)( CONTEXT *context )
327 EXCEPTION_RECORD rec;
329 rec.ExceptionCode = EXCEPTION_BREAKPOINT;
330 rec.ExceptionFlags = EH_NONCONTINUABLE;
331 rec.ExceptionRecord = NULL;
332 rec.NumberParameters = 0;
333 REGS_FUNC(RtlRaiseException)( &rec, context );
337 /***********************************************************************
338 * DebugBreak16 (KERNEL.203)
340 void WINAPI DebugBreak16( CONTEXT86 *context )
342 #ifdef __i386__
343 REGS_FUNC(DebugBreak)( context );
344 #endif /* defined(__i386__) */
348 /***********************************************************************
349 * EXC_SaveContext
351 * Set the register values from a sigcontext.
353 static void EXC_SaveContext( CONTEXT *context, const SIGCONTEXT *sigcontext )
355 #ifdef __i386__
356 EAX_reg(context) = EAX_sig(sigcontext);
357 EBX_reg(context) = EBX_sig(sigcontext);
358 ECX_reg(context) = ECX_sig(sigcontext);
359 EDX_reg(context) = EDX_sig(sigcontext);
360 ESI_reg(context) = ESI_sig(sigcontext);
361 EDI_reg(context) = EDI_sig(sigcontext);
362 EBP_reg(context) = EBP_sig(sigcontext);
363 EFL_reg(context) = EFL_sig(sigcontext);
364 EIP_reg(context) = EIP_sig(sigcontext);
365 ESP_reg(context) = ESP_sig(sigcontext);
366 CS_reg(context) = LOWORD(CS_sig(sigcontext));
367 DS_reg(context) = LOWORD(DS_sig(sigcontext));
368 ES_reg(context) = LOWORD(ES_sig(sigcontext));
369 SS_reg(context) = LOWORD(SS_sig(sigcontext));
370 #ifdef FS_sig
371 FS_reg(context) = LOWORD(FS_sig(sigcontext));
372 #else
373 GET_FS( FS_reg(context) );
374 FS_reg(context) &= 0xffff;
375 #endif
376 #ifdef GS_sig
377 GS_reg(context) = LOWORD(GS_sig(sigcontext));
378 #else
379 GET_GS( GS_reg(context) );
380 GS_reg(context) &= 0xffff;
381 #endif
382 if (ISV86(context)) V86BASE(context) = (DWORD)DOSMEM_MemoryBase(0);
383 #endif /* __i386__ */
387 /***********************************************************************
388 * EXC_RestoreContext
390 * Build a sigcontext from the register values.
392 static void EXC_RestoreContext( const CONTEXT *context, SIGCONTEXT *sigcontext )
394 #ifdef __i386__
395 EAX_sig(sigcontext) = EAX_reg(context);
396 EBX_sig(sigcontext) = EBX_reg(context);
397 ECX_sig(sigcontext) = ECX_reg(context);
398 EDX_sig(sigcontext) = EDX_reg(context);
399 ESI_sig(sigcontext) = ESI_reg(context);
400 EDI_sig(sigcontext) = EDI_reg(context);
401 EBP_sig(sigcontext) = EBP_reg(context);
402 EFL_sig(sigcontext) = EFL_reg(context);
403 EIP_sig(sigcontext) = EIP_reg(context);
404 ESP_sig(sigcontext) = ESP_reg(context);
405 CS_sig(sigcontext) = CS_reg(context);
406 DS_sig(sigcontext) = DS_reg(context);
407 ES_sig(sigcontext) = ES_reg(context);
408 SS_sig(sigcontext) = SS_reg(context);
409 #ifdef FS_sig
410 FS_sig(sigcontext) = FS_reg(context);
411 #else
412 SET_FS( FS_reg(context) );
413 #endif
414 #ifdef GS_sig
415 GS_sig(sigcontext) = GS_reg(context);
416 #else
417 SET_GS( GS_reg(context) );
418 #endif
419 #endif /* __i386__ */
423 /**********************************************************************
424 * EXC_segv
426 * Handler for SIGSEGV and related errors.
428 static HANDLER_DEF(EXC_segv)
430 EXCEPTION_RECORD rec;
431 CONTEXT context;
433 HANDLER_INIT();
435 #if defined(TRAP_sig) && defined(CR2_sig)
436 /* we want the page-fault case to be fast */
437 if (TRAP_sig(HANDLER_CONTEXT) == 14)
438 if (VIRTUAL_HandleFault( (LPVOID)CR2_sig(HANDLER_CONTEXT) )) return;
439 #endif
441 EXC_SaveContext( &context, HANDLER_CONTEXT );
442 rec.ExceptionRecord = NULL;
443 rec.ExceptionFlags = EH_NONCONTINUABLE;
444 rec.ExceptionAddress = GET_IP(&context);
445 rec.NumberParameters = 0;
447 #ifdef TRAP_sig
448 switch(TRAP_sig(HANDLER_CONTEXT))
450 case 4: /* Overflow exception */
451 rec.ExceptionCode = EXCEPTION_INT_OVERFLOW;
452 break;
453 case 5: /* Bound range exception */
454 rec.ExceptionCode = EXCEPTION_ARRAY_BOUNDS_EXCEEDED;
455 break;
456 case 6: /* Invalid opcode exception */
457 rec.ExceptionCode = EXCEPTION_ILLEGAL_INSTRUCTION;
458 break;
459 case 12: /* Stack fault */
460 rec.ExceptionCode = EXCEPTION_STACK_OVERFLOW;
461 break;
462 case 11: /* Segment not present exception */
463 case 13: /* General protection fault */
464 if (INSTR_EmulateInstruction( &context )) goto restore;
465 rec.ExceptionCode = EXCEPTION_PRIV_INSTRUCTION;
466 break;
467 case 14: /* Page fault */
468 #ifdef CR2_sig
469 rec.NumberParameters = 2;
470 #ifdef ERROR_sig
471 rec.ExceptionInformation[0] = (ERROR_sig(HANDLER_CONTEXT) & 2) != 0;
472 #else
473 rec.ExceptionInformation[0] = 0;
474 #endif /* ERROR_sig */
475 rec.ExceptionInformation[1] = CR2_sig(HANDLER_CONTEXT);
476 #endif /* CR2_sig */
477 rec.ExceptionCode = EXCEPTION_ACCESS_VIOLATION;
478 break;
479 case 17: /* Alignment check exception */
480 /* FIXME: pass through exception handler first? */
481 if (EFL_reg(&context) & 0x00040000)
483 /* Disable AC flag, return */
484 EFL_reg(&context) &= ~0x00040000;
485 goto restore;
487 rec.ExceptionCode = EXCEPTION_DATATYPE_MISALIGNMENT;
488 break;
489 default:
490 ERR( "Got unexpected trap %ld\n", TRAP_sig(HANDLER_CONTEXT) );
491 /* fall through */
492 case 2: /* NMI interrupt */
493 case 7: /* Device not available exception */
494 case 8: /* Double fault exception */
495 case 10: /* Invalid TSS exception */
496 case 15: /* Unknown exception */
497 case 18: /* Machine check exception */
498 case 19: /* Cache flush exception */
499 rec.ExceptionCode = EXCEPTION_ILLEGAL_INSTRUCTION;
500 break;
502 #else /* TRAP_sig */
503 # ifdef __i386__
504 if (INSTR_EmulateInstruction( &context )) goto restore;
505 # endif
506 rec.ExceptionCode = EXCEPTION_ILLEGAL_INSTRUCTION; /* generic error */
507 #endif /* TRAP_sig */
509 REGS_FUNC(RtlRaiseException)( &rec, &context );
510 restore:
511 EXC_RestoreContext( &context, HANDLER_CONTEXT );
515 /**********************************************************************
516 * EXC_trap
518 * Handler for SIGTRAP.
520 static HANDLER_DEF(EXC_trap)
522 EXCEPTION_RECORD rec;
523 CONTEXT context;
525 HANDLER_INIT();
527 #ifdef TRAP_sig
528 rec.ExceptionCode = (TRAP_sig(HANDLER_CONTEXT) == 1) ?
529 EXCEPTION_SINGLE_STEP : EXCEPTION_BREAKPOINT;
530 #else
531 rec.ExceptionCode = EXCEPTION_BREAKPOINT;
532 #endif /* TRAP_sig */
534 EXC_SaveContext( &context, HANDLER_CONTEXT );
535 rec.ExceptionFlags = EXCEPTION_CONTINUABLE;
536 rec.ExceptionRecord = NULL;
537 rec.ExceptionAddress = GET_IP(&context);
538 rec.NumberParameters = 0;
539 REGS_FUNC(RtlRaiseException)( &rec, &context );
540 EXC_RestoreContext( &context, HANDLER_CONTEXT );
544 /***********************************************************************
545 * EXC_SaveFPU
547 * Set the FPU context from a sigcontext.
549 static void inline EXC_SaveFPU( CONTEXT *context, const SIGCONTEXT *sigcontext )
551 #ifdef __i386__
552 # ifdef FPU_sig
553 if (FPU_sig(sigcontext))
555 context->FloatSave = *FPU_sig(sigcontext);
556 return;
558 # endif /* FPU_sig */
559 # ifdef __GNUC__
560 __asm__ __volatile__( "fnsave %0; fwait" : "=m" (context->FloatSave) );
561 # endif /* __GNUC__ */
562 #endif /* __i386__ */
566 /***********************************************************************
567 * EXC_RestoreFPU
569 * Restore the FPU context to a sigcontext.
571 static void inline EXC_RestoreFPU( CONTEXT *context, const SIGCONTEXT *sigcontext )
573 #ifdef __i386__
574 # ifdef FPU_sig
575 if (FPU_sig(sigcontext))
577 *FPU_sig(sigcontext) = context->FloatSave;
578 return;
580 # endif /* FPU_sig */
581 # ifdef __GNUC__
582 /* avoid nested exceptions */
583 context->FloatSave.StatusWord &= context->FloatSave.ControlWord | 0xffffff80;
584 __asm__ __volatile__( "frstor %0; fwait" : : "m" (context->FloatSave) );
585 # endif /* __GNUC__ */
586 #endif /* __i386__ */
590 /**********************************************************************
591 * EXC_GetFPUCode
593 * Get the FPU exception code from the FPU status.
595 static inline DWORD EXC_GetFPUCode( const CONTEXT *context )
597 #ifdef __i386__
598 DWORD status = context->FloatSave.StatusWord;
600 if (status & 0x01) /* IE */
602 if (status & 0x40) /* SF */
603 return EXCEPTION_FLT_STACK_CHECK;
604 else
605 return EXCEPTION_FLT_INVALID_OPERATION;
607 if (status & 0x02) return EXCEPTION_FLT_DENORMAL_OPERAND; /* DE flag */
608 if (status & 0x04) return EXCEPTION_FLT_DIVIDE_BY_ZERO; /* ZE flag */
609 if (status & 0x08) return EXCEPTION_FLT_OVERFLOW; /* OE flag */
610 if (status & 0x10) return EXCEPTION_FLT_UNDERFLOW; /* UE flag */
611 if (status & 0x20) return EXCEPTION_FLT_INEXACT_RESULT; /* PE flag */
612 #endif /* __i386__ */
613 return EXCEPTION_FLT_INVALID_OPERATION; /* generic error */
617 /**********************************************************************
618 * EXC_fpe
620 * Handler for SIGFPE.
622 static HANDLER_DEF(EXC_fpe)
624 EXCEPTION_RECORD rec;
625 CONTEXT context;
627 HANDLER_INIT();
629 EXC_SaveFPU( &context, HANDLER_CONTEXT );
631 #ifdef TRAP_sig
632 switch(TRAP_sig(HANDLER_CONTEXT))
634 case 0: /* Division by zero exception */
635 rec.ExceptionCode = EXCEPTION_INT_DIVIDE_BY_ZERO;
636 break;
637 case 9: /* Coprocessor segment overrun */
638 rec.ExceptionCode = EXCEPTION_FLT_INVALID_OPERATION;
639 break;
640 case 16: /* Floating point exception */
641 rec.ExceptionCode = EXC_GetFPUCode( &context );
642 break;
643 default:
644 ERR( "Got unexpected trap %ld\n", TRAP_sig(HANDLER_CONTEXT) );
645 rec.ExceptionCode = EXCEPTION_FLT_INVALID_OPERATION;
646 break;
648 #else /* TRAP_sig */
649 rec.ExceptionCode = EXC_GetFPUCode( &context );
650 #endif /* TRAP_sig */
652 EXC_SaveContext( &context, HANDLER_CONTEXT );
653 rec.ExceptionFlags = EH_NONCONTINUABLE;
654 rec.ExceptionRecord = NULL;
655 rec.ExceptionAddress = GET_IP(&context);
656 rec.NumberParameters = 0;
657 REGS_FUNC(RtlRaiseException)( &rec, &context );
658 EXC_RestoreContext( &context, HANDLER_CONTEXT );
659 EXC_RestoreFPU( &context, HANDLER_CONTEXT );
663 /**********************************************************************
664 * EXC_int
666 * Handler for SIGINT.
668 static HANDLER_DEF(EXC_int)
670 EXCEPTION_RECORD rec;
671 CONTEXT context;
673 HANDLER_INIT();
675 EXC_SaveContext( &context, HANDLER_CONTEXT );
676 rec.ExceptionCode = CONTROL_C_EXIT;
677 rec.ExceptionFlags = EH_NONCONTINUABLE;
678 rec.ExceptionRecord = NULL;
679 rec.ExceptionAddress = GET_IP(&context);
680 rec.NumberParameters = 0;
681 REGS_FUNC(RtlRaiseException)( &rec, &context );
682 EXC_RestoreContext( &context, HANDLER_CONTEXT );
686 /**********************************************************************
687 * EXC_InitHandlers
689 * Initialize the signal handlers for exception handling.
691 void EXC_InitHandlers(void)
693 SIGNAL_SetHandler( SIGINT, (void (*)())EXC_int );
694 SIGNAL_SetHandler( SIGFPE, (void (*)())EXC_fpe );
695 SIGNAL_SetHandler( SIGSEGV, (void (*)())EXC_segv );
696 SIGNAL_SetHandler( SIGILL, (void (*)())EXC_segv );
697 #ifdef SIGBUS
698 SIGNAL_SetHandler( SIGBUS, (void (*)())EXC_segv );
699 #endif
700 #ifdef SIGTRAP
701 SIGNAL_SetHandler( SIGTRAP, (void (*)())EXC_trap );
702 #endif
703 return;