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