msxml3: Added IObjectWithSite support in IXMLDOMDocument2.
[wine] / dlls / msvcrt / except.c
1 /*
2  * msvcrt.dll exception handling
3  *
4  * Copyright 2000 Jon Griffiths
5  * Copyright 2005 Juan Lang
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20  *
21  * FIXME: Incomplete support for nested exceptions/try block cleanup.
22  */
23
24 #include "config.h"
25 #include "wine/port.h"
26
27 #include <stdarg.h>
28
29 #include "windef.h"
30 #include "winbase.h"
31 #include "winternl.h"
32 #include "wine/exception.h"
33 #include "msvcrt.h"
34 #include "excpt.h"
35 #include "wincon.h"
36 #include "msvcrt/float.h"
37 #include "wine/debug.h"
38
39 WINE_DEFAULT_DEBUG_CHANNEL(seh);
40
41 /* VC++ extensions to Win32 SEH */
42 typedef struct _SCOPETABLE
43 {
44   int previousTryLevel;
45   int (*lpfnFilter)(PEXCEPTION_POINTERS);
46   int (*lpfnHandler)(void);
47 } SCOPETABLE, *PSCOPETABLE;
48
49 typedef struct _MSVCRT_EXCEPTION_FRAME
50 {
51   EXCEPTION_REGISTRATION_RECORD *prev;
52   void (*handler)(PEXCEPTION_RECORD, EXCEPTION_REGISTRATION_RECORD*,
53                   PCONTEXT, PEXCEPTION_RECORD);
54   PSCOPETABLE scopetable;
55   int trylevel;
56   int _ebp;
57   PEXCEPTION_POINTERS xpointers;
58 } MSVCRT_EXCEPTION_FRAME;
59
60 #define TRYLEVEL_END (-1) /* End of trylevel list */
61
62 #if defined(__GNUC__) && defined(__i386__)
63 static inline void call_finally_block( void *code_block, void *base_ptr )
64 {
65     __asm__ __volatile__ ("movl %1,%%ebp; call *%%eax"
66                           : : "a" (code_block), "g" (base_ptr));
67 }
68
69 static inline int call_filter( int (*func)(PEXCEPTION_POINTERS), void *arg, void *ebp )
70 {
71     int ret;
72     __asm__ __volatile__ ("pushl %%ebp; pushl %3; movl %2,%%ebp; call *%%eax; popl %%ebp; popl %%ebp"
73                           : "=a" (ret)
74                           : "0" (func), "r" (ebp), "r" (arg)
75                           : "ecx", "edx", "memory" );
76     return ret;
77 }
78
79 static inline int call_unwind_func( int (*func)(void), void *ebp )
80 {
81     int ret;
82     __asm__ __volatile__ ("pushl %%ebp\n\t"
83                           "pushl %%ebx\n\t"
84                           "pushl %%esi\n\t"
85                           "pushl %%edi\n\t"
86                           "movl %2,%%ebp\n\t"
87                           "call *%0\n\t"
88                           "popl %%edi\n\t"
89                           "popl %%esi\n\t"
90                           "popl %%ebx\n\t"
91                           "popl %%ebp"
92                           : "=a" (ret)
93                           : "0" (func), "r" (ebp)
94                           : "ecx", "edx", "memory" );
95     return ret;
96 }
97
98 #endif
99
100 static DWORD MSVCRT_nested_handler(PEXCEPTION_RECORD rec,
101                                    EXCEPTION_REGISTRATION_RECORD* frame,
102                                    PCONTEXT context,
103                                    EXCEPTION_REGISTRATION_RECORD** dispatch)
104 {
105   if (!(rec->ExceptionFlags & (EH_UNWINDING | EH_EXIT_UNWIND)))
106     return ExceptionContinueSearch;
107   *dispatch = frame;
108   return ExceptionCollidedUnwind;
109 }
110
111
112 /*********************************************************************
113  *              _EH_prolog (MSVCRT.@)
114  */
115 #ifdef __i386__
116 /* Provided for VC++ binary compatibility only */
117 __ASM_GLOBAL_FUNC(_EH_prolog,
118                   "pushl $-1\n\t"
119                   "pushl %eax\n\t"
120                   "pushl %fs:0\n\t"
121                   "movl  %esp, %fs:0\n\t"
122                   "movl  12(%esp), %eax\n\t"
123                   "movl  %ebp, 12(%esp)\n\t"
124                   "leal  12(%esp), %ebp\n\t"
125                   "pushl %eax\n\t"
126                   "ret")
127
128 static void msvcrt_local_unwind2(MSVCRT_EXCEPTION_FRAME* frame, int trylevel, void *ebp)
129 {
130   EXCEPTION_REGISTRATION_RECORD reg;
131
132   TRACE("(%p,%d,%d)\n",frame, frame->trylevel, trylevel);
133
134   /* Register a handler in case of a nested exception */
135   reg.Handler = MSVCRT_nested_handler;
136   reg.Prev = NtCurrentTeb()->Tib.ExceptionList;
137   __wine_push_frame(&reg);
138
139   while (frame->trylevel != TRYLEVEL_END && frame->trylevel != trylevel)
140   {
141       int level = frame->trylevel;
142       frame->trylevel = frame->scopetable[level].previousTryLevel;
143       if (!frame->scopetable[level].lpfnFilter)
144       {
145           TRACE( "__try block cleanup level %d handler %p ebp %p\n",
146                  level, frame->scopetable[level].lpfnHandler, ebp );
147           call_unwind_func( frame->scopetable[level].lpfnHandler, ebp );
148       }
149   }
150   __wine_pop_frame(&reg);
151   TRACE("unwound OK\n");
152 }
153
154 /*******************************************************************
155  *              _local_unwind2 (MSVCRT.@)
156  */
157 void CDECL _local_unwind2(MSVCRT_EXCEPTION_FRAME* frame, int trylevel)
158 {
159     msvcrt_local_unwind2( frame, trylevel, &frame->_ebp );
160 }
161
162 #endif  /* __i386__ */
163
164 /*******************************************************************
165  *              _global_unwind2 (MSVCRT.@)
166  */
167 void CDECL _global_unwind2(EXCEPTION_REGISTRATION_RECORD* frame)
168 {
169     TRACE("(%p)\n",frame);
170     RtlUnwind( frame, 0, 0, 0 );
171 }
172
173 /*********************************************************************
174  *              _except_handler2 (MSVCRT.@)
175  */
176 int CDECL _except_handler2(PEXCEPTION_RECORD rec,
177                            EXCEPTION_REGISTRATION_RECORD* frame,
178                            PCONTEXT context,
179                            EXCEPTION_REGISTRATION_RECORD** dispatcher)
180 {
181   FIXME("exception %x flags=%x at %p handler=%p %p %p stub\n",
182         rec->ExceptionCode, rec->ExceptionFlags, rec->ExceptionAddress,
183         frame->Handler, context, dispatcher);
184   return ExceptionContinueSearch;
185 }
186
187 /*********************************************************************
188  *              _except_handler3 (MSVCRT.@)
189  */
190 int CDECL _except_handler3(PEXCEPTION_RECORD rec,
191                            MSVCRT_EXCEPTION_FRAME* frame,
192                            PCONTEXT context, void* dispatcher)
193 {
194 #if defined(__GNUC__) && defined(__i386__)
195   int retval, trylevel;
196   EXCEPTION_POINTERS exceptPtrs;
197   PSCOPETABLE pScopeTable;
198
199   TRACE("exception %x flags=%x at %p handler=%p %p %p semi-stub\n",
200         rec->ExceptionCode, rec->ExceptionFlags, rec->ExceptionAddress,
201         frame->handler, context, dispatcher);
202
203   __asm__ __volatile__ ("cld");
204
205   if (rec->ExceptionFlags & (EH_UNWINDING | EH_EXIT_UNWIND))
206   {
207     /* Unwinding the current frame */
208     msvcrt_local_unwind2(frame, TRYLEVEL_END, &frame->_ebp);
209     TRACE("unwound current frame, returning ExceptionContinueSearch\n");
210     return ExceptionContinueSearch;
211   }
212   else
213   {
214     /* Hunting for handler */
215     exceptPtrs.ExceptionRecord = rec;
216     exceptPtrs.ContextRecord = context;
217     *((DWORD *)frame-1) = (DWORD)&exceptPtrs;
218     trylevel = frame->trylevel;
219     pScopeTable = frame->scopetable;
220
221     while (trylevel != TRYLEVEL_END)
222     {
223       if (pScopeTable[trylevel].lpfnFilter)
224       {
225         TRACE("filter = %p\n", pScopeTable[trylevel].lpfnFilter);
226
227         retval = call_filter( pScopeTable[trylevel].lpfnFilter, &exceptPtrs, &frame->_ebp );
228
229         TRACE("filter returned %s\n", retval == EXCEPTION_CONTINUE_EXECUTION ?
230               "CONTINUE_EXECUTION" : retval == EXCEPTION_EXECUTE_HANDLER ?
231               "EXECUTE_HANDLER" : "CONTINUE_SEARCH");
232
233         if (retval == EXCEPTION_CONTINUE_EXECUTION)
234           return ExceptionContinueExecution;
235
236         if (retval == EXCEPTION_EXECUTE_HANDLER)
237         {
238           /* Unwind all higher frames, this one will handle the exception */
239           _global_unwind2((EXCEPTION_REGISTRATION_RECORD*)frame);
240           msvcrt_local_unwind2(frame, trylevel, &frame->_ebp);
241
242           /* Set our trylevel to the enclosing block, and call the __finally
243            * code, which won't return
244            */
245           frame->trylevel = pScopeTable->previousTryLevel;
246           TRACE("__finally block %p\n",pScopeTable[trylevel].lpfnHandler);
247           call_finally_block(pScopeTable[trylevel].lpfnHandler, &frame->_ebp);
248           ERR("Returned from __finally block - expect crash!\n");
249        }
250       }
251       trylevel = pScopeTable->previousTryLevel;
252     }
253   }
254 #else
255   FIXME("exception %lx flags=%lx at %p handler=%p %p %p stub\n",
256         rec->ExceptionCode, rec->ExceptionFlags, rec->ExceptionAddress,
257         frame->handler, context, dispatcher);
258 #endif
259   TRACE("reached TRYLEVEL_END, returning ExceptionContinueSearch\n");
260   return ExceptionContinueSearch;
261 }
262
263 /*********************************************************************
264  *              _abnormal_termination (MSVCRT.@)
265  */
266 int CDECL _abnormal_termination(void)
267 {
268   FIXME("(void)stub\n");
269   return 0;
270 }
271
272 /*
273  * setjmp/longjmp implementation
274  */
275
276 #ifdef __i386__
277 #define MSVCRT_JMP_MAGIC 0x56433230 /* ID value for new jump structure */
278 typedef void (__stdcall *MSVCRT_unwind_function)(const struct MSVCRT___JUMP_BUFFER *);
279
280 /* define an entrypoint for setjmp/setjmp3 that stores the registers in the jmp buf */
281 /* and then jumps to the C backend function */
282 #define DEFINE_SETJMP_ENTRYPOINT(name) \
283     __ASM_GLOBAL_FUNC( name, \
284                        "movl 4(%esp),%ecx\n\t"   /* jmp_buf */      \
285                        "movl %ebp,0(%ecx)\n\t"   /* jmp_buf.Ebp */  \
286                        "movl %ebx,4(%ecx)\n\t"   /* jmp_buf.Ebx */  \
287                        "movl %edi,8(%ecx)\n\t"   /* jmp_buf.Edi */  \
288                        "movl %esi,12(%ecx)\n\t"  /* jmp_buf.Esi */  \
289                        "movl %esp,16(%ecx)\n\t"  /* jmp_buf.Esp */  \
290                        "movl 0(%esp),%eax\n\t"                      \
291                        "movl %eax,20(%ecx)\n\t"  /* jmp_buf.Eip */  \
292                        "jmp " __ASM_NAME("__regs_") # name )
293
294 /* restore the registers from the jmp buf upon longjmp */
295 extern void DECLSPEC_NORETURN longjmp_set_regs( struct MSVCRT___JUMP_BUFFER *jmp, int retval );
296 __ASM_GLOBAL_FUNC( longjmp_set_regs,
297                    "movl 4(%esp),%ecx\n\t"   /* jmp_buf */
298                    "movl 8(%esp),%eax\n\t"   /* retval */
299                    "movl 0(%ecx),%ebp\n\t"   /* jmp_buf.Ebp */
300                    "movl 4(%ecx),%ebx\n\t"   /* jmp_buf.Ebx */
301                    "movl 8(%ecx),%edi\n\t"   /* jmp_buf.Edi */
302                    "movl 12(%ecx),%esi\n\t"  /* jmp_buf.Esi */
303                    "movl 16(%ecx),%esp\n\t"  /* jmp_buf.Esp */
304                    "addl $4,%esp\n\t"        /* get rid of return address */
305                    "jmp *20(%ecx)\n\t"       /* jmp_buf.Eip */ )
306
307 /*
308  * The signatures of the setjmp/longjmp functions do not match that
309  * declared in the setjmp header so they don't follow the regular naming
310  * convention to avoid conflicts.
311  */
312
313 /*******************************************************************
314  *              _setjmp (MSVCRT.@)
315  */
316 DEFINE_SETJMP_ENTRYPOINT(MSVCRT__setjmp)
317 int CDECL __regs_MSVCRT__setjmp(struct MSVCRT___JUMP_BUFFER *jmp)
318 {
319     jmp->Registration = (unsigned long)NtCurrentTeb()->Tib.ExceptionList;
320     if (jmp->Registration == ~0UL)
321         jmp->TryLevel = TRYLEVEL_END;
322     else
323         jmp->TryLevel = ((MSVCRT_EXCEPTION_FRAME*)jmp->Registration)->trylevel;
324
325     TRACE("buf=%p ebx=%08lx esi=%08lx edi=%08lx ebp=%08lx esp=%08lx eip=%08lx frame=%08lx\n",
326           jmp, jmp->Ebx, jmp->Esi, jmp->Edi, jmp->Ebp, jmp->Esp, jmp->Eip, jmp->Registration );
327     return 0;
328 }
329
330 /*******************************************************************
331  *              _setjmp3 (MSVCRT.@)
332  */
333 DEFINE_SETJMP_ENTRYPOINT( MSVCRT__setjmp3 )
334 int CDECL __regs_MSVCRT__setjmp3(struct MSVCRT___JUMP_BUFFER *jmp, int nb_args, ...)
335 {
336     jmp->Cookie = MSVCRT_JMP_MAGIC;
337     jmp->UnwindFunc = 0;
338     jmp->Registration = (unsigned long)NtCurrentTeb()->Tib.ExceptionList;
339     if (jmp->Registration == ~0UL)
340     {
341         jmp->TryLevel = TRYLEVEL_END;
342     }
343     else
344     {
345         int i;
346         va_list args;
347
348         va_start( args, nb_args );
349         if (nb_args > 0) jmp->UnwindFunc = va_arg( args, unsigned long );
350         if (nb_args > 1) jmp->TryLevel = va_arg( args, unsigned long );
351         else jmp->TryLevel = ((MSVCRT_EXCEPTION_FRAME*)jmp->Registration)->trylevel;
352         for (i = 0; i < 6 && i < nb_args - 2; i++)
353             jmp->UnwindData[i] = va_arg( args, unsigned long );
354         va_end( args );
355     }
356
357     TRACE("buf=%p ebx=%08lx esi=%08lx edi=%08lx ebp=%08lx esp=%08lx eip=%08lx frame=%08lx\n",
358           jmp, jmp->Ebx, jmp->Esi, jmp->Edi, jmp->Ebp, jmp->Esp, jmp->Eip, jmp->Registration );
359     return 0;
360 }
361
362 /*********************************************************************
363  *              longjmp (MSVCRT.@)
364  */
365 int CDECL MSVCRT_longjmp(struct MSVCRT___JUMP_BUFFER *jmp, int retval)
366 {
367     unsigned long cur_frame = 0;
368
369     TRACE("buf=%p ebx=%08lx esi=%08lx edi=%08lx ebp=%08lx esp=%08lx eip=%08lx frame=%08lx retval=%08x\n",
370           jmp, jmp->Ebx, jmp->Esi, jmp->Edi, jmp->Ebp, jmp->Esp, jmp->Eip, jmp->Registration, retval );
371
372     cur_frame=(unsigned long)NtCurrentTeb()->Tib.ExceptionList;
373     TRACE("cur_frame=%lx\n",cur_frame);
374
375     if (cur_frame != jmp->Registration)
376         _global_unwind2((EXCEPTION_REGISTRATION_RECORD*)jmp->Registration);
377
378     if (jmp->Registration)
379     {
380         if (!IsBadReadPtr(&jmp->Cookie, sizeof(long)) &&
381             jmp->Cookie == MSVCRT_JMP_MAGIC && jmp->UnwindFunc)
382         {
383             MSVCRT_unwind_function unwind_func;
384
385             unwind_func=(MSVCRT_unwind_function)jmp->UnwindFunc;
386             unwind_func(jmp);
387         }
388         else
389             msvcrt_local_unwind2((MSVCRT_EXCEPTION_FRAME*)jmp->Registration,
390                                  jmp->TryLevel, (void *)jmp->Ebp);
391     }
392
393     if (!retval)
394         retval = 1;
395
396     longjmp_set_regs( jmp, retval );
397 }
398
399 /*********************************************************************
400  *              _seh_longjmp_unwind (MSVCRT.@)
401  */
402 void __stdcall _seh_longjmp_unwind(struct MSVCRT___JUMP_BUFFER *jmp)
403 {
404     msvcrt_local_unwind2( (MSVCRT_EXCEPTION_FRAME *)jmp->Registration, jmp->TryLevel, (void *)jmp->Ebp );
405 }
406 #endif /* i386 */
407
408 static MSVCRT___sighandler_t sighandlers[MSVCRT_NSIG] = { MSVCRT_SIG_DFL };
409
410 static BOOL WINAPI msvcrt_console_handler(DWORD ctrlType)
411 {
412     BOOL ret = FALSE;
413
414     switch (ctrlType)
415     {
416     case CTRL_C_EVENT:
417         if (sighandlers[MSVCRT_SIGINT])
418         {
419             if (sighandlers[MSVCRT_SIGINT] != MSVCRT_SIG_IGN)
420                 sighandlers[MSVCRT_SIGINT](MSVCRT_SIGINT);
421             ret = TRUE;
422         }
423         break;
424     }
425     return ret;
426 }
427
428 typedef void (*float_handler)(int, int);
429
430 /* The exception codes are actually NTSTATUS values */
431 static const struct
432 {
433     NTSTATUS status;
434     int signal;
435 } float_exception_map[] = {
436  { EXCEPTION_FLT_DENORMAL_OPERAND, _FPE_DENORMAL },
437  { EXCEPTION_FLT_DIVIDE_BY_ZERO, _FPE_ZERODIVIDE },
438  { EXCEPTION_FLT_INEXACT_RESULT, _FPE_INEXACT },
439  { EXCEPTION_FLT_INVALID_OPERATION, _FPE_INVALID },
440  { EXCEPTION_FLT_OVERFLOW, _FPE_OVERFLOW },
441  { EXCEPTION_FLT_STACK_CHECK, _FPE_STACKOVERFLOW },
442  { EXCEPTION_FLT_UNDERFLOW, _FPE_UNDERFLOW },
443 };
444
445 static LONG WINAPI msvcrt_exception_filter(struct _EXCEPTION_POINTERS *except)
446 {
447     LONG ret = EXCEPTION_CONTINUE_SEARCH;
448     MSVCRT___sighandler_t handler;
449
450     if (!except || !except->ExceptionRecord)
451         return EXCEPTION_CONTINUE_SEARCH;
452
453     switch (except->ExceptionRecord->ExceptionCode)
454     {
455     case EXCEPTION_ACCESS_VIOLATION:
456         if ((handler = sighandlers[MSVCRT_SIGSEGV]) != MSVCRT_SIG_DFL)
457         {
458             if (handler != MSVCRT_SIG_IGN)
459             {
460                 sighandlers[MSVCRT_SIGSEGV] = MSVCRT_SIG_DFL;
461                 handler(MSVCRT_SIGSEGV);
462             }
463             ret = EXCEPTION_CONTINUE_EXECUTION;
464         }
465         break;
466     /* According to msdn,
467      * the FPE signal handler takes as a second argument the type of
468      * floating point exception.
469      */
470     case EXCEPTION_FLT_DENORMAL_OPERAND:
471     case EXCEPTION_FLT_DIVIDE_BY_ZERO:
472     case EXCEPTION_FLT_INEXACT_RESULT:
473     case EXCEPTION_FLT_INVALID_OPERATION:
474     case EXCEPTION_FLT_OVERFLOW:
475     case EXCEPTION_FLT_STACK_CHECK:
476     case EXCEPTION_FLT_UNDERFLOW:
477         if ((handler = sighandlers[MSVCRT_SIGFPE]) != MSVCRT_SIG_DFL)
478         {
479             if (handler != MSVCRT_SIG_IGN)
480             {
481                 int i, float_signal = _FPE_INVALID;
482
483                 sighandlers[MSVCRT_SIGFPE] = MSVCRT_SIG_DFL;
484                 for (i = 0; i < sizeof(float_exception_map) /
485                          sizeof(float_exception_map[0]); i++)
486                 {
487                     if (float_exception_map[i].status ==
488                         except->ExceptionRecord->ExceptionCode)
489                     {
490                         float_signal = float_exception_map[i].signal;
491                         break;
492                     }
493                 }
494                 ((float_handler)handler)(MSVCRT_SIGFPE, float_signal);
495             }
496             ret = EXCEPTION_CONTINUE_EXECUTION;
497         }
498         break;
499     case EXCEPTION_ILLEGAL_INSTRUCTION:
500         if ((handler = sighandlers[MSVCRT_SIGILL]) != MSVCRT_SIG_DFL)
501         {
502             if (handler != MSVCRT_SIG_IGN)
503             {
504                 sighandlers[MSVCRT_SIGILL] = MSVCRT_SIG_DFL;
505                 handler(MSVCRT_SIGILL);
506             }
507             ret = EXCEPTION_CONTINUE_EXECUTION;
508         }
509         break;
510     }
511     return ret;
512 }
513
514 void msvcrt_init_signals(void)
515 {
516     SetConsoleCtrlHandler(msvcrt_console_handler, TRUE);
517     SetUnhandledExceptionFilter(msvcrt_exception_filter);
518 }
519
520 void msvcrt_free_signals(void)
521 {
522     SetConsoleCtrlHandler(msvcrt_console_handler, FALSE);
523     SetUnhandledExceptionFilter(NULL);
524 }
525
526 /*********************************************************************
527  *              signal (MSVCRT.@)
528  * Some signals may never be generated except through an explicit call to
529  * raise.
530  */
531 MSVCRT___sighandler_t CDECL MSVCRT_signal(int sig, MSVCRT___sighandler_t func)
532 {
533     MSVCRT___sighandler_t ret = MSVCRT_SIG_ERR;
534
535     TRACE("(%d, %p)\n", sig, func);
536
537     if (func == MSVCRT_SIG_ERR) return MSVCRT_SIG_ERR;
538
539     switch (sig)
540     {
541     /* Cases handled internally.  Note SIGTERM is never generated by Windows,
542      * so we effectively mask it.
543      */
544     case MSVCRT_SIGABRT:
545     case MSVCRT_SIGFPE:
546     case MSVCRT_SIGILL:
547     case MSVCRT_SIGSEGV:
548     case MSVCRT_SIGINT:
549     case MSVCRT_SIGTERM:
550         ret = sighandlers[sig];
551         sighandlers[sig] = func;
552         break;
553     default:
554         ret = MSVCRT_SIG_ERR;
555     }
556     return ret;
557 }
558
559 /*********************************************************************
560  *              raise (MSVCRT.@)
561  */
562 int CDECL MSVCRT_raise(int sig)
563 {
564     MSVCRT___sighandler_t handler;
565
566     TRACE("(%d)\n", sig);
567
568     switch (sig)
569     {
570     case MSVCRT_SIGABRT:
571     case MSVCRT_SIGFPE:
572     case MSVCRT_SIGILL:
573     case MSVCRT_SIGSEGV:
574     case MSVCRT_SIGINT:
575     case MSVCRT_SIGTERM:
576         handler = sighandlers[sig];
577         if (handler == MSVCRT_SIG_DFL) MSVCRT__exit(3);
578         if (handler != MSVCRT_SIG_IGN)
579         {
580             sighandlers[sig] = MSVCRT_SIG_DFL;
581             if (sig == MSVCRT_SIGFPE)
582                 ((float_handler)handler)(sig, _FPE_EXPLICITGEN);
583             else
584                 handler(sig);
585         }
586         break;
587     default:
588         return -1;
589     }
590     return 0;
591 }
592
593 /*********************************************************************
594  *              _XcptFilter (MSVCRT.@)
595  */
596 int CDECL _XcptFilter(NTSTATUS ex, PEXCEPTION_POINTERS ptr)
597 {
598     TRACE("(%08x,%p)\n", ex, ptr);
599     /* I assume ptr->ExceptionRecord->ExceptionCode is the same as ex */
600     return msvcrt_exception_filter(ptr);
601 }