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