ntdll: Print traces for EXC_CallHandler even with the assembly version.
[wine] / dlls / ntdll / exception.c
1 /*
2  * NT exception handling routines
3  *
4  * Copyright 1999 Turchanov Sergey
5  * Copyright 1999 Alexandre Julliard
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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20  */
21
22 #include "config.h"
23 #include "wine/port.h"
24
25 #include <assert.h>
26 #include <signal.h>
27 #include <stdarg.h>
28
29 #include "ntstatus.h"
30 #define WIN32_NO_STATUS
31 #include "windef.h"
32 #include "winternl.h"
33 #include "wine/exception.h"
34 #include "wine/server.h"
35 #include "wine/list.h"
36 #include "wine/debug.h"
37 #include "excpt.h"
38 #include "ntdll_misc.h"
39
40 WINE_DEFAULT_DEBUG_CHANNEL(seh);
41
42 /* Exception record for handling exceptions happening inside exception handlers */
43 typedef struct
44 {
45     EXCEPTION_REGISTRATION_RECORD frame;
46     EXCEPTION_REGISTRATION_RECORD *prevFrame;
47 } EXC_NESTED_FRAME;
48
49 typedef struct
50 {
51     struct list                 entry;
52     PVECTORED_EXCEPTION_HANDLER func;
53 } VECTORED_HANDLER;
54
55 static struct list vectored_handlers = LIST_INIT(vectored_handlers);
56
57 static RTL_CRITICAL_SECTION vectored_handlers_section;
58 static RTL_CRITICAL_SECTION_DEBUG critsect_debug =
59 {
60     0, 0, &vectored_handlers_section,
61     { &critsect_debug.ProcessLocksList, &critsect_debug.ProcessLocksList },
62       0, 0, { (DWORD_PTR)(__FILE__ ": vectored_handlers_section") }
63 };
64 static RTL_CRITICAL_SECTION vectored_handlers_section = { &critsect_debug, -1, 0, 0, 0, 0 };
65
66 #ifdef __i386__
67 # define GET_IP(context) ((LPVOID)(context)->Eip)
68 #elif defined(__sparc__)
69 # define GET_IP(context) ((LPVOID)(context)->pc)
70 #elif defined(__powerpc__)
71 # define GET_IP(context) ((LPVOID)(context)->Iar)
72 #elif defined(__ALPHA__)
73 # define GET_IP(context) ((LPVOID)(context)->Fir)
74 #elif defined(__x86_64__)
75 # define GET_IP(context) ((LPVOID)(context)->Rip)
76 #else
77 # error You must define GET_IP for this CPU
78 #endif
79
80 extern void DECLSPEC_NORETURN __wine_call_from_32_restore_regs( const CONTEXT *context );
81
82 /*******************************************************************
83  *         EXC_RaiseHandler
84  *
85  * Handler for exceptions happening inside a handler.
86  */
87 static DWORD EXC_RaiseHandler( EXCEPTION_RECORD *rec, EXCEPTION_REGISTRATION_RECORD *frame,
88                                CONTEXT *context, EXCEPTION_REGISTRATION_RECORD **dispatcher )
89 {
90     if (rec->ExceptionFlags & (EH_UNWINDING | EH_EXIT_UNWIND))
91         return ExceptionContinueSearch;
92     /* We shouldn't get here so we store faulty frame in dispatcher */
93     *dispatcher = ((EXC_NESTED_FRAME*)frame)->prevFrame;
94     return ExceptionNestedException;
95 }
96
97
98 /*******************************************************************
99  *         EXC_UnwindHandler
100  *
101  * Handler for exceptions happening inside an unwind handler.
102  */
103 static DWORD EXC_UnwindHandler( EXCEPTION_RECORD *rec, EXCEPTION_REGISTRATION_RECORD *frame,
104                                 CONTEXT *context, EXCEPTION_REGISTRATION_RECORD **dispatcher )
105 {
106     if (!(rec->ExceptionFlags & (EH_UNWINDING | EH_EXIT_UNWIND)))
107         return ExceptionContinueSearch;
108     /* We shouldn't get here so we store faulty frame in dispatcher */
109     *dispatcher = ((EXC_NESTED_FRAME*)frame)->prevFrame;
110     return ExceptionCollidedUnwind;
111 }
112
113
114 /*******************************************************************
115  *         EXC_CallHandler
116  *
117  * Call an exception handler, setting up an exception frame to catch exceptions
118  * happening during the handler execution.
119  *
120  * For i386 this function is implemented in assembler in signal_i386.c.
121  */
122 #ifndef __i386__
123 static DWORD EXC_CallHandler( EXCEPTION_RECORD *record, EXCEPTION_REGISTRATION_RECORD *frame,
124                               CONTEXT *context, EXCEPTION_REGISTRATION_RECORD **dispatcher,
125                               PEXCEPTION_HANDLER handler, PEXCEPTION_HANDLER nested_handler)
126 {
127     EXC_NESTED_FRAME newframe;
128     DWORD ret;
129
130     newframe.frame.Handler = nested_handler;
131     newframe.prevFrame     = frame;
132     __wine_push_frame( &newframe.frame );
133     ret = handler( record, frame, context, dispatcher );
134     __wine_pop_frame( &newframe.frame );
135     return ret;
136 }
137 #else
138 /* in signal_i386.c */
139 extern DWORD EXC_CallHandler( EXCEPTION_RECORD *record, EXCEPTION_REGISTRATION_RECORD *frame,
140                               CONTEXT *context, EXCEPTION_REGISTRATION_RECORD **dispatcher,
141                               PEXCEPTION_HANDLER handler, PEXCEPTION_HANDLER nested_handler);
142 #endif
143
144 /**********************************************************************
145  *           wait_suspend
146  *
147  * Wait until the thread is no longer suspended.
148  */
149 void wait_suspend( CONTEXT *context )
150 {
151     LARGE_INTEGER timeout;
152
153     /* store the context we got at suspend time */
154     SERVER_START_REQ( set_thread_context )
155     {
156         req->handle  = GetCurrentThread();
157         req->flags   = CONTEXT_FULL;
158         req->suspend = 1;
159         wine_server_add_data( req, context, sizeof(*context) );
160         wine_server_call( req );
161     }
162     SERVER_END_REQ;
163
164     /* wait with 0 timeout, will only return once the thread is no longer suspended */
165     timeout.QuadPart = 0;
166     NTDLL_wait_for_multiple_objects( 0, NULL, 0, &timeout, 0 );
167
168     /* retrieve the new context */
169     SERVER_START_REQ( get_thread_context )
170     {
171         req->handle  = GetCurrentThread();
172         req->flags   = CONTEXT_FULL;
173         req->suspend = 1;
174         wine_server_set_reply( req, context, sizeof(*context) );
175         wine_server_call( req );
176     }
177     SERVER_END_REQ;
178 }
179
180
181 /**********************************************************************
182  *           send_debug_event
183  *
184  * Send an EXCEPTION_DEBUG_EVENT event to the debugger.
185  */
186 static NTSTATUS send_debug_event( EXCEPTION_RECORD *rec, int first_chance, CONTEXT *context )
187 {
188     int ret;
189     HANDLE handle = 0;
190
191     if (!NtCurrentTeb()->Peb->BeingDebugged) return 0;  /* no debugger present */
192
193     SERVER_START_REQ( queue_exception_event )
194     {
195         req->first   = first_chance;
196         wine_server_add_data( req, context, sizeof(*context) );
197         wine_server_add_data( req, rec, sizeof(*rec) );
198         if (!wine_server_call( req )) handle = reply->handle;
199     }
200     SERVER_END_REQ;
201     if (!handle) return 0;
202
203     NTDLL_wait_for_multiple_objects( 1, &handle, 0, NULL, 0 );
204
205     SERVER_START_REQ( get_exception_status )
206     {
207         req->handle = handle;
208         wine_server_set_reply( req, context, sizeof(*context) );
209         ret = wine_server_call( req );
210     }
211     SERVER_END_REQ;
212     return ret;
213 }
214
215
216 /**********************************************************************
217  *           call_vectored_handlers
218  *
219  * Call the vectored handlers chain.
220  */
221 static LONG call_vectored_handlers( EXCEPTION_RECORD *rec, CONTEXT *context )
222 {
223     struct list *ptr;
224     LONG ret = EXCEPTION_CONTINUE_SEARCH;
225     EXCEPTION_POINTERS except_ptrs;
226
227     except_ptrs.ExceptionRecord = rec;
228     except_ptrs.ContextRecord = context;
229
230     RtlEnterCriticalSection( &vectored_handlers_section );
231     LIST_FOR_EACH( ptr, &vectored_handlers )
232     {
233         VECTORED_HANDLER *handler = LIST_ENTRY( ptr, VECTORED_HANDLER, entry );
234         ret = handler->func( &except_ptrs );
235         if (ret == EXCEPTION_CONTINUE_EXECUTION) break;
236     }
237     RtlLeaveCriticalSection( &vectored_handlers_section );
238     return ret;
239 }
240
241
242 /**********************************************************************
243  *           call_stack_handlers
244  *
245  * Call the stack handlers chain.
246  */
247 static NTSTATUS call_stack_handlers( EXCEPTION_RECORD *rec, CONTEXT *context )
248 {
249     EXCEPTION_REGISTRATION_RECORD *frame, *dispatch, *nested_frame;
250     DWORD res;
251
252     frame = NtCurrentTeb()->Tib.ExceptionList;
253     nested_frame = NULL;
254     while (frame != (EXCEPTION_REGISTRATION_RECORD*)~0UL)
255     {
256         /* Check frame address */
257         if (((void*)frame < NtCurrentTeb()->Tib.StackLimit) ||
258             ((void*)(frame+1) > NtCurrentTeb()->Tib.StackBase) ||
259             (ULONG_PTR)frame & 3)
260         {
261             rec->ExceptionFlags |= EH_STACK_INVALID;
262             break;
263         }
264
265         /* Call handler */
266         TRACE( "calling handler at %p code=%lx flags=%lx\n",
267                frame->Handler, rec->ExceptionCode, rec->ExceptionFlags );
268         res = EXC_CallHandler( rec, frame, context, &dispatch, frame->Handler, EXC_RaiseHandler );
269         TRACE( "handler at %p returned %lx\n", frame->Handler, res );
270
271         if (frame == nested_frame)
272         {
273             /* no longer nested */
274             nested_frame = NULL;
275             rec->ExceptionFlags &= ~EH_NESTED_CALL;
276         }
277
278         switch(res)
279         {
280         case ExceptionContinueExecution:
281             if (!(rec->ExceptionFlags & EH_NONCONTINUABLE)) return STATUS_SUCCESS;
282             return STATUS_NONCONTINUABLE_EXCEPTION;
283         case ExceptionContinueSearch:
284             break;
285         case ExceptionNestedException:
286             if (nested_frame < dispatch) nested_frame = dispatch;
287             rec->ExceptionFlags |= EH_NESTED_CALL;
288             break;
289         default:
290             return STATUS_INVALID_DISPOSITION;
291         }
292         frame = frame->Prev;
293     }
294     return STATUS_UNHANDLED_EXCEPTION;
295 }
296
297
298 /*******************************************************************
299  *              raise_exception
300  *
301  * Implementation of NtRaiseException.
302  */
303 static NTSTATUS raise_exception( EXCEPTION_RECORD *rec, CONTEXT *context, BOOL first_chance )
304 {
305     NTSTATUS status;
306
307     if (first_chance)
308     {
309         DWORD c;
310
311         TRACE( "code=%lx flags=%lx addr=%p\n",
312                rec->ExceptionCode, rec->ExceptionFlags, rec->ExceptionAddress );
313         for (c = 0; c < rec->NumberParameters; c++)
314             TRACE( " info[%ld]=%08lx\n", c, rec->ExceptionInformation[c] );
315         if (rec->ExceptionCode == EXCEPTION_WINE_STUB)
316         {
317             if (rec->ExceptionInformation[1] >> 16)
318                 MESSAGE( "wine: Call from %p to unimplemented function %s.%s, aborting\n",
319                          rec->ExceptionAddress,
320                          (char*)rec->ExceptionInformation[0], (char*)rec->ExceptionInformation[1] );
321             else
322                 MESSAGE( "wine: Call from %p to unimplemented function %s.%ld, aborting\n",
323                          rec->ExceptionAddress,
324                          (char*)rec->ExceptionInformation[0], rec->ExceptionInformation[1] );
325         }
326 #ifdef __i386__
327         else
328         {
329             TRACE(" eax=%08lx ebx=%08lx ecx=%08lx edx=%08lx esi=%08lx edi=%08lx\n",
330                   context->Eax, context->Ebx, context->Ecx,
331                   context->Edx, context->Esi, context->Edi );
332             TRACE(" ebp=%08lx esp=%08lx cs=%04lx ds=%04lx es=%04lx fs=%04lx gs=%04lx flags=%08lx\n",
333                   context->Ebp, context->Esp, context->SegCs, context->SegDs,
334                   context->SegEs, context->SegFs, context->SegGs, context->EFlags );
335         }
336 #endif
337         status = send_debug_event( rec, TRUE, context );
338         if (status == DBG_CONTINUE || status == DBG_EXCEPTION_HANDLED)
339             return STATUS_SUCCESS;
340
341         if (call_vectored_handlers( rec, context ) == EXCEPTION_CONTINUE_EXECUTION)
342             return STATUS_SUCCESS;
343
344         if ((status = call_stack_handlers( rec, context )) != STATUS_UNHANDLED_EXCEPTION)
345             return status;
346     }
347
348     /* last chance exception */
349
350     status = send_debug_event( rec, FALSE, context );
351     if (status != DBG_CONTINUE)
352     {
353         if (rec->ExceptionFlags & EH_STACK_INVALID)
354             ERR("Exception frame is not in stack limits => unable to dispatch exception.\n");
355         else if (rec->ExceptionCode == STATUS_NONCONTINUABLE_EXCEPTION)
356             ERR("Process attempted to continue execution after noncontinuable exception.\n");
357         else
358             ERR("Unhandled exception code %lx flags %lx addr %p\n",
359                 rec->ExceptionCode, rec->ExceptionFlags, rec->ExceptionAddress );
360         NtTerminateProcess( NtCurrentProcess(), 1 );
361     }
362     return STATUS_SUCCESS;
363 }
364
365
366 /*******************************************************************
367  *              NtRaiseException (NTDLL.@)
368  */
369 NTSTATUS WINAPI NtRaiseException( EXCEPTION_RECORD *rec, CONTEXT *context, BOOL first_chance )
370 {
371     NTSTATUS status = raise_exception( rec, context, first_chance );
372 #ifdef DEFINE_REGS_ENTRYPOINT
373     if (status == STATUS_SUCCESS) __wine_call_from_32_restore_regs( context );
374 #endif
375     return status;
376 }
377
378 /***********************************************************************
379  *              RtlRaiseException (NTDLL.@)
380  */
381 void WINAPI __regs_RtlRaiseException( EXCEPTION_RECORD *rec, CONTEXT *context )
382 {
383     NTSTATUS status = raise_exception( rec, context, TRUE );
384     if (status != STATUS_SUCCESS)
385     {
386         EXCEPTION_RECORD newrec;
387         newrec.ExceptionCode    = status;
388         newrec.ExceptionFlags   = EH_NONCONTINUABLE;
389         newrec.ExceptionRecord  = rec;
390         newrec.NumberParameters = 0;
391         RtlRaiseException( &newrec );  /* never returns */
392     }
393 }
394
395 /**********************************************************************/
396
397 #ifdef DEFINE_REGS_ENTRYPOINT
398 DEFINE_REGS_ENTRYPOINT( RtlRaiseException, 4, 4 );
399 #else
400 void WINAPI RtlRaiseException( EXCEPTION_RECORD *rec )
401 {
402     CONTEXT context;
403     memset( &context, 0, sizeof(context) );
404     __regs_RtlRaiseException( rec, &context );
405 }
406 #endif
407
408
409 /*******************************************************************
410  *              RtlUnwind (NTDLL.@)
411  */
412 void WINAPI __regs_RtlUnwind( EXCEPTION_REGISTRATION_RECORD* pEndFrame, PVOID unusedEip,
413                               PEXCEPTION_RECORD pRecord, PVOID returnEax, CONTEXT *context )
414 {
415     EXCEPTION_RECORD record, newrec;
416     EXCEPTION_REGISTRATION_RECORD *frame, *dispatch;
417     DWORD res;
418
419 #ifdef __i386__
420     context->Eax = (DWORD)returnEax;
421 #endif
422
423     /* build an exception record, if we do not have one */
424     if (!pRecord)
425     {
426         record.ExceptionCode    = STATUS_UNWIND;
427         record.ExceptionFlags   = 0;
428         record.ExceptionRecord  = NULL;
429         record.ExceptionAddress = GET_IP(context);
430         record.NumberParameters = 0;
431         pRecord = &record;
432     }
433
434     pRecord->ExceptionFlags |= EH_UNWINDING | (pEndFrame ? 0 : EH_EXIT_UNWIND);
435
436     TRACE( "code=%lx flags=%lx\n", pRecord->ExceptionCode, pRecord->ExceptionFlags );
437
438     /* get chain of exception frames */
439     frame = NtCurrentTeb()->Tib.ExceptionList;
440     while ((frame != (EXCEPTION_REGISTRATION_RECORD*)~0UL) && (frame != pEndFrame))
441     {
442         /* Check frame address */
443         if (pEndFrame && (frame > pEndFrame))
444         {
445             newrec.ExceptionCode    = STATUS_INVALID_UNWIND_TARGET;
446             newrec.ExceptionFlags   = EH_NONCONTINUABLE;
447             newrec.ExceptionRecord  = pRecord;
448             newrec.NumberParameters = 0;
449             RtlRaiseException( &newrec );  /* never returns */
450         }
451         if (((void*)frame < NtCurrentTeb()->Tib.StackLimit) ||
452             ((void*)(frame+1) > NtCurrentTeb()->Tib.StackBase) ||
453             (UINT_PTR)frame & 3)
454         {
455             newrec.ExceptionCode    = STATUS_BAD_STACK;
456             newrec.ExceptionFlags   = EH_NONCONTINUABLE;
457             newrec.ExceptionRecord  = pRecord;
458             newrec.NumberParameters = 0;
459             RtlRaiseException( &newrec );  /* never returns */
460         }
461
462         /* Call handler */
463         TRACE( "calling handler at %p code=%lx flags=%lx\n",
464                frame->Handler, pRecord->ExceptionCode, pRecord->ExceptionFlags );
465         res = EXC_CallHandler( pRecord, frame, context, &dispatch, frame->Handler, EXC_UnwindHandler );
466         TRACE( "handler at %p returned %lx\n", frame->Handler, res );
467
468         switch(res)
469         {
470         case ExceptionContinueSearch:
471             break;
472         case ExceptionCollidedUnwind:
473             frame = dispatch;
474             break;
475         default:
476             newrec.ExceptionCode    = STATUS_INVALID_DISPOSITION;
477             newrec.ExceptionFlags   = EH_NONCONTINUABLE;
478             newrec.ExceptionRecord  = pRecord;
479             newrec.NumberParameters = 0;
480             RtlRaiseException( &newrec );  /* never returns */
481             break;
482         }
483         frame = __wine_pop_frame( frame );
484     }
485 }
486
487 /**********************************************************************/
488
489 #ifdef DEFINE_REGS_ENTRYPOINT
490 DEFINE_REGS_ENTRYPOINT( RtlUnwind, 16, 16 );
491 #else
492 void WINAPI RtlUnwind( PVOID pEndFrame, PVOID unusedEip,
493                        PEXCEPTION_RECORD pRecord, PVOID returnEax )
494 {
495     CONTEXT context;
496     memset( &context, 0, sizeof(context) );
497     __regs_RtlUnwind( pEndFrame, unusedEip, pRecord, returnEax, &context );
498 }
499 #endif
500
501
502 /***********************************************************************
503  *            RtlRaiseStatus  (NTDLL.@)
504  *
505  * Raise an exception with ExceptionCode = status
506  */
507 void WINAPI RtlRaiseStatus( NTSTATUS status )
508 {
509     EXCEPTION_RECORD ExceptionRec;
510
511     ExceptionRec.ExceptionCode    = status;
512     ExceptionRec.ExceptionFlags   = EH_NONCONTINUABLE;
513     ExceptionRec.ExceptionRecord  = NULL;
514     ExceptionRec.NumberParameters = 0;
515     RtlRaiseException( &ExceptionRec );
516 }
517
518
519 /*******************************************************************
520  *         RtlAddVectoredExceptionHandler   (NTDLL.@)
521  */
522 PVOID WINAPI RtlAddVectoredExceptionHandler( ULONG first, PVECTORED_EXCEPTION_HANDLER func )
523 {
524     VECTORED_HANDLER *handler = RtlAllocateHeap( GetProcessHeap(), 0, sizeof(*handler) );
525     if (handler)
526     {
527         handler->func = func;
528         RtlEnterCriticalSection( &vectored_handlers_section );
529         if (first) list_add_head( &vectored_handlers, &handler->entry );
530         else list_add_tail( &vectored_handlers, &handler->entry );
531         RtlLeaveCriticalSection( &vectored_handlers_section );
532     }
533     return handler;
534 }
535
536
537 /*******************************************************************
538  *         RtlRemoveVectoredExceptionHandler   (NTDLL.@)
539  */
540 ULONG WINAPI RtlRemoveVectoredExceptionHandler( PVOID handler )
541 {
542     struct list *ptr;
543     ULONG ret = FALSE;
544
545     RtlEnterCriticalSection( &vectored_handlers_section );
546     LIST_FOR_EACH( ptr, &vectored_handlers )
547     {
548         VECTORED_HANDLER *curr_handler = LIST_ENTRY( ptr, VECTORED_HANDLER, entry );
549         if (curr_handler == handler)
550         {
551             list_remove( ptr );
552             ret = TRUE;
553             break;
554         }
555     }
556     RtlLeaveCriticalSection( &vectored_handlers_section );
557     if (ret) RtlFreeHeap( GetProcessHeap(), 0, handler );
558     return ret;
559 }
560
561
562 /*************************************************************
563  *            __wine_exception_handler (NTDLL.@)
564  *
565  * Exception handler for exception blocks declared in Wine code.
566  */
567 DWORD __wine_exception_handler( EXCEPTION_RECORD *record, EXCEPTION_REGISTRATION_RECORD *frame,
568                                 CONTEXT *context, EXCEPTION_REGISTRATION_RECORD **pdispatcher )
569 {
570     __WINE_FRAME *wine_frame = (__WINE_FRAME *)frame;
571
572     if (record->ExceptionFlags & (EH_UNWINDING | EH_EXIT_UNWIND | EH_NESTED_CALL))
573         return ExceptionContinueSearch;
574
575     if (wine_frame->u.filter == (void *)1)  /* special hack for page faults */
576     {
577         if (record->ExceptionCode != STATUS_ACCESS_VIOLATION)
578             return ExceptionContinueSearch;
579     }
580     else if (wine_frame->u.filter)
581     {
582         EXCEPTION_POINTERS ptrs;
583         ptrs.ExceptionRecord = record;
584         ptrs.ContextRecord = context;
585         switch(wine_frame->u.filter( &ptrs ))
586         {
587         case EXCEPTION_CONTINUE_SEARCH:
588             return ExceptionContinueSearch;
589         case EXCEPTION_CONTINUE_EXECUTION:
590             return ExceptionContinueExecution;
591         case EXCEPTION_EXECUTE_HANDLER:
592             break;
593         default:
594             MESSAGE( "Invalid return value from exception filter\n" );
595             assert( FALSE );
596         }
597     }
598     /* hack to make GetExceptionCode() work in handler */
599     wine_frame->ExceptionCode   = record->ExceptionCode;
600     wine_frame->ExceptionRecord = wine_frame;
601
602     RtlUnwind( frame, 0, record, 0 );
603     __wine_pop_frame( frame );
604     siglongjmp( wine_frame->jmp, 1 );
605 }
606
607
608 /*************************************************************
609  *            __wine_finally_handler (NTDLL.@)
610  *
611  * Exception handler for try/finally blocks declared in Wine code.
612  */
613 DWORD __wine_finally_handler( EXCEPTION_RECORD *record, EXCEPTION_REGISTRATION_RECORD *frame,
614                               CONTEXT *context, EXCEPTION_REGISTRATION_RECORD **pdispatcher )
615 {
616     if (record->ExceptionFlags & (EH_UNWINDING | EH_EXIT_UNWIND))
617     {
618         __WINE_FRAME *wine_frame = (__WINE_FRAME *)frame;
619         wine_frame->u.finally_func( FALSE );
620     }
621     return ExceptionContinueSearch;
622 }
623
624
625 /*************************************************************
626  *            __wine_spec_unimplemented_stub
627  *
628  * ntdll-specific implementation to avoid depending on kernel functions.
629  * Can be removed once ntdll.spec no longer contains stubs.
630  */
631 void __wine_spec_unimplemented_stub( const char *module, const char *function )
632 {
633     EXCEPTION_RECORD record;
634
635     record.ExceptionCode    = EXCEPTION_WINE_STUB;
636     record.ExceptionFlags   = EH_NONCONTINUABLE;
637     record.ExceptionRecord  = NULL;
638     record.ExceptionAddress = __wine_spec_unimplemented_stub;
639     record.NumberParameters = 2;
640     record.ExceptionInformation[0] = (ULONG_PTR)module;
641     record.ExceptionInformation[1] = (ULONG_PTR)function;
642     RtlRaiseException( &record );
643 }