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