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