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