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