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